Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-31863 Web service : added modified to parameters and modifiedtime…

… to description
  • Loading branch information...
commit 25ccaf54949cfafc1f61572dba203a3a76700089 1 parent 4db0616
Yang doraemonyoung authored nebgor committed

Showing 1 changed file with 50 additions and 33 deletions. Show diff stats Hide diff stats

  1. +50 33 files/externallib.php
83 files/externallib.php
@@ -52,7 +52,9 @@ public static function get_files_parameters() {
52 52 'filearea' => new external_value(PARAM_TEXT, 'file area'),
53 53 'itemid' => new external_value(PARAM_INT, 'associated id'),
54 54 'filepath' => new external_value(PARAM_PATH, 'file path'),
55   - 'filename' => new external_value(PARAM_FILE, 'file name')
  55 + 'filename' => new external_value(PARAM_FILE, 'file name'),
  56 + 'modified' => new external_value(PARAM_INT, 'timestamp, return files which the last ' .
  57 + 'timemodified time is the same or later than the specified time', VALUE_DEFAULT, null)
56 58 )
57 59 );
58 60 }
@@ -66,12 +68,16 @@ public static function get_files_parameters() {
66 68 * @param int $itemid item id
67 69 * @param string $filepath file path
68 70 * @param string $filename file name
  71 + * @param int $modified, timestamp, timestamp,
  72 + * return files which the last timemodified time is the same or later than the specified time
69 73 * @return array
70 74 * @since Moodle 2.2
71 75 */
72   - public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename) {
  76 + public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null) {
73 77 global $CFG, $USER, $OUTPUT;
74   - $fileinfo = self::validate_parameters(self::get_files_parameters(), array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename));
  78 + $fileinfo = self::validate_parameters(self::get_files_parameters(), array(
  79 + 'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea,
  80 + 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename, 'modified'=>$modified));
75 81
76 82 $browser = get_file_browser();
77 83
@@ -99,7 +105,9 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
99 105 $return = array();
100 106 $return['parents'] = array();
101 107 $return['files'] = array();
102   - if ($file = $browser->get_file_info($context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) {
  108 + if ($file = $browser->get_file_info(
  109 + $context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'],
  110 + $fileinfo['filepath'], $fileinfo['filename'])) {
103 111 $level = $file->get_parent();
104 112 while ($level) {
105 113 $params = $level->get_params();
@@ -112,31 +120,38 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
112 120 foreach ($children as $child) {
113 121
114 122 $params = $child->get_params();
  123 + $timemodified = $child->get_timemodified();
115 124
116 125 if ($child->is_directory()) {
117   - $node = array(
118   - 'contextid' => $params['contextid'],
119   - 'component' => $params['component'],
120   - 'filearea' => $params['filearea'],
121   - 'itemid' => $params['itemid'],
122   - 'filepath' => $params['filepath'],
123   - 'filename' => $child->get_visible_name(),
124   - 'url' => null,
125   - 'isdir' => true
126   - );
127   - $list[] = $node;
  126 + if ((is_null($modified)) or ($modified <= $timemodified)) {
  127 + $node = array(
  128 + 'contextid' => $params['contextid'],
  129 + 'component' => $params['component'],
  130 + 'filearea' => $params['filearea'],
  131 + 'itemid' => $params['itemid'],
  132 + 'filepath' => $params['filepath'],
  133 + 'filename' => $child->get_visible_name(),
  134 + 'url' => null,
  135 + 'isdir' => true,
  136 + 'timemodified' => $timemodified
  137 + );
  138 + $list[] = $node;
  139 + }
128 140 } else {
129   - $node = array(
130   - 'contextid' => $params['contextid'],
131   - 'component' => $params['component'],
132   - 'filearea' => $params['filearea'],
133   - 'itemid' => $params['itemid'],
134   - 'filepath' => $params['filepath'],
135   - 'filename' => $child->get_visible_name(),
136   - 'url' => $child->get_url(),
137   - 'isdir' => false
138   - );
139   - $list[] = $node;
  141 + if ((is_null($modified)) or ($modified <= $timemodified)) {
  142 + $node = array(
  143 + 'contextid' => $params['contextid'],
  144 + 'component' => $params['component'],
  145 + 'filearea' => $params['filearea'],
  146 + 'itemid' => $params['itemid'],
  147 + 'filepath' => $params['filepath'],
  148 + 'filename' => $child->get_visible_name(),
  149 + 'url' => $child->get_url(),
  150 + 'isdir' => false,
  151 + 'timemodified' => $timemodified
  152 + );
  153 + $list[] = $node;
  154 + }
140 155 }
141 156 }
142 157 }
@@ -176,6 +191,7 @@ public static function get_files_returns() {
176 191 'filename' => new external_value(PARAM_FILE, ''),
177 192 'isdir' => new external_value(PARAM_BOOL, ''),
178 193 'url' => new external_value(PARAM_TEXT, ''),
  194 + 'timemodified' => new external_value(PARAM_INT, ''),
179 195 )
180 196 )
181 197 )
@@ -219,12 +235,14 @@ public static function upload_parameters() {
219 235 public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
220 236 global $USER, $CFG;
221 237
222   - $fileinfo = self::validate_parameters(self::upload_parameters(), array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename, 'filecontent'=>$filecontent));
  238 + $fileinfo = self::validate_parameters(self::upload_parameters(), array(
  239 + 'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid,
  240 + 'filepath'=>$filepath, 'filename'=>$filename, 'filecontent'=>$filecontent));
223 241
224 242 if (!isset($fileinfo['filecontent'])) {
225 243 throw new moodle_exception('nofile');
226 244 }
227   - // saving file
  245 + // Saving file.
228 246 $dir = make_temp_directory('wsupload');
229 247
230 248 if (empty($fileinfo['filename'])) {
@@ -239,7 +257,6 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
239 257 $savedfilepath = $dir.$filename;
240 258 }
241 259
242   -
243 260 file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
244 261 unset($fileinfo['filecontent']);
245 262
@@ -250,7 +267,7 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
250 267 }
251 268
252 269 if (isset($fileinfo['itemid'])) {
253   - // TODO MDL-31116 in user private area, itemid is always 0
  270 + // TODO MDL-31116 in user private area, itemid is always 0.
254 271 $itemid = 0;
255 272 } else {
256 273 throw new coding_exception('itemid cannot be empty');
@@ -265,19 +282,19 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
265 282 if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'private')) {
266 283 throw new coding_exception('File can be uploaded to user private area only');
267 284 } else {
268   - // TODO MDL-31116 hard-coded to use user_private area
  285 + // TODO MDL-31116 hard-coded to use user_private area.
269 286 $component = 'user';
270 287 $filearea = 'private';
271 288 }
272 289
273 290 $browser = get_file_browser();
274 291
275   - // check existing file
  292 + // Check existing file.
276 293 if ($file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
277 294 throw new moodle_exception('fileexist');
278 295 }
279 296
280   - // move file to filepool
  297 + // Move file to filepool.
281 298 if ($dir = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, '.')) {
282 299 $info = $dir->create_file_from_pathname($filename, $savedfilepath);
283 300 $params = $info->get_params();

0 comments on commit 25ccaf5

Please sign in to comment.
Something went wrong with that request. Please try again.