Databases - C0D3D3V/Moodle-DL GitHub Wiki
To download databases the following functions are of interest:
| Area | Name | Introduced in | Description |
|---|---|---|---|
| mod_data | mod_data_get_databases_by_courses | 2.9 (2015051100) | Returns a list of database instances in a provided set of courses, if no courses are provided then all the database instances the user has access to will be returned. |
| mod_data | mod_data_get_entries | 3.3 (2017051500) | Return the complete list of entries of the given database. |
| mod_data | mod_data_get_fields | 3.3 (2017051500) | Return the list of configured fields for the given database. |
| mod_data | mod_data_get_data_access_information | 3.3 (2017051500) | Return access information for a given database. |
The function returns all databases that a user is allowed to see. If the parameter courseids is specified, then filtering is done using the course id's.
The result is an array called databases, which looks like this:
"databases":[
{
"id":25,
"course":66,
"name":"Learner database",
"intro":"<p>Give us a few details about yourself so we can build a bank of course participants and get to know each other!</p>",
"introformat":1,
"comments":false,
"timeavailablefrom":0,
"timeavailableto":0,
"timeviewfrom":0,
"timeviewto":0,
"requiredentries":0,
"requiredentriestoview":0,
"maxentries":0,
"rssarticles":0,
"singletemplate":"<some HTML>",
"listtemplate":"<some HTML>",
"listtemplateheader":"<table align=\"center\" class=\"recipelist\">",
"listtemplatefooter":"</table>",
"addtemplate":"<some HTML>",
"rsstemplate":"<p>[[Your nickname]] - [[Main role]]</p>",
"rsstitletemplate":"",
"csstemplate":"<some CSS>",
"jstemplate":"",
"asearchtemplate":"<p>Type: [[Type]]</p>",
"approval":false,
"manageapproved":true,
"defaultsort":0,
"defaultsortdir":1,
"coursemodule":802,
"introfiles":[ ]
},
....]
Important is the coursemodule which corresponds to the module_id of a module. The id corresponds to the instance id of a module. introfiles can contain some intro files. name is identical to the name of the module, only the intro text is new.
In reality we do not need this request at all to download individual databases.
Parameters
Function
Returns
Returns Structure and the Contents (the file structure as usual)
This function returns all entries of a database. As parameter the databaseid is needed, which is the instance id.
returncontents must be set to 1 so that the content is also returned.
The return can look as follows:
"entries": [
{
"id": 95,
"userid": 56,
"groupid": 0,
"dataid": 7,
"timecreated": 1338674986,
"timemodified": 1338674986,
"approved": true,
"canmanageentry": true,
"fullname": "Barbara Gardner",
"contents": [
{
"id": 739,
"fieldid": 39,
"recordid": 95,
"content": "256px-Single_White_Lily.jpg",
"content1": "White lily",
"content2": null,
"content3": null,
"content4": null,
"files": [
{
"filename": "256px-Single_White_Lily.jpg",
"filepath": "/",
"filesize": 9429,
"fileurl": "https://school.moodledemo.net/webservice/pluginfile.php/676/mod_data/content/739/256px-Single_White_Lily.jpg",
"timemodified": 1338674969,
"mimetype": "image/jpeg",
"isexternalfile": false
},
{
"filename": "thumb_256px-Single_White_Lily.jpg",
"filepath": "/",
"filesize": 4268,
"fileurl": "https://school.moodledemo.net/webservice/pluginfile.php/676/mod_data/content/739/thumb_256px-Single_White_Lily.jpg",
"timemodified": 1338674986,
"mimetype": "image/jpeg",
"isexternalfile": false
}
]
},
{
"id": 740,
"fieldid": 40,
"recordid": 95,
"content": "I think it's beautiful and it only has one petal :)",
"content1": null,
"content2": null,
"content3": null,
"content4": null,
"files": []
}
],
"tags": []
}, ...
]
If you want to know what content to content4 means, you have to call this function once for each database.
If timeavailable returns False, the database is no longer accessible.