mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-31863 Web service : added modified to parameters and modifiedtime to description
This commit is contained in:
parent
4db061680e
commit
8f3039576a
1 changed files with 50 additions and 33 deletions
|
@ -52,7 +52,9 @@ class core_files_external extends external_api {
|
||||||
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
||||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||||
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
||||||
'filename' => new external_value(PARAM_FILE, 'file name')
|
'filename' => new external_value(PARAM_FILE, 'file name'),
|
||||||
|
'modified' => new external_value(PARAM_INT, 'timestamp, return files which the last ' .
|
||||||
|
'timemodified time is the same or later than the specified time', VALUE_DEFAULT, null)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -66,12 +68,16 @@ class core_files_external extends external_api {
|
||||||
* @param int $itemid item id
|
* @param int $itemid item id
|
||||||
* @param string $filepath file path
|
* @param string $filepath file path
|
||||||
* @param string $filename file name
|
* @param string $filename file name
|
||||||
|
* @param int $modified, timestamp, timestamp,
|
||||||
|
* return files which the last timemodified time is the same or later than the specified time
|
||||||
* @return array
|
* @return array
|
||||||
* @since Moodle 2.2
|
* @since Moodle 2.2
|
||||||
*/
|
*/
|
||||||
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null) {
|
||||||
global $CFG, $USER, $OUTPUT;
|
global $CFG, $USER, $OUTPUT;
|
||||||
$fileinfo = self::validate_parameters(self::get_files_parameters(), array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename));
|
$fileinfo = self::validate_parameters(self::get_files_parameters(), array(
|
||||||
|
'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea,
|
||||||
|
'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename, 'modified'=>$modified));
|
||||||
|
|
||||||
$browser = get_file_browser();
|
$browser = get_file_browser();
|
||||||
|
|
||||||
|
@ -99,7 +105,9 @@ class core_files_external extends external_api {
|
||||||
$return = array();
|
$return = array();
|
||||||
$return['parents'] = array();
|
$return['parents'] = array();
|
||||||
$return['files'] = array();
|
$return['files'] = array();
|
||||||
if ($file = $browser->get_file_info($context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) {
|
if ($file = $browser->get_file_info(
|
||||||
|
$context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'],
|
||||||
|
$fileinfo['filepath'], $fileinfo['filename'])) {
|
||||||
$level = $file->get_parent();
|
$level = $file->get_parent();
|
||||||
while ($level) {
|
while ($level) {
|
||||||
$params = $level->get_params();
|
$params = $level->get_params();
|
||||||
|
@ -112,8 +120,10 @@ class core_files_external extends external_api {
|
||||||
foreach ($children as $child) {
|
foreach ($children as $child) {
|
||||||
|
|
||||||
$params = $child->get_params();
|
$params = $child->get_params();
|
||||||
|
$timemodified = $child->get_timemodified();
|
||||||
|
|
||||||
if ($child->is_directory()) {
|
if ($child->is_directory()) {
|
||||||
|
if ((is_null($modified)) or ($modified <= $timemodified)) {
|
||||||
$node = array(
|
$node = array(
|
||||||
'contextid' => $params['contextid'],
|
'contextid' => $params['contextid'],
|
||||||
'component' => $params['component'],
|
'component' => $params['component'],
|
||||||
|
@ -122,10 +132,13 @@ class core_files_external extends external_api {
|
||||||
'filepath' => $params['filepath'],
|
'filepath' => $params['filepath'],
|
||||||
'filename' => $child->get_visible_name(),
|
'filename' => $child->get_visible_name(),
|
||||||
'url' => null,
|
'url' => null,
|
||||||
'isdir' => true
|
'isdir' => true,
|
||||||
|
'timemodified' => $timemodified
|
||||||
);
|
);
|
||||||
$list[] = $node;
|
$list[] = $node;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ((is_null($modified)) or ($modified <= $timemodified)) {
|
||||||
$node = array(
|
$node = array(
|
||||||
'contextid' => $params['contextid'],
|
'contextid' => $params['contextid'],
|
||||||
'component' => $params['component'],
|
'component' => $params['component'],
|
||||||
|
@ -134,12 +147,14 @@ class core_files_external extends external_api {
|
||||||
'filepath' => $params['filepath'],
|
'filepath' => $params['filepath'],
|
||||||
'filename' => $child->get_visible_name(),
|
'filename' => $child->get_visible_name(),
|
||||||
'url' => $child->get_url(),
|
'url' => $child->get_url(),
|
||||||
'isdir' => false
|
'isdir' => false,
|
||||||
|
'timemodified' => $timemodified
|
||||||
);
|
);
|
||||||
$list[] = $node;
|
$list[] = $node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$return['files'] = $list;
|
$return['files'] = $list;
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +191,7 @@ class core_files_external extends external_api {
|
||||||
'filename' => new external_value(PARAM_FILE, ''),
|
'filename' => new external_value(PARAM_FILE, ''),
|
||||||
'isdir' => new external_value(PARAM_BOOL, ''),
|
'isdir' => new external_value(PARAM_BOOL, ''),
|
||||||
'url' => new external_value(PARAM_TEXT, ''),
|
'url' => new external_value(PARAM_TEXT, ''),
|
||||||
|
'timemodified' => new external_value(PARAM_INT, ''),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -219,12 +235,14 @@ class core_files_external extends external_api {
|
||||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||||
global $USER, $CFG;
|
global $USER, $CFG;
|
||||||
|
|
||||||
$fileinfo = self::validate_parameters(self::upload_parameters(), array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename, 'filecontent'=>$filecontent));
|
$fileinfo = self::validate_parameters(self::upload_parameters(), array(
|
||||||
|
'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid,
|
||||||
|
'filepath'=>$filepath, 'filename'=>$filename, 'filecontent'=>$filecontent));
|
||||||
|
|
||||||
if (!isset($fileinfo['filecontent'])) {
|
if (!isset($fileinfo['filecontent'])) {
|
||||||
throw new moodle_exception('nofile');
|
throw new moodle_exception('nofile');
|
||||||
}
|
}
|
||||||
// saving file
|
// Saving file.
|
||||||
$dir = make_temp_directory('wsupload');
|
$dir = make_temp_directory('wsupload');
|
||||||
|
|
||||||
if (empty($fileinfo['filename'])) {
|
if (empty($fileinfo['filename'])) {
|
||||||
|
@ -239,7 +257,6 @@ class core_files_external extends external_api {
|
||||||
$savedfilepath = $dir.$filename;
|
$savedfilepath = $dir.$filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
|
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
|
||||||
unset($fileinfo['filecontent']);
|
unset($fileinfo['filecontent']);
|
||||||
|
|
||||||
|
@ -250,7 +267,7 @@ class core_files_external extends external_api {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fileinfo['itemid'])) {
|
if (isset($fileinfo['itemid'])) {
|
||||||
// TODO MDL-31116 in user private area, itemid is always 0
|
// TODO MDL-31116 in user private area, itemid is always 0.
|
||||||
$itemid = 0;
|
$itemid = 0;
|
||||||
} else {
|
} else {
|
||||||
throw new coding_exception('itemid cannot be empty');
|
throw new coding_exception('itemid cannot be empty');
|
||||||
|
@ -265,19 +282,19 @@ class core_files_external extends external_api {
|
||||||
if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'private')) {
|
if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'private')) {
|
||||||
throw new coding_exception('File can be uploaded to user private area only');
|
throw new coding_exception('File can be uploaded to user private area only');
|
||||||
} else {
|
} else {
|
||||||
// TODO MDL-31116 hard-coded to use user_private area
|
// TODO MDL-31116 hard-coded to use user_private area.
|
||||||
$component = 'user';
|
$component = 'user';
|
||||||
$filearea = 'private';
|
$filearea = 'private';
|
||||||
}
|
}
|
||||||
|
|
||||||
$browser = get_file_browser();
|
$browser = get_file_browser();
|
||||||
|
|
||||||
// check existing file
|
// Check existing file.
|
||||||
if ($file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
|
if ($file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||||
throw new moodle_exception('fileexist');
|
throw new moodle_exception('fileexist');
|
||||||
}
|
}
|
||||||
|
|
||||||
// move file to filepool
|
// Move file to filepool.
|
||||||
if ($dir = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, '.')) {
|
if ($dir = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, '.')) {
|
||||||
$info = $dir->create_file_from_pathname($filename, $savedfilepath);
|
$info = $dir->create_file_from_pathname($filename, $savedfilepath);
|
||||||
$params = $info->get_params();
|
$params = $info->get_params();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue