The export object provides a files array where files for the export can be added. But this just makes sure the actual file is exported. There won't be any information about which data record the files are linked to. We need to add this missing information in each item which exports files.
If an item has one or more files associated to it's data records then it needs to:
- Add file information to the data record the file is associated to
- Add the files to the export→files array
Data format for files
Files added to the data records need to have the following format:
The key for the files in the specific record should always be 'files' but depending on the item the files can be more detailed structured inside the files array. Forum posts for example have attachment and post files so the structure can look like that:
There's a helper method in the export class \totara_userdata\userdata\export::add_file() which adds a file to the export→files array and returns the standardised data to be added to the data.