Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/report/outline/index.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 require('../../config.php');
00027 require_once($CFG->dirroot.'/report/outline/locallib.php');
00028 
00029 $id = required_param('id',PARAM_INT);       // course id
00030 
00031 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
00032 
00033 $PAGE->set_url('/report/outline/index.php', array('id'=>$id));
00034 $PAGE->set_pagelayout('report');
00035 
00036 require_login($course);
00037 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00038 require_capability('report/outline:view', $context);
00039 
00040 add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
00041 
00042 $showlastaccess = true;
00043 $hiddenfields = explode(',', $CFG->hiddenuserfields);
00044 
00045 if (array_search('lastaccess', $hiddenfields) and !has_capability('moodle/user:viewhiddendetails', $context)) {
00046     $showlastaccess = false;
00047 }
00048 
00049 $stractivityreport = get_string('pluginname', 'report_outline');
00050 $stractivity       = get_string('activity');
00051 $strlast           = get_string('lastaccess');
00052 $strreports        = get_string('reports');
00053 $strviews          = get_string('views');
00054 $strrelatedblogentries = get_string('relatedblogentries', 'blog');
00055 
00056 $PAGE->set_title($course->shortname .': '. $stractivityreport);
00057 $PAGE->set_heading($course->fullname);
00058 echo $OUTPUT->header();
00059 echo $OUTPUT->heading(format_string($course->fullname));
00060 
00061 if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
00062     print_error('logfilenotavailable');
00063 }
00064 
00065 echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');
00066 
00067 $outlinetable = new html_table();
00068 $outlinetable->attributes['class'] = 'generaltable boxaligncenter';
00069 $outlinetable->cellpadding = 5;
00070 $outlinetable->id = 'outlinetable';
00071 $outlinetable->head = array($stractivity, $strviews);
00072 
00073 if ($CFG->useblogassociations) {
00074     $outlinetable->head[] = $strrelatedblogentries;
00075 }
00076 
00077 if ($showlastaccess) {
00078     $outlinetable->head[] = $strlast;
00079 }
00080 
00081 $modinfo = get_fast_modinfo($course);
00082 $sections = get_all_sections($course->id);
00083 
00084 $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
00085           FROM {course_modules} cm
00086                JOIN {modules} m ON m.id = cm.module
00087                JOIN {log} l     ON l.cmid = cm.id
00088          WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
00089       GROUP BY cm.id";
00090 $views = $DB->get_records_sql($sql, array($course->id));
00091 
00092 $prevsecctionnum = 0;
00093 foreach ($modinfo->sections as $sectionnum=>$section) {
00094     foreach ($section as $cmid) {
00095         $cm = $modinfo->cms[$cmid];
00096         if (!$cm->has_view()) {
00097             continue;
00098         }
00099         if (!$cm->uservisible) {
00100             continue;
00101         }
00102         if ($prevsecctionnum != $sectionnum) {
00103             $sectionrow = new html_table_row();
00104             $sectionrow->attributes['class'] = 'section';
00105             $sectioncell = new html_table_cell();
00106             $sectioncell->colspan = count($outlinetable->head);
00107 
00108             $sectiontitle = get_section_name($course, $sections[$sectionnum]);
00109 
00110             $sectioncell->text = $OUTPUT->heading($sectiontitle, 3);
00111             $sectionrow->cells[] = $sectioncell;
00112             $outlinetable->data[] = $sectionrow;
00113 
00114             $prevsecctionnum = $sectionnum;
00115         }
00116 
00117         $dimmed = $cm->visible ? '' : 'class="dimmed"';
00118         $modulename = get_string('modulename', $cm->modname);
00119 
00120         $reportrow = new html_table_row();
00121         $activitycell = new html_table_cell();
00122         $activitycell->attributes['class'] = 'activity';
00123 
00124         $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));
00125 
00126         $attributes = array();
00127         if (!$cm->visible) {
00128             $attributes['class'] = 'dimmed';
00129         }
00130 
00131         $activitycell->text = $activityicon . html_writer::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name), $attributes);;
00132 
00133         $reportrow->cells[] = $activitycell;
00134 
00135         $numviewscell = new html_table_cell();
00136         $numviewscell->attributes['class'] = 'numviews';
00137 
00138         if (!empty($views[$cm->id]->numviews)) {
00139             $numviewscell->text = $views[$cm->id]->numviews;
00140         } else {
00141             $numviewscell->text = '-';
00142         }
00143 
00144         $reportrow->cells[] = $numviewscell;
00145 
00146         if ($CFG->useblogassociations) {
00147             require_once($CFG->dirroot.'/blog/lib.php');
00148             $blogcell = new html_table_cell();
00149             $blogcell->attributes['class'] = 'blog';
00150             if ($blogcount = blog_get_associated_count($course->id, $cm->id)) {
00151                 $blogcell->text = html_writer::link('/blog/index.php?modid='.$cm->id, $blogcount);
00152             } else {
00153                 $blogcell->text = '-';
00154             }
00155             $reportrow->cells[] = $blogcell;
00156         }
00157 
00158         if ($showlastaccess) {
00159             $lastaccesscell = new html_table_cell();
00160             $lastaccesscell->attributes['class'] = 'lastaccess';
00161 
00162             if (isset($views[$cm->id]->lasttime)) {
00163                 $timeago = format_time(time() - $views[$cm->id]->lasttime);
00164                 $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)";
00165             }
00166             $reportrow->cells[] = $lastaccesscell;
00167         }
00168         $outlinetable->data[] = $reportrow;
00169     }
00170 }
00171 echo html_writer::table($outlinetable);
00172 
00173 echo $OUTPUT->footer();
00174 
00175 
00176 
 All Data Structures Namespaces Files Functions Variables Enumerations