|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00034 function folder_supports($feature) { 00035 switch($feature) { 00036 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE; 00037 case FEATURE_GROUPS: return false; 00038 case FEATURE_GROUPINGS: return false; 00039 case FEATURE_GROUPMEMBERSONLY: return true; 00040 case FEATURE_MOD_INTRO: return true; 00041 case FEATURE_COMPLETION_TRACKS_VIEWS: return true; 00042 case FEATURE_GRADE_HAS_GRADE: return false; 00043 case FEATURE_GRADE_OUTCOMES: return false; 00044 case FEATURE_BACKUP_MOODLE2: return true; 00045 case FEATURE_SHOW_DESCRIPTION: return true; 00046 00047 default: return null; 00048 } 00049 } 00050 00055 function folder_get_extra_capabilities() { 00056 return array('moodle/site:accessallgroups'); 00057 } 00058 00064 function folder_reset_userdata($data) { 00065 return array(); 00066 } 00067 00072 function folder_get_view_actions() { 00073 return array('view', 'view all'); 00074 } 00075 00080 function folder_get_post_actions() { 00081 return array('update', 'add'); 00082 } 00083 00090 function folder_add_instance($data, $mform) { 00091 global $DB; 00092 00093 $cmid = $data->coursemodule; 00094 $draftitemid = $data->files; 00095 00096 $data->timemodified = time(); 00097 $data->id = $DB->insert_record('folder', $data); 00098 00099 // we need to use context now, so we need to make sure all needed info is already in db 00100 $DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid)); 00101 $context = get_context_instance(CONTEXT_MODULE, $cmid); 00102 00103 if ($draftitemid) { 00104 file_save_draft_area_files($draftitemid, $context->id, 'mod_folder', 'content', 0, array('subdirs'=>true)); 00105 } 00106 00107 return $data->id; 00108 } 00109 00116 function folder_update_instance($data, $mform) { 00117 global $CFG, $DB; 00118 00119 $cmid = $data->coursemodule; 00120 $draftitemid = $data->files; 00121 00122 $data->timemodified = time(); 00123 $data->id = $data->instance; 00124 $data->revision++; 00125 00126 $DB->update_record('folder', $data); 00127 00128 $context = get_context_instance(CONTEXT_MODULE, $cmid); 00129 if ($draftitemid = file_get_submitted_draft_itemid('files')) { 00130 file_save_draft_area_files($draftitemid, $context->id, 'mod_folder', 'content', 0, array('subdirs'=>true)); 00131 } 00132 00133 return true; 00134 } 00135 00141 function folder_delete_instance($id) { 00142 global $DB; 00143 00144 if (!$folder = $DB->get_record('folder', array('id'=>$id))) { 00145 return false; 00146 } 00147 00148 // note: all context files are deleted automatically 00149 00150 $DB->delete_records('folder', array('id'=>$folder->id)); 00151 00152 return true; 00153 } 00154 00163 function folder_user_outline($course, $user, $mod, $folder) { 00164 global $DB; 00165 00166 if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'folder', 00167 'action'=>'view', 'info'=>$folder->id), 'time ASC')) { 00168 00169 $numviews = count($logs); 00170 $lastlog = array_pop($logs); 00171 00172 $result = new stdClass(); 00173 $result->info = get_string('numviews', '', $numviews); 00174 $result->time = $lastlog->time; 00175 00176 return $result; 00177 } 00178 return NULL; 00179 } 00180 00188 function folder_user_complete($course, $user, $mod, $folder) { 00189 global $CFG, $DB; 00190 00191 if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'folder', 00192 'action'=>'view', 'info'=>$folder->id), 'time ASC')) { 00193 $numviews = count($logs); 00194 $lastlog = array_pop($logs); 00195 00196 $strmostrecently = get_string('mostrecently'); 00197 $strnumviews = get_string('numviews', '', $numviews); 00198 00199 echo "$strnumviews - $strmostrecently ".userdate($lastlog->time); 00200 00201 } else { 00202 print_string('neverseen', 'folder'); 00203 } 00204 } 00205 00214 function folder_get_participants($folderid) { 00215 return false; 00216 } 00217 00225 function folder_get_file_areas($course, $cm, $context) { 00226 $areas = array(); 00227 $areas['content'] = get_string('foldercontent', 'folder'); 00228 00229 return $areas; 00230 } 00231 00245 function folder_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) { 00246 global $CFG; 00247 00248 00249 if ($filearea === 'content') { 00250 if (!has_capability('mod/folder:view', $context)) { 00251 return NULL; 00252 } 00253 $fs = get_file_storage(); 00254 00255 $filepath = is_null($filepath) ? '/' : $filepath; 00256 $filename = is_null($filename) ? '.' : $filename; 00257 if (!$storedfile = $fs->get_file($context->id, 'mod_folder', 'content', 0, $filepath, $filename)) { 00258 if ($filepath === '/' and $filename === '.') { 00259 $storedfile = new virtual_root_file($context->id, 'mod_folder', 'content', 0); 00260 } else { 00261 // not found 00262 return null; 00263 } 00264 } 00265 00266 require_once("$CFG->dirroot/mod/folder/locallib.php"); 00267 $urlbase = $CFG->wwwroot.'/pluginfile.php'; 00268 00269 // students may read files here 00270 $canwrite = has_capability('mod/folder:managefiles', $context); 00271 return new folder_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, $canwrite, false); 00272 } 00273 00274 // note: folder_intro handled in file_browser automatically 00275 00276 return null; 00277 } 00278 00290 function folder_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { 00291 global $CFG, $DB; 00292 00293 if ($context->contextlevel != CONTEXT_MODULE) { 00294 return false; 00295 } 00296 00297 require_course_login($course, true, $cm); 00298 if (!has_capability('mod/folder:view', $context)) { 00299 return false; 00300 } 00301 00302 if ($filearea !== 'content') { 00303 // intro is handled automatically in pluginfile.php 00304 return false; 00305 } 00306 00307 array_shift($args); // ignore revision - designed to prevent caching problems only 00308 00309 $fs = get_file_storage(); 00310 $relativepath = implode('/', $args); 00311 $fullpath = "/$context->id/mod_folder/content/0/$relativepath"; 00312 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { 00313 return false; 00314 } 00315 00316 // finally send the file 00317 // for folder module, we force download file all the time 00318 send_stored_file($file, 86400, 0, true); 00319 } 00320 00332 function folder_extend_navigation($navigation, $course, $module, $cm) { 00338 $navigation->nodetype = navigation_node::NODETYPE_LEAF; 00339 } 00340 00347 function folder_page_type_list($pagetype, $parentcontext, $currentcontext) { 00348 $module_pagetype = array('mod-folder-*'=>get_string('page-mod-folder-x', 'folder')); 00349 return $module_pagetype; 00350 } 00351 00357 function folder_export_contents($cm, $baseurl) { 00358 global $CFG, $DB; 00359 $contents = array(); 00360 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00361 $folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST); 00362 00363 $fs = get_file_storage(); 00364 $files = $fs->get_area_files($context->id, 'mod_folder', 'content', 0, 'sortorder DESC, id ASC', false); 00365 00366 foreach ($files as $fileinfo) { 00367 $file = array(); 00368 $file['type'] = 'file'; 00369 $file['filename'] = $fileinfo->get_filename(); 00370 $file['filepath'] = $fileinfo->get_filepath(); 00371 $file['filesize'] = $fileinfo->get_filesize(); 00372 $file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_folder/content/'.$folder->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true); 00373 $file['timecreated'] = $fileinfo->get_timecreated(); 00374 $file['timemodified'] = $fileinfo->get_timemodified(); 00375 $file['sortorder'] = $fileinfo->get_sortorder(); 00376 $file['userid'] = $fileinfo->get_userid(); 00377 $file['author'] = $fileinfo->get_author(); 00378 $file['license'] = $fileinfo->get_license(); 00379 $contents[] = $file; 00380 } 00381 00382 return $contents; 00383 }