Skip to content

Commit

Permalink
MDL-30239 webservices: Return additional fields in ws get_files
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Feb 5, 2015
1 parent 88cd577 commit 7310dcf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
19 changes: 17 additions & 2 deletions files/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function get_files_parameters() {
* @param string $contextlevel The context level for the file location.
* @param int $instanceid The instance id for where the file is located.
* @return array
* @since Moodle 2.9 Returns additional fields (timecreated, filesize, author, license)
* @since Moodle 2.2
*/
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null,
Expand Down Expand Up @@ -139,6 +140,7 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi

$params = $child->get_params();
$timemodified = $child->get_timemodified();
$timecreated = $child->get_timecreated();

if ($child->is_directory()) {
if ((is_null($modified)) or ($modified < $timemodified)) {
Expand All @@ -151,7 +153,11 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
'filename' => $child->get_visible_name(),
'url' => null,
'isdir' => true,
'timemodified' => $timemodified
'timemodified' => $timemodified,
'timecreated' => $timecreated,
'filesize' => 0,
'author' => null,
'license' => null
);
$list[] = $node;
}
Expand All @@ -166,7 +172,11 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
'filename' => $child->get_visible_name(),
'url' => $child->get_url(),
'isdir' => false,
'timemodified' => $timemodified
'timemodified' => $timemodified,
'timecreated' => $timecreated,
'filesize' => $child->get_filesize(),
'author' => $child->get_author(),
'license' => $child->get_license()
);
$list[] = $node;
}
Expand All @@ -181,6 +191,7 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
* Returns description of get_files returns
*
* @return external_single_structure
* @since Moodle 2.9 Returns additional fields for files (timecreated, filesize, author, license)
* @since Moodle 2.2
*/
public static function get_files_returns() {
Expand Down Expand Up @@ -210,6 +221,10 @@ public static function get_files_returns() {
'isdir' => new external_value(PARAM_BOOL, ''),
'url' => new external_value(PARAM_TEXT, ''),
'timemodified' => new external_value(PARAM_INT, ''),
'timecreated' => new external_value(PARAM_INT, 'Time created', VALUE_OPTIONAL),
'filesize' => new external_value(PARAM_INT, 'File size', VALUE_OPTIONAL),
'author' => new external_value(PARAM_TEXT, 'File owner', VALUE_OPTIONAL),
'license' => new external_value(PARAM_TEXT, 'File license', VALUE_OPTIONAL),
)
)
)
Expand Down
9 changes: 8 additions & 1 deletion files/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public function test_get_files() {
// Create a file from the string that we made earlier.
$file = $fs->create_file_from_string($filerecord, $filecontent);
$timemodified = $file->get_timemodified();
$timecreated = $file->get_timemodified();
$filesize = $file->get_filesize();

// Use the web service function to return the information about the file that we just uploaded.
// The first time is with a valid context ID.
Expand Down Expand Up @@ -293,7 +295,12 @@ public function test_get_files() {
'filename' => 'Simple4.txt',
'url' => 'http://www.example.com/moodle/pluginfile.php/'.$context->id.'/mod_data/content/'.$itemid.'/Simple4.txt',
'isdir' => false,
'timemodified' => $timemodified);
'timemodified' => $timemodified,
'timecreated' => $timecreated,
'filesize' => $filesize,
'author' => null,
'license' => null
);
// Make sure that they are the same.
$this->assertEquals($testdata, $testfilelisting);

Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ information provided here is intended especially for developers.
* For 3rd party plugin specific environment.xml files, it's now possible to specify version independent checks by using the
<PLUGIN name="component_name"> tag instead of the version dependent <MOODLE version="x.y"> one. If the PLUGIN tag is used any
Moodle specific tags will be ignored.
* External function core_files_get_files returns additional fields (timecreated, filesize, author, license)

=== 2.8 ===

Expand Down

0 comments on commit 7310dcf

Please sign in to comment.