| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           4 | 
           //
  | 
        
        
            | 
            | 
           5 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           6 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           7 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           8 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           9 | 
           //
  | 
        
        
            | 
            | 
           10 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           11 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           12 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           13 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           14 | 
           //
  | 
        
        
            | 
            | 
           15 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           16 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
           /**
  | 
        
        
            | 
            | 
           19 | 
            * Display all recent activity in a flexible way
  | 
        
        
            | 
            | 
           20 | 
            *
  | 
        
        
            | 
            | 
           21 | 
            * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  | 
        
        
            | 
            | 
           22 | 
            * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            * @package course
  | 
        
        
            | 
            | 
           24 | 
            */
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           require_once('../config.php');
  | 
        
        
            | 
            | 
           27 | 
           require_once('lib.php');
  | 
        
        
            | 
            | 
           28 | 
           require_once('recent_form.php');
  | 
        
        
            | 
            | 
           29 | 
              | 
        
        
            | 
            | 
           30 | 
           $id = required_param('id', PARAM_INT);
  | 
        
        
            | 
            | 
           31 | 
              | 
        
        
            | 
            | 
           32 | 
           $PAGE->set_url('/course/recent.php', array('id'=>$id));
  | 
        
        
            | 
            | 
           33 | 
           $PAGE->set_pagelayout('report');
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
           if (!$course = $DB->get_record('course', array('id'=>$id))) {
  | 
        
        
            | 
            | 
           36 | 
               throw new \moodle_exception("That's an invalid course id");
  | 
        
        
            | 
            | 
           37 | 
           }
  | 
        
        
            | 
            | 
           38 | 
              | 
        
        
            | 
            | 
           39 | 
           require_login($course);
  | 
        
        
            | 
            | 
           40 | 
           $context = context_course::instance($course->id);
  | 
        
        
            | 
            | 
           41 | 
              | 
        
        
            | 
            | 
           42 | 
           \core\event\recent_activity_viewed::create(array('context' => $context))->trigger();
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           $lastlogin = time() - COURSE_MAX_RECENT_PERIOD;
  | 
        
        
            | 
            | 
           45 | 
           if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) {
  | 
        
        
            | 
            | 
           46 | 
               if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) {
  | 
        
        
            | 
            | 
           47 | 
                   $lastlogin = $USER->lastcourseaccess[$COURSE->id];
  | 
        
        
            | 
            | 
           48 | 
               }
  | 
        
        
            | 
            | 
           49 | 
           }
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
           $param = new stdClass();
  | 
        
        
            | 
            | 
           52 | 
           $param->user   = 0;
  | 
        
        
            | 
            | 
           53 | 
           $param->modid  = 'all';
  | 
        
        
            | 
            | 
           54 | 
           $param->group  = 0;
  | 
        
        
            | 
            | 
           55 | 
           $param->sortby = 'default';
  | 
        
        
            | 
            | 
           56 | 
           $param->date   = $lastlogin;
  | 
        
        
            | 
            | 
           57 | 
           $param->id     = $COURSE->id;
  | 
        
        
            | 
            | 
           58 | 
              | 
        
        
            | 
            | 
           59 | 
           $mform = new recent_form();
  | 
        
        
            | 
            | 
           60 | 
           $mform->set_data($param);
  | 
        
        
            | 
            | 
           61 | 
           if ($formdata = $mform->get_data()) {
  | 
        
        
            | 
            | 
           62 | 
               $param = $formdata;
  | 
        
        
            | 
            | 
           63 | 
           }
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
           $userinfo = get_string('allparticipants');
  | 
        
        
            | 
            | 
           66 | 
           $dateinfo = get_string('alldays');
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
           if (!empty($param->user)) {
  | 
        
        
            | 
            | 
           69 | 
               if (!$u = $DB->get_record('user', array('id'=>$param->user))) {
  | 
        
        
            | 
            | 
           70 | 
                   throw new \moodle_exception("That's an invalid user!");
  | 
        
        
            | 
            | 
           71 | 
               }
  | 
        
        
            | 
            | 
           72 | 
               $userinfo = fullname($u);
  | 
        
        
            | 
            | 
           73 | 
           }
  | 
        
        
            | 
            | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
           $strrecentactivity = get_string('recentactivity');
  | 
        
        
            | 
            | 
           76 | 
           $PAGE->navbar->add($strrecentactivity, new moodle_url('/course/recent.php', array('id'=>$course->id)));
  | 
        
        
            | 
            | 
           77 | 
           $PAGE->navbar->add($userinfo);
  | 
        
        
            | 
            | 
           78 | 
           $PAGE->set_title("$course->shortname: $strrecentactivity");
  | 
        
        
            | 
            | 
           79 | 
           $PAGE->set_heading($course->fullname);
  | 
        
        
            | 
            | 
           80 | 
           echo $OUTPUT->header();
  | 
        
        
            | 
            | 
           81 | 
           echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo", 2);
  | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
           $mform->display();
  | 
        
        
            | 
            | 
           84 | 
              | 
        
        
            | 
            | 
           85 | 
           $modinfo = get_fast_modinfo($course);
  | 
        
        
            | 
            | 
           86 | 
           $modnames = get_module_types_names();
  | 
        
        
            | 
            | 
           87 | 
              | 
        
        
            | 
            | 
           88 | 
           if (has_capability('moodle/course:viewhiddensections', $context)) {
  | 
        
        
            | 
            | 
           89 | 
               $hiddenfilter = "";
  | 
        
        
            | 
            | 
           90 | 
           } else {
  | 
        
        
            | 
            | 
           91 | 
               $hiddenfilter = "AND cs.visible = 1";
  | 
        
        
            | 
            | 
           92 | 
           }
  | 
        
        
            | 
            | 
           93 | 
           $sections = array();
  | 
        
        
            | 
            | 
           94 | 
           foreach ($modinfo->get_section_info_all() as $i => $section) {
  | 
        
        
            | 
            | 
           95 | 
               if (!empty($section->uservisible)) {
  | 
        
        
            | 
            | 
           96 | 
                   $sections[$i] = $section;
  | 
        
        
            | 
            | 
           97 | 
               }
  | 
        
        
            | 
            | 
           98 | 
           }
  | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
           if ($param->modid === 'all') {
  | 
        
        
            | 
            | 
           101 | 
               // ok
  | 
        
        
            | 
            | 
           102 | 
              | 
        
        
            | 
            | 
           103 | 
           } else if (strpos($param->modid, 'mod/') === 0) {
  | 
        
        
            | 
            | 
           104 | 
               $modname = substr($param->modid, strlen('mod/'));
  | 
        
        
            | 
            | 
           105 | 
               if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
  | 
        
        
            | 
            | 
           106 | 
                   $filter = $modname;
  | 
        
        
            | 
            | 
           107 | 
               }
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
           } else if (strpos($param->modid, 'section/') === 0) {
  | 
        
        
            | 
            | 
           110 | 
               $sectionid = substr($param->modid, strlen('section/'));
  | 
        
        
            | 
            | 
           111 | 
               if (isset($sections[$sectionid])) {
  | 
        
        
            | 
            | 
           112 | 
                   $sections = array($sectionid=>$sections[$sectionid]);
  | 
        
        
            | 
            | 
           113 | 
               }
  | 
        
        
            | 
            | 
           114 | 
              | 
        
        
            | 
            | 
           115 | 
           } else if (is_numeric($param->modid)) {
  | 
        
        
            | 
            | 
           116 | 
               $sectionnum = $modinfo->cms[$param->modid]->sectionnum;
  | 
        
        
            | 
            | 
           117 | 
               $filter_modid = $param->modid;
  | 
        
        
            | 
            | 
           118 | 
               $sections = array($sectionnum => $sections[$sectionnum]);
  | 
        
        
            | 
            | 
           119 | 
           }
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
           $activities = array();
  | 
        
        
            | 
            | 
           122 | 
           $index = 0;
  | 
        
        
            | 
            | 
           123 | 
              | 
        
        
            | 
            | 
           124 | 
           foreach ($sections as $sectionnum => $section) {
  | 
        
        
            | 
            | 
           125 | 
              | 
        
        
            | 
            | 
           126 | 
               $activity = new stdClass();
  | 
        
        
            | 
            | 
           127 | 
               $activity->type = 'section';
  | 
        
        
            | 
            | 
           128 | 
               if ($section->section > 0) {
  | 
        
        
            | 
            | 
           129 | 
                   $activity->name = get_section_name($course, $section);
  | 
        
        
            | 
            | 
           130 | 
               } else {
  | 
        
        
            | 
            | 
           131 | 
                   $activity->name = '';
  | 
        
        
            | 
            | 
           132 | 
               }
  | 
        
        
            | 
            | 
           133 | 
              | 
        
        
            | 
            | 
           134 | 
               $activity->visible = $section->visible;
  | 
        
        
            | 
            | 
           135 | 
               $activities[$index++] = $activity;
  | 
        
        
            | 
            | 
           136 | 
              | 
        
        
            | 
            | 
           137 | 
               if (empty($modinfo->sections[$sectionnum])) {
  | 
        
        
            | 
            | 
           138 | 
                   continue;
  | 
        
        
            | 
            | 
           139 | 
               }
  | 
        
        
            | 
            | 
           140 | 
              | 
        
        
            | 
            | 
           141 | 
               foreach ($modinfo->sections[$sectionnum] as $cmid) {
  | 
        
        
            | 
            | 
           142 | 
                   $cm = $modinfo->cms[$cmid];
  | 
        
        
            | 
            | 
           143 | 
              | 
        
        
            | 
            | 
           144 | 
                   if (!$cm->uservisible) {
  | 
        
        
            | 
            | 
           145 | 
                       continue;
  | 
        
        
            | 
            | 
           146 | 
                   }
  | 
        
        
            | 
            | 
           147 | 
              | 
        
        
            | 
            | 
           148 | 
                   if (!empty($filter) and $cm->modname != $filter) {
  | 
        
        
            | 
            | 
           149 | 
                       continue;
  | 
        
        
            | 
            | 
           150 | 
                   }
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   if (!empty($filter_modid) and $cmid != $filter_modid) {
  | 
        
        
            | 
            | 
           153 | 
                       continue;
  | 
        
        
            | 
            | 
           154 | 
                   }
  | 
        
        
            | 
            | 
           155 | 
              | 
        
        
            | 
            | 
           156 | 
                   $libfile = "$CFG->dirroot/mod/$cm->modname/lib.php";
  | 
        
        
            | 
            | 
           157 | 
              | 
        
        
            | 
            | 
           158 | 
                   if (file_exists($libfile)) {
  | 
        
        
            | 
            | 
           159 | 
                       require_once($libfile);
  | 
        
        
            | 
            | 
           160 | 
                       $get_recent_mod_activity = $cm->modname."_get_recent_mod_activity";
  | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
                       if (function_exists($get_recent_mod_activity)) {
  | 
        
        
            | 
            | 
           163 | 
                           $activity = new stdClass();
  | 
        
        
            | 
            | 
           164 | 
                           $activity->type    = 'activity';
  | 
        
        
            | 
            | 
           165 | 
                           $activity->cmid    = $cmid;
  | 
        
        
            | 
            | 
           166 | 
                           $activities[$index++] = $activity;
  | 
        
        
            | 
            | 
           167 | 
                           $get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group);
  | 
        
        
            | 
            | 
           168 | 
                       }
  | 
        
        
            | 
            | 
           169 | 
                   }
  | 
        
        
            | 
            | 
           170 | 
               }
  | 
        
        
            | 
            | 
           171 | 
           }
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
           $detail = true;
  | 
        
        
            | 
            | 
           174 | 
              | 
        
        
            | 
            | 
           175 | 
           switch ($param->sortby) {
  | 
        
        
            | 
            | 
           176 | 
               case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break;
  | 
        
        
            | 
            | 
           177 | 
               case 'dateasc'  : usort($activities, 'compare_activities_by_time_asc'); break;
  | 
        
        
            | 
            | 
           178 | 
               case 'default'  :
  | 
        
        
            | 
            | 
           179 | 
               default         : $detail = false; $param->sortby = 'default';
  | 
        
        
            | 
            | 
           180 | 
              | 
        
        
            | 
            | 
           181 | 
           }
  | 
        
        
            | 
            | 
           182 | 
              | 
        
        
            | 
            | 
           183 | 
           if (!empty($activities)) {
  | 
        
        
            | 
            | 
           184 | 
              | 
        
        
            | 
            | 
           185 | 
               $newsection   = true;
  | 
        
        
            | 
            | 
           186 | 
               $lastsection  = '';
  | 
        
        
            | 
            | 
           187 | 
               $newinstance  = true;
  | 
        
        
            | 
            | 
           188 | 
               $lastinstance = '';
  | 
        
        
            | 
            | 
           189 | 
               $inbox        = false;
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
               $section = 0;
  | 
        
        
            | 
            | 
           192 | 
              | 
        
        
            | 
            | 
           193 | 
               $activity_count = count($activities);
  | 
        
        
            | 
            | 
           194 | 
               $viewfullnames  = array();
  | 
        
        
            | 
            | 
           195 | 
              | 
        
        
            | 
            | 
           196 | 
               foreach ($activities as $key => $activity) {
  | 
        
        
            | 
            | 
           197 | 
              | 
        
        
            | 
            | 
           198 | 
                   if ($activity->type == 'section') {
  | 
        
        
            | 
            | 
           199 | 
                       if ($param->sortby != 'default') {
  | 
        
        
            | 
            | 
           200 | 
                           continue; // no section if ordering by date
  | 
        
        
            | 
            | 
           201 | 
                       }
  | 
        
        
            | 
            | 
           202 | 
                       if ($activity_count == ($key + 1) or $activities[$key+1]->type == 'section') {
  | 
        
        
            | 
            | 
           203 | 
                       // peak at next activity.  If it's another section, don't print this one!
  | 
        
        
            | 
            | 
           204 | 
                       // this means there are no activities in the current section
  | 
        
        
            | 
            | 
           205 | 
                           continue;
  | 
        
        
            | 
            | 
           206 | 
                       }
  | 
        
        
            | 
            | 
           207 | 
                   }
  | 
        
        
            | 
            | 
           208 | 
              | 
        
        
            | 
            | 
           209 | 
                   if (($activity->type == 'section') && ($param->sortby == 'default')) {
  | 
        
        
            | 
            | 
           210 | 
                       if ($inbox) {
  | 
        
        
            | 
            | 
           211 | 
                           echo html_writer::end_tag('ul');
  | 
        
        
            | 
            | 
           212 | 
                           echo $OUTPUT->box_end();
  | 
        
        
            | 
            | 
           213 | 
                       }
  | 
        
        
            | 
            | 
           214 | 
                       echo $OUTPUT->box_start();
  | 
        
        
            | 
            | 
           215 | 
                       if (strval($activity->name) !== '') {
  | 
        
        
            | 
            | 
           216 | 
                           echo html_writer::tag('h3', $activity->name, ['class' => 'h5']);
  | 
        
        
            | 
            | 
           217 | 
                       }
  | 
        
        
            | 
            | 
           218 | 
                       echo html_writer::start_tag('ul', ['class' => 'list-unstyled']);
  | 
        
        
            | 
            | 
           219 | 
                       $inbox = true;
  | 
        
        
            | 
            | 
           220 | 
              | 
        
        
            | 
            | 
           221 | 
                   } else if ($activity->type == 'activity') {
  | 
        
        
            | 
            | 
           222 | 
              | 
        
        
            | 
            | 
           223 | 
                       if ($param->sortby == 'default') {
  | 
        
        
            | 
            | 
           224 | 
                           $cm = $modinfo->cms[$activity->cmid];
  | 
        
        
            | 
            | 
           225 | 
              | 
        
        
            | 
            | 
           226 | 
                           if ($cm->visible) {
  | 
        
        
            | 
            | 
           227 | 
                               $class = '';
  | 
        
        
            | 
            | 
           228 | 
                           } else {
  | 
        
        
            | 
            | 
           229 | 
                               $class = 'dimmed';
  | 
        
        
            | 
            | 
           230 | 
                           }
  | 
        
        
            | 
            | 
           231 | 
                           $name        = format_string($cm->name);
  | 
        
        
            | 
            | 
           232 | 
                           $modfullname = $modnames[$cm->modname];
  | 
        
        
            | 
            | 
           233 | 
              | 
        
        
            | 
            | 
           234 | 
                           $image = $OUTPUT->pix_icon('monologo', $modfullname, $cm->modname, array('class' => 'icon smallicon'));
  | 
        
        
            | 
            | 
           235 | 
                           $link = html_writer::link(new moodle_url("/mod/$cm->modname/view.php",
  | 
        
        
            | 
            | 
           236 | 
                                       array("id" => $cm->id)), $name, array('class' => $class));
  | 
        
        
            | 
            | 
           237 | 
                           echo html_writer::tag('li', "$image $modfullname $link");
  | 
        
        
            | 
            | 
           238 | 
                      }
  | 
        
        
            | 
            | 
           239 | 
              | 
        
        
            | 
            | 
           240 | 
                   } else {
  | 
        
        
            | 
            | 
           241 | 
              | 
        
        
            | 
            | 
           242 | 
                       if (!isset($viewfullnames[$activity->cmid])) {
  | 
        
        
            | 
            | 
           243 | 
                           $cm_context = context_module::instance($activity->cmid);
  | 
        
        
            | 
            | 
           244 | 
                           $viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context);
  | 
        
        
            | 
            | 
           245 | 
                       }
  | 
        
        
            | 
            | 
           246 | 
              | 
        
        
            | 
            | 
           247 | 
                       if (!$inbox) {
  | 
        
        
            | 
            | 
           248 | 
                           echo $OUTPUT->box_start();
  | 
        
        
            | 
            | 
           249 | 
                           $inbox = true;
  | 
        
        
            | 
            | 
           250 | 
                       }
  | 
        
        
            | 
            | 
           251 | 
              | 
        
        
            | 
            | 
           252 | 
                       $print_recent_mod_activity = $activity->type.'_print_recent_mod_activity';
  | 
        
        
            | 
            | 
           253 | 
              | 
        
        
            | 
            | 
           254 | 
                       if (function_exists($print_recent_mod_activity)) {
  | 
        
        
            | 
            | 
           255 | 
                           echo html_writer::start_tag('li');
  | 
        
        
            | 
            | 
           256 | 
                           $print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]);
  | 
        
        
            | 
            | 
           257 | 
                           echo html_writer::end_tag('li');
  | 
        
        
            | 
            | 
           258 | 
                       }
  | 
        
        
            | 
            | 
           259 | 
                   }
  | 
        
        
            | 
            | 
           260 | 
               }
  | 
        
        
            | 
            | 
           261 | 
              | 
        
        
            | 
            | 
           262 | 
               if ($inbox) {
  | 
        
        
            | 
            | 
           263 | 
                   echo $OUTPUT->box_end();
  | 
        
        
            | 
            | 
           264 | 
               }
  | 
        
        
            | 
            | 
           265 | 
              | 
        
        
            | 
            | 
           266 | 
              | 
        
        
            | 
            | 
           267 | 
           } else {
  | 
        
        
            | 
            | 
           268 | 
              | 
        
        
            | 
            | 
           269 | 
               echo html_writer::tag('h3', get_string('norecentactivity'), array('class' => 'mdl-align'));
  | 
        
        
            | 
            | 
           270 | 
              | 
        
        
            | 
            | 
           271 | 
           }
  | 
        
        
            | 
            | 
           272 | 
              | 
        
        
            | 
            | 
           273 | 
           echo $OUTPUT->footer();
  | 
        
        
            | 
            | 
           274 | 
              |