Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/resources.php
Go to the documentation of this file.
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 
00026 require_once('../config.php');
00027 require_once("$CFG->libdir/resourcelib.php");
00028 
00029 $id = required_param('id', PARAM_INT); // course id
00030 
00031 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
00032 $PAGE->set_pagelayout('course');
00033 require_course_login($course, true);
00034 
00035 // get list of all resource-like modules
00036 $allmodules = $DB->get_records('modules', array('visible'=>1));
00037 $modules = array();
00038 foreach ($allmodules as $key=>$module) {
00039     $modname = $module->name;
00040     $libfile = "$CFG->dirroot/mod/$modname/lib.php";
00041     if (!file_exists($libfile)) {
00042         continue;
00043     }
00044     $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
00045     if ($archetype != MOD_ARCHETYPE_RESOURCE) {
00046         continue;
00047     }
00048 
00049     $modules[$modname] = get_string('modulename', $modname);
00050     //some hacky nasic logging
00051     add_to_log($course->id, $modname, 'view all', "index.php?id=$course->id", '');
00052 }
00053 
00054 $strresources    = get_string('resources');
00055 $strsectionname  = get_string('sectionname', 'format_'.$course->format);
00056 $strname         = get_string('name');
00057 $strintro        = get_string('moduleintro');
00058 $strlastmodified = get_string('lastmodified');
00059 
00060 $PAGE->set_url('/course/resources.php', array('id' => $course->id));
00061 $PAGE->set_title($course->shortname.': '.$strresources);
00062 $PAGE->set_heading($course->fullname);
00063 $PAGE->navbar->add($strresources);
00064 echo $OUTPUT->header();
00065 
00066 $modinfo = get_fast_modinfo($course);
00067 $usesections = course_format_uses_sections($course->format);
00068 if ($usesections) {
00069     $sections = get_all_sections($course->id);
00070 }
00071 $cms = array();
00072 $resources = array();
00073 foreach ($modinfo->cms as $cm) {
00074     if (!$cm->uservisible) {
00075         continue;
00076     }
00077     if (!array_key_exists($cm->modname, $modules)) {
00078         continue;
00079     }
00080     if (!$cm->has_view()) {
00081         // Exclude label and similar
00082         continue;
00083     }
00084     $cms[$cm->id] = $cm;
00085     $resources[$cm->modname][] = $cm->instance;
00086 }
00087 
00088 // preload instances
00089 foreach ($resources as $modname=>$instances) {
00090     $resources[$modname] = $DB->get_records_list($modname, 'id', $instances, 'id', 'id,name,intro,introformat,timemodified');
00091 }
00092 
00093 if (!$cms) {
00094     notice(get_string('thereareno', 'moodle', $strresources), "$CFG->wwwroot/course/view.php?id=$course->id");
00095     exit;
00096 }
00097 
00098 $table = new html_table();
00099 $table->attributes['class'] = 'generaltable mod_index';
00100 
00101 if ($usesections) {
00102     $table->head  = array ($strsectionname, $strname, $strintro);
00103     $table->align = array ('center', 'left', 'left');
00104 } else {
00105     $table->head  = array ($strlastmodified, $strname, $strintro);
00106     $table->align = array ('left', 'left', 'left');
00107 }
00108 
00109 $currentsection = '';
00110 foreach ($cms as $cm) {
00111     if (!isset($resources[$cm->modname][$cm->instance])) {
00112         continue;
00113     }
00114     $resource = $resources[$cm->modname][$cm->instance];
00115     if ($usesections) {
00116         $printsection = '';
00117         if ($cm->sectionnum !== $currentsection) {
00118             if ($cm->sectionnum) {
00119                 $printsection = get_section_name($course, $sections[$cm->sectionnum]);
00120             }
00121             if ($currentsection !== '') {
00122                 $table->data[] = 'hr';
00123             }
00124             $currentsection = $cm->sectionnum;
00125         }
00126     } else {
00127         $printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
00128     }
00129 
00130     $extra = empty($cm->extra) ? '' : $cm->extra;
00131     if (!empty($cm->icon)) {
00132         $icon = '<img src="'.$OUTPUT->pix_url($cm->icon).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
00133     } else {
00134         $icon = '<img src="'.$OUTPUT->pix_url('icon', $cm->modname).'" class="activityicon" alt="'.get_string('modulename', $cm->modname).'" /> ';
00135     }
00136 
00137     $class = $cm->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
00138     $table->data[] = array (
00139         $printsection,
00140         "<a $class $extra href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\">".$icon.format_string($resource->name)."</a>",
00141         format_module_intro('resource', $resource, $cm->id));
00142 }
00143 
00144 echo html_writer::table($table);
00145 
00146 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations