/** * Print recent activity from all assignments in a given course * * This is used by the recent activity block * @param mixed $course the course to print activity for * @param bool $viewfullnames boolean to determine whether to show full names or not * @param int $timestart the time the rendering started * @return bool true if activity was printed, false otherwise. */ function assign_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; require_once $CFG->dirroot . '/mod/assign/locallib.php'; // Do not use log table if possible, it may be huge. $dbparams = array($timestart, $course->id, 'assign', ASSIGN_SUBMISSION_STATUS_SUBMITTED); $namefields = user_picture::fields('u', null, 'userid'); if (!($submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, um.id as recordid,\n {$namefields}\n FROM {assign_submission} asb\n JOIN {assign} a ON a.id = asb.assignment\n JOIN {course_modules} cm ON cm.instance = a.id\n JOIN {modules} md ON md.id = cm.module\n JOIN {user} u ON u.id = asb.userid\n LEFT JOIN {assign_user_mapping} um ON um.userid = u.id AND um.assignment = a.id\n WHERE asb.timemodified > ? AND\n asb.latest = 1 AND\n a.course = ? AND\n md.name = ? AND\n asb.status = ?\n ORDER BY asb.timemodified ASC", $dbparams))) { return false; } $modinfo = get_fast_modinfo($course); $show = array(); $grader = array(); $showrecentsubmissions = get_config('assign', 'showrecentsubmissions'); foreach ($submissions as $submission) { if (!array_key_exists($submission->cmid, $modinfo->get_cms())) { continue; } $cm = $modinfo->get_cm($submission->cmid); if (!$cm->uservisible) { continue; } if ($submission->userid == $USER->id) { $show[] = $submission; continue; } $context = context_module::instance($submission->cmid); // The act of submitting of assignment may be considered private - // only graders will see it if specified. if (empty($showrecentsubmissions)) { if (!array_key_exists($cm->id, $grader)) { $grader[$cm->id] = has_capability('moodle/grade:viewall', $context); } if (!$grader[$cm->id]) { continue; } } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // Shortcut - guest user does not belong into any group. continue; } // This will be slow - show only users that share group with me in this cm. if (!$modinfo->get_groups($cm->groupingid)) { continue; } $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid); if (is_array($usersgroups)) { $usersgroups = array_keys($usersgroups); $intersect = array_intersect($usersgroups, $modinfo->get_groups($cm->groupingid)); if (empty($intersect)) { continue; } } } $show[] = $submission; } if (empty($show)) { return false; } echo $OUTPUT->heading(get_string('newsubmissions', 'assign') . ':', 3); foreach ($show as $submission) { $cm = $modinfo->get_cm($submission->cmid); $context = context_module::instance($submission->cmid); $assign = new assign($context, $cm, $cm->course); $link = $CFG->wwwroot . '/mod/assign/view.php?id=' . $cm->id; // Obscure first and last name if blind marking enabled. if ($assign->is_blind_marking()) { $submission->firstname = get_string('participant', 'mod_assign'); if (empty($submission->recordid)) { $submission->recordid = $assign->get_uniqueid_for_user($submission->userid); } $submission->lastname = $submission->recordid; } print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); } return true; }
function elluminate_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a time, this module should find recent activity /// that has occurred in Blackboard Collaborate activities and print it out. /// Return true if there was output, or false is there was none. global $CFG; global $DB; $content = false; $meetings = NULL; $select = "time > {$timestart} AND course = {$course->id} AND " . "module = 'elluminate' AND action = 'view.meeting'"; if (!($logs = $DB->get_records_select('log', $select, null, 'time ASC'))) { return false; } foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod = new stdClass(); $tempmod->course = $log->course; $tempmod->id = $log->info; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible) { $sql = "SELECT e.name, u.firstname, u.lastname\n\t\t FROM {elluminate} e,\n\t\t {user} u" . "WHERE e.id = :elluminate\n \t\tAND u.id = :log"; $sql_params = array('elluminate' => $log->info, 'log' => $log->userid); $meetings[$log->info] = $DB->get_record_sql($sql, $sql_params); $meetings[$log->info]->time = $log->time; $meetings[$log->info]->url = str_replace('&', '&', $log->url); } } if ($meetings) { print_headline(get_string('newsubmissions', 'assignment') . ':'); foreach ($meetings as $meeting) { print_recent_activity_note($meeting->time, $meeting, $isteacher, stripslashes($meeting->name), $CFG->wwwroot . '/mod/elluminate/' . $meeting->url); } $content = true; } return $content; }
/** * Prints any recent dialogue activity since a given time * @param object $course * @param bool $viewfullnames capability * @param timestamp $timestart * @return bool success */ function dialogue_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG; // have a look for new entries $addentrycontent = false; $tempmod = new object(); // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; if ($logs = dialogue_get_add_entry_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { $tempmod->id = $log->dialogueid; //Obtain the visible property from the instance if (instance_is_visible('dialogue', $tempmod)) { $addentrycontent = true; break; } } // if we got some "live" ones then output them if ($addentrycontent) { print_headline(get_string('newdialogueentries', 'dialogue') . ':'); foreach ($logs as $log) { $tempmod->id = $log->dialogueid; $user = get_record('user', 'id', $log->userid); //Obtain the visible property from the instance if (instance_is_visible('dialogue', $tempmod)) { print_recent_activity_note($log->time, $user, $log->subject, $CFG->wwwroot . '/mod/dialogue/' . str_replace('&', '&', $log->url)); } } } } // have a look for open conversations $opencontent = false; if ($logs = dialogue_get_open_conversations($course)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->id = $log->dialogueid; //Obtain the visible property from the instance if (instance_is_visible('dialogue', $tempmod)) { $opencontent = true; break; } } // if we got some 'live' ones then output them if ($opencontent) { print_headline(get_string('opendialogueentries', 'dialogue') . ':'); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->id = $log->dialogueid; $user = get_record('user', 'id', $log->userid); //Obtain the visible property from the instance if (instance_is_visible('dialogue', $tempmod)) { print_recent_activity_note($log->time, $user, $log->name, $CFG->wwwroot . '/mod/dialogue/' . str_replace('&', '&', $log->url)); } } } } return $addentrycontent or $opencontent; }
/** * @global stdClass * @global object * @param object $course * @param mixed $viewfullnames * @param int $timestamp * @return bool */ function survey_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $DB, $OUTPUT; $modinfo = get_fast_modinfo($course); $ids = array(); foreach ($modinfo->cms as $cm) { if ($cm->modname != 'survey') { continue; } if (!$cm->uservisible) { continue; } $ids[$cm->instance] = $cm->instance; } if (!$ids) { return false; } $slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right? $allusernames = user_picture::fields('u'); $rs = $DB->get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time, $allusernames FROM {survey_answers} sa JOIN {user} u ON u.id = sa.userid WHERE sa.survey IN ($slist) AND sa.time > ? GROUP BY sa.userid, sa.survey, $allusernames ORDER BY time ASC", array($timestart)); if (!$rs->valid()) { $rs->close(); // Not going to iterate (but exit), close rs return false; } $surveys = array(); foreach ($rs as $survey) { $cm = $modinfo->instances['survey'][$survey->survey]; $survey->name = $cm->name; $survey->cmid = $cm->id; $surveys[] = $survey; } $rs->close(); if (!$surveys) { return false; } echo $OUTPUT->heading(get_string('newsurveyresponses', 'survey').':', 3); foreach ($surveys as $survey) { $url = $CFG->wwwroot.'/mod/survey/view.php?id='.$survey->cmid; print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames); } return true; }
/** * Given a course and a time, this module should find recent activity * that has occurred in wiki activities and print it out. * Return true if there was output, or false is there was none. * * @global stdClass * @global object * @param object $course * @param bool $isteacher * @param int $timestart * @return bool */ function wiki_print_recent_activity($course, $isteacher, $timestart) { global $CFG, $DB, $OUTPUT; $sql = "SELECT l.*, cm.instance\n FROM {log} l JOIN {course_modules} cm ON l.cmid = cm.id \n WHERE l.time > ? AND l.course = ? \n AND l.module = 'wiki' AND action LIKE 'edit%'\n ORDER BY l.time ASC"; if (!($logs = $DB->get_records_sql($sql, array($timestart, $course->id)))) { return false; } $modinfo = get_fast_modinfo($course); $wikis = array(); foreach ($logs as $log) { $cm = $modinfo->instances['wiki'][$log->instance]; if (!$cm->uservisible) { continue; } /// Process log->url and rebuild it here to properly clean the pagename - MDL-15896 $extractedpage = preg_replace('/^.*&page=/', '', $log->url); $log->url = preg_replace('/page=.*$/', 'page=' . urlencode($extractedpage), $log->url); $wikis[$log->info] = wiki_log_info($log); $wikis[$log->info]->pagename = $log->info; $wikis[$log->info]->time = $log->time; $wikis[$log->info]->url = str_replace('&', '&', $log->url); } if (!$wikis) { return false; } echo $OUTPUT->heading(get_string("updatedwikipages", 'wiki') . ':', 3); foreach ($wikis as $wiki) { print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot . '/mod/wiki/' . $wiki->url); } return false; }
function workshop_print_recent_activity($course, $viewfullanmes, $timestart) { global $CFG; $isteacher = has_capability('mod/workshop:manage', get_context_instance(CONTEXT_COURSE, $course->id)); $modinfo = get_fast_modinfo($course); // have a look for agreed assessments for this user (agree) $agreecontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_agree_logs($course, $timestart)) { $agreecontent = true; print_headline(get_string("workshopagreedassessments", "workshop") . ":"); foreach ($logs as $log) { if (!workshop_is_teacher($workshop, $log->userid)) { // don't break anonymous rule $log->firstname = $course->student; $log->lastname = ''; } print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } // have a look for new assessments for this user (assess) $assesscontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_assess_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['workshop'][$log->workshopid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $assesscontent = true; print_headline(get_string("workshopassessments", "workshop") . ":"); foreach ($logs as $log) { if (!workshop_is_teacher($tempmod->id, $log->userid)) { // don't break anonymous rule $log->firstname = $course->student; // Keep anonymous $log->lastname = ''; } print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } // have a look for new comments for this user (comment) $commentcontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_comment_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['workshop'][$log->workshopid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $commentcontent = true; print_headline(get_string("workshopcomments", "workshop") . ":"); foreach ($logs as $log) { $log->firstname = $course->student; // Keep anonymous $log->lastname = ''; print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } // have a look for new assessment gradings for this user (grade) $gradecontent = false; if ($logs = workshop_get_grade_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['workshop'][$log->workshopid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $gradecontent = true; print_headline(get_string("workshopfeedback", "workshop") . ":"); foreach ($logs as $log) { $log->firstname = $course->teacher; // Keep anonymous $log->lastname = ''; print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } // have a look for new submissions (only show to teachers) (submit) $submitcontent = false; if ($isteacher) { if ($logs = workshop_get_submit_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['workshop'][$log->workshopid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $submitcontent = true; print_headline(get_string("workshopsubmissions", "workshop") . ":"); foreach ($logs as $log) { print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } return $agreecontent or $assesscontent or $commentcontent or $gradecontent or $submitcontent; }
/** * Print recent activity from all assignments in a given course * * This is used by the recent activity block */ function assignment_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; // do not use log table if possible, it may be huge if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid, u.firstname, u.lastname, u.email, u.picture FROM {assignment_submissions} asb JOIN {assignment} a ON a.id = asb.assignment JOIN {course_modules} cm ON cm.instance = a.id JOIN {modules} md ON md.id = cm.module JOIN {user} u ON u.id = asb.userid WHERE asb.timemodified > ? AND a.course = ? AND md.name = 'assignment' ORDER BY asb.timemodified ASC", array($timestart, $course->id))) { return false; } $modinfo =& get_fast_modinfo($course); // reference needed because we might load the groups $show = array(); $grader = array(); foreach($submissions as $submission) { if (!array_key_exists($submission->cmid, $modinfo->cms)) { continue; } $cm = $modinfo->cms[$submission->cmid]; if (!$cm->uservisible) { continue; } if ($submission->userid == $USER->id) { $show[] = $submission; continue; } // the act of sumbitting of assignment may be considered private - only graders will see it if specified if (empty($CFG->assignment_showrecentsubmissions)) { if (!array_key_exists($cm->id, $grader)) { $grader[$cm->id] = has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_MODULE, $cm->id)); } if (!$grader[$cm->id]) { continue; } } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) { if (isguestuser()) { // shortcut - guest user does not belong into any group continue; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } // this will be slow - show only users that share group with me in this cm if (empty($modinfo->groups[$cm->id])) { continue; } $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid); if (is_array($usersgroups)) { $usersgroups = array_keys($usersgroups); $intersect = array_intersect($usersgroups, $modinfo->groups[$cm->id]); if (empty($intersect)) { continue; } } } $show[] = $submission; } if (empty($show)) { return false; } echo $OUTPUT->heading(get_string('newsubmissions', 'assignment').':', 3); foreach ($show as $submission) { $cm = $modinfo->cms[$submission->cmid]; $link = $CFG->wwwroot.'/mod/assignment/view.php?id='.$cm->id; print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); } return true; }
function wiki_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a time, this module should find recent activity /// that has occurred in wiki activities and print it out. /// Return true if there was output, or false is there was none. global $CFG; $sql = "SELECT l.*, cm.instance FROM {$CFG->prefix}log l \n INNER JOIN {$CFG->prefix}course_modules cm ON l.cmid = cm.id \n WHERE l.time > '{$timestart}' AND l.course = {$course->id} \n AND l.module = 'wiki' AND action LIKE 'edit%'\n ORDER BY l.time ASC"; if (!($logs = get_records_sql($sql))) { return false; } foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod = new Object(); $tempmod->course = $log->course; $tempmod->id = $log->instance; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible) { $wikis[$log->info] = wiki_log_info($log); $wikis[$log->info]->pagename = $log->info; $wikis[$log->info]->time = $log->time; $wikis[$log->info]->url = str_replace('&', '&', $log->url); } } if (isset($wikis)) { $content = true; print_headline(get_string('updatedwikipages', 'wiki') . ':', 3); foreach ($wikis as $wiki) { print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot . '/mod/wiki/' . $wiki->url); } } return true; // True if anything was printed, otherwise false }
function exercise_print_recent_activity($course, $viewfullanmes, $timestart) { global $CFG; $isteacher = has_capability('mod/exercise:assess', get_context_instance(CONTEXT_COURSE, $course->id)); $modinfo = get_fast_modinfo($course); // have a look for new submissions (only show to teachers) $submitcontent = false; if ($isteacher) { if ($logs = exercise_get_submit_logs($course, $timestart)) { // if we got some 'live' ones then output them $submitcontent = true; print_headline(get_string('exercisesubmissions', 'exercise') . ':'); foreach ($logs as $log) { print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/exercise/' . str_replace('&', '&', $log->url)); } } } // have a look for new assessment gradings for this user $gradecontent = false; if ($logs = exercise_get_grade_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['exercise'][$log->exerciseid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $gradecontent = true; print_headline(get_string('exercisefeedback', 'exercise') . ':'); foreach ($logs as $log) { print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/exercise/' . str_replace('&', '&', $log->url)); } } } // have a look for new assessments for this user $assesscontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = exercise_get_assess_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $id => $log) { $cm = $modinfo->instances['exercise'][$log->exerciseid]; if (!$cm->uservisible) { unset($logs[$id]); continue; } } // if we got some "live" ones then output them if ($logs) { $assesscontent = true; print_headline(get_string('exerciseassessments', 'exercise') . ':'); foreach ($logs as $log) { print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/exercise/' . str_replace('&', '&', $log->url)); } } } } return $submitcontent or $gradecontent or $assesscontent; }
function wiki_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a time, this module should find recent activity /// that has occurred in wiki activities and print it out. /// Return true if there was output, or false is there was none. global $CFG; if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'wiki\' AND ' . 'action LIKE \'edit%\' ', 'time ASC'))) { return false; } foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod = new Object(); $tempmod->course = $log->course; $tempmod->id = $log->cmid; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); /// Process log->url and rebuild it here to properly clean the pagename - MDL-15896 $extractedpage = preg_replace('/^.*&page=/', '', $log->url); $log->url = preg_replace('/page=.*$/', 'page=' . urlencode($extractedpage), $log->url); //Only if the mod is visible if ($modvisible) { $wikis[$log->info] = wiki_log_info($log); $wikis[$log->info]->pagename = $log->info; $wikis[$log->info]->time = $log->time; $wikis[$log->info]->url = str_replace('&', '&', $log->url); } } if ($wikis) { $content = true; print_headline(get_string('updatedwikipages', 'wiki') . ':', 3); foreach ($wikis as $wiki) { print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot . '/mod/wiki/' . $wiki->url); } } return true; // True if anything was printed, otherwise false }
function survey_print_recent_activity($course, $isteacher, $timestart) { global $CFG; $content = false; $surveys = NULL; if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'survey\' AND ' . 'action = \'submit\' ', 'time ASC'))) { return false; } foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod->course = $log->course; $tempmod->id = $log->info; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible) { $surveys[$log->id] = survey_log_info($log); $surveys[$log->id]->time = $log->time; $surveys[$log->id]->url = str_replace('&', '&', $log->url); } } if ($surveys) { $content = true; print_headline(get_string('newsurveyresponses', 'survey') . ':'); foreach ($surveys as $survey) { print_recent_activity_note($survey->time, $survey, $survey->name, $CFG->wwwroot . '/mod/survey/' . $survey->url); } } return $content; }
/** * Given a course and a time, this module should find recent activity * that has occurred in teamwork activities and print it out. * Return true if there was output, or false is there was none. * * @param stdClass $course * @param bool $viewfullnames * @param int $timestart * @return boolean */ function teamwork_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; $authoramefields = get_all_user_name_fields(true, 'author', null, 'author'); $reviewerfields = get_all_user_name_fields(true, 'reviewer', null, 'reviewer'); $sql = "SELECT s.id AS submissionid, s.title AS submissiontitle, s.timemodified AS submissionmodified,\n author.id AS authorid, {$authoramefields}, a.id AS assessmentid, a.timemodified AS assessmentmodified,\n reviewer.id AS reviewerid, {$reviewerfields}, cm.id AS cmid\n FROM {teamwork} w\n INNER JOIN {course_modules} cm ON cm.instance = w.id\n INNER JOIN {modules} md ON md.id = cm.module\n INNER JOIN {teamwork_submissions} s ON s.teamworkid = w.id\n INNER JOIN {user} author ON s.authorid = author.id\n LEFT JOIN {teamwork_assessments} a ON a.submissionid = s.id\n LEFT JOIN {user} reviewer ON a.reviewerid = reviewer.id\n WHERE cm.course = ?\n AND md.name = 'teamwork'\n AND s.example = 0\n AND (s.timemodified > ? OR a.timemodified > ?)\n ORDER BY s.timemodified"; $rs = $DB->get_recordset_sql($sql, array($course->id, $timestart, $timestart)); $modinfo = get_fast_modinfo($course); // reference needed because we might load the groups $submissions = array(); // recent submissions indexed by submission id $assessments = array(); // recent assessments indexed by assessment id $users = array(); foreach ($rs as $activity) { if (!array_key_exists($activity->cmid, $modinfo->cms)) { // this should not happen but just in case continue; } $cm = $modinfo->cms[$activity->cmid]; if (!$cm->uservisible) { continue; } // remember all user names we can use later if (empty($users[$activity->authorid])) { $u = new stdclass(); $users[$activity->authorid] = username_load_fields_from_object($u, $activity, 'author'); } if ($activity->reviewerid and empty($users[$activity->reviewerid])) { $u = new stdclass(); $users[$activity->reviewerid] = username_load_fields_from_object($u, $activity, 'reviewer'); } $context = context_module::instance($cm->id); $groupmode = groups_get_activity_groupmode($cm, $course); if ($activity->submissionmodified > $timestart and empty($submissions[$activity->submissionid])) { $s = new stdclass(); $s->title = $activity->submissiontitle; $s->authorid = $activity->authorid; $s->timemodified = $activity->submissionmodified; $s->cmid = $activity->cmid; if ($activity->authorid == $USER->id || has_capability('mod/teamwork:viewauthornames', $context)) { $s->authornamevisible = true; } else { $s->authornamevisible = false; } // the following do-while wrapper allows to break from deeply nested if-statements do { if ($s->authorid === $USER->id) { // own submissions always visible $submissions[$activity->submissionid] = $s; break; } if (has_capability('mod/teamwork:viewallsubmissions', $context)) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // shortcut - guest user does not belong into any group break; } // this might be slow - show only submissions by users who share group with me in this cm if (!$modinfo->get_groups($cm->groupingid)) { break; } $authorsgroups = groups_get_all_groups($course->id, $s->authorid, $cm->groupingid); if (is_array($authorsgroups)) { $authorsgroups = array_keys($authorsgroups); $intersect = array_intersect($authorsgroups, $modinfo->get_groups($cm->groupingid)); if (empty($intersect)) { break; } else { // can see all submissions and shares a group with the author $submissions[$activity->submissionid] = $s; break; } } } else { // can see all submissions from all groups $submissions[$activity->submissionid] = $s; } } } while (0); } if ($activity->assessmentmodified > $timestart and empty($assessments[$activity->assessmentid])) { $a = new stdclass(); $a->submissionid = $activity->submissionid; $a->submissiontitle = $activity->submissiontitle; $a->reviewerid = $activity->reviewerid; $a->timemodified = $activity->assessmentmodified; $a->cmid = $activity->cmid; if ($activity->reviewerid == $USER->id || has_capability('mod/teamwork:viewreviewernames', $context)) { $a->reviewernamevisible = true; } else { $a->reviewernamevisible = false; } // the following do-while wrapper allows to break from deeply nested if-statements do { if ($a->reviewerid === $USER->id) { // own assessments always visible $assessments[$activity->assessmentid] = $a; break; } if (has_capability('mod/teamwork:viewallassessments', $context)) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // shortcut - guest user does not belong into any group break; } // this might be slow - show only submissions by users who share group with me in this cm if (!$modinfo->get_groups($cm->groupingid)) { break; } $reviewersgroups = groups_get_all_groups($course->id, $a->reviewerid, $cm->groupingid); if (is_array($reviewersgroups)) { $reviewersgroups = array_keys($reviewersgroups); $intersect = array_intersect($reviewersgroups, $modinfo->get_groups($cm->groupingid)); if (empty($intersect)) { break; } else { // can see all assessments and shares a group with the reviewer $assessments[$activity->assessmentid] = $a; break; } } } else { // can see all assessments from all groups $assessments[$activity->assessmentid] = $a; } } } while (0); } } $rs->close(); $shown = false; if (!empty($submissions)) { $shown = true; echo $OUTPUT->heading(get_string('recentsubmissions', 'teamwork'), 3); foreach ($submissions as $id => $submission) { $link = new moodle_url('/mod/teamwork/submission.php', array('id' => $id, 'cmid' => $submission->cmid)); if ($submission->authornamevisible) { $author = $users[$submission->authorid]; } else { $author = null; } print_recent_activity_note($submission->timemodified, $author, $submission->title, $link->out(), false, $viewfullnames); } } if (!empty($assessments)) { $shown = true; echo $OUTPUT->heading(get_string('recentassessments', 'teamwork'), 3); core_collator::asort_objects_by_property($assessments, 'timemodified'); foreach ($assessments as $id => $assessment) { $link = new moodle_url('/mod/teamwork/assessment.php', array('asid' => $id)); if ($assessment->reviewernamevisible) { $reviewer = $users[$assessment->reviewerid]; } else { $reviewer = null; } print_recent_activity_note($assessment->timemodified, $reviewer, $assessment->submissiontitle, $link->out(), false, $viewfullnames); } } if ($shown) { return true; } return false; }
function journal_print_recent_activity($course, $isteacher, $timestart) { global $CFG; if (!empty($CFG->journal_showrecentactivity)) { // Don't even bother return false; } $content = false; $journals = NULL; if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'journal\' AND ' . '(action = \'add entry\' OR action = \'update entry\')', 'time ASC'))) { return false; } foreach ($logs as $log) { ///Get journal info. I'll need it later $j_log_info = journal_log_info($log); //Create a temp valid module structure (course,id) $tempmod->course = $log->course; $tempmod->id = $j_log_info->id; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible) { if (!isset($journals[$log->info])) { $journals[$log->info] = $j_log_info; $journals[$log->info]->time = $log->time; $journals[$log->info]->url = str_replace('&', '&', $log->url); } } } if ($journals) { $content = true; print_headline(get_string('newjournalentries', 'journal') . ':'); foreach ($journals as $journal) { print_recent_activity_note($journal->time, $journal, $journal->name, $CFG->wwwroot . '/mod/journal/' . $journal->url); } } return $content; }
function glossary_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a time, this module should find recent activity /// that has occurred in glossary activities and print it out. /// Return true if there was output, or false is there was none. global $CFG; if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'glossary\' AND ' . '(action = \'add entry\' OR ' . ' action = \'approve entry\')', 'time ASC'))) { return false; } $entries = array(); foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod = new object(); $tempmod->course = $log->course; $entry = get_record('glossary_entries', 'id', $log->info); if (!$entry) { continue; } $tempmod->id = $entry->glossaryid; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible and $entry->approved) { $entries[$log->info] = glossary_log_info($log); $entries[$log->info]->time = $log->time; $entries[$log->info]->url = str_replace('&', '&', $log->url); } } $content = false; if ($entries) { $content = true; print_headline(get_string('newentries', 'glossary') . ':'); foreach ($entries as $entry) { $user = get_record('user', 'id', $entry->userid, '', '', '', '', 'firstname,lastname'); print_recent_activity_note($entry->timemodified, $user, $entry->concept, $CFG->wwwroot . '/mod/glossary/view.php?g=' . $entry->glossaryid . '&mode=entry&hook=' . $entry->id); } } return $content; }
/** * Given a course and a time, this module should find recent activity * that has occurred in workshop activities and print it out. * Return true if there was output, or false is there was none. * * @param stdClass $course * @param bool $viewfullnames * @param int $timestart * @return boolean */ function workshop_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; $sql = "SELECT s.id AS submissionid, s.title AS submissiontitle, s.timemodified AS submissionmodified, author.id AS authorid, author.lastname AS authorlastname, author.firstname AS authorfirstname, a.id AS assessmentid, a.timemodified AS assessmentmodified, reviewer.id AS reviewerid, reviewer.lastname AS reviewerlastname, reviewer.firstname AS reviewerfirstname, cm.id AS cmid FROM {workshop} w INNER JOIN {course_modules} cm ON cm.instance = w.id INNER JOIN {modules} md ON md.id = cm.module INNER JOIN {workshop_submissions} s ON s.workshopid = w.id INNER JOIN {user} author ON s.authorid = author.id LEFT JOIN {workshop_assessments} a ON a.submissionid = s.id LEFT JOIN {user} reviewer ON a.reviewerid = reviewer.id WHERE cm.course = ? AND md.name = 'workshop' AND s.example = 0 AND (s.timemodified > ? OR a.timemodified > ?)"; $rs = $DB->get_recordset_sql($sql, array($course->id, $timestart, $timestart)); $modinfo = get_fast_modinfo($course); // reference needed because we might load the groups $submissions = array(); // recent submissions indexed by submission id $assessments = array(); // recent assessments indexed by assessment id $users = array(); foreach ($rs as $activity) { if (!array_key_exists($activity->cmid, $modinfo->cms)) { // this should not happen but just in case continue; } $cm = $modinfo->cms[$activity->cmid]; if (!$cm->uservisible) { continue; } if ($viewfullnames) { // remember all user names we can use later if (empty($users[$activity->authorid])) { $u = new stdclass(); $u->lastname = $activity->authorlastname; $u->firstname = $activity->authorfirstname; $users[$activity->authorid] = $u; } if ($activity->reviewerid and empty($users[$activity->reviewerid])) { $u = new stdclass(); $u->lastname = $activity->reviewerlastname; $u->firstname = $activity->reviewerfirstname; $users[$activity->reviewerid] = $u; } } $context = get_context_instance(CONTEXT_MODULE, $cm->id); $groupmode = groups_get_activity_groupmode($cm, $course); if ($activity->submissionmodified > $timestart and empty($submissions[$activity->submissionid])) { $s = new stdclass(); $s->title = $activity->submissiontitle; $s->authorid = $activity->authorid; $s->timemodified = $activity->submissionmodified; $s->cmid = $activity->cmid; if (has_capability('mod/workshop:viewauthornames', $context)) { $s->authornamevisible = true; } else { $s->authornamevisible = false; } // the following do-while wrapper allows to break from deeply nested if-statements do { if ($s->authorid === $USER->id) { // own submissions always visible $submissions[$activity->submissionid] = $s; break; } if (has_capability('mod/workshop:viewallsubmissions', $context)) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // shortcut - guest user does not belong into any group break; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } // this might be slow - show only submissions by users who share group with me in this cm if (empty($modinfo->groups[$cm->id])) { break; } $authorsgroups = groups_get_all_groups($course->id, $s->authorid, $cm->groupingid); if (is_array($authorsgroups)) { $authorsgroups = array_keys($authorsgroups); $intersect = array_intersect($authorsgroups, $modinfo->groups[$cm->id]); if (empty($intersect)) { break; } else { // can see all submissions and shares a group with the author $submissions[$activity->submissionid] = $s; break; } } } else { // can see all submissions from all groups $submissions[$activity->submissionid] = $s; } } } while (0); } if ($activity->assessmentmodified > $timestart and empty($assessments[$activity->assessmentid])) { $a = new stdclass(); $a->submissionid = $activity->submissionid; $a->submissiontitle = $activity->submissiontitle; $a->reviewerid = $activity->reviewerid; $a->timemodified = $activity->assessmentmodified; $a->cmid = $activity->cmid; if (has_capability('mod/workshop:viewreviewernames', $context)) { $a->reviewernamevisible = true; } else { $a->reviewernamevisible = false; } // the following do-while wrapper allows to break from deeply nested if-statements do { if ($a->reviewerid === $USER->id) { // own assessments always visible $assessments[$activity->assessmentid] = $a; break; } if (has_capability('mod/workshop:viewallassessments', $context)) { if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // shortcut - guest user does not belong into any group break; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } // this might be slow - show only submissions by users who share group with me in this cm if (empty($modinfo->groups[$cm->id])) { break; } $reviewersgroups = groups_get_all_groups($course->id, $a->reviewerid, $cm->groupingid); if (is_array($reviewersgroups)) { $reviewersgroups = array_keys($reviewersgroups); $intersect = array_intersect($reviewersgroups, $modinfo->groups[$cm->id]); if (empty($intersect)) { break; } else { // can see all assessments and shares a group with the reviewer $assessments[$activity->assessmentid] = $a; break; } } } else { // can see all assessments from all groups $assessments[$activity->assessmentid] = $a; } } } while (0); } } $rs->close(); $shown = false; if (!empty($submissions)) { $shown = true; echo $OUTPUT->heading(get_string('recentsubmissions', 'workshop'), 3); foreach ($submissions as $id => $submission) { $link = new moodle_url('/mod/workshop/submission.php', array('id'=>$id, 'cmid'=>$submission->cmid)); if ($viewfullnames and $submission->authornamevisible) { $author = $users[$submission->authorid]; } else { $author = null; } print_recent_activity_note($submission->timemodified, $author, $submission->title, $link->out(), false, $viewfullnames); } } if (!empty($assessments)) { $shown = true; echo $OUTPUT->heading(get_string('recentassessments', 'workshop'), 3); foreach ($assessments as $id => $assessment) { $link = new moodle_url('/mod/workshop/assessment.php', array('asid' => $id)); if ($viewfullnames and $assessment->reviewernamevisible) { $reviewer = $users[$assessment->reviewerid]; } else { $reviewer = null; } print_recent_activity_note($assessment->timemodified, $reviewer, $assessment->submissiontitle, $link->out(), false, $viewfullnames); } } if ($shown) { return true; } return false; }
function journal_print_recent_activity($course, $isteacher, $timestart) { global $CFG, $DB, $OUTPUT; if (!get_config('journal', 'showrecentactivity')) { return false; } $content = false; $journals = NULL; // log table should not be used here $select = "time > ? AND\n course = ? AND\n module = 'journal' AND\n (action = 'add entry' OR action = 'update entry')"; if (!($logs = $DB->get_records_select('log', $select, array($timestart, $course->id), 'time ASC'))) { return false; } $modinfo =& get_fast_modinfo($course); foreach ($logs as $log) { ///Get journal info. I'll need it later $j_log_info = journal_log_info($log); $cm = $modinfo->instances['journal'][$j_log_info->id]; if (!$cm->uservisible) { continue; } if (!isset($journals[$log->info])) { $journals[$log->info] = $j_log_info; $journals[$log->info]->time = $log->time; $journals[$log->info]->url = str_replace('&', '&', $log->url); } } if ($journals) { $content = true; echo $OUTPUT->heading(get_string('newjournalentries', 'journal') . ':', 3); foreach ($journals as $journal) { print_recent_activity_note($journal->time, $journal, $journal->name, $CFG->wwwroot . '/mod/journal/' . $journal->url); } } return $content; }
/** * Given a course and a time, this module should find recent activity * that has occurred in wiki activities and print it out. * Return true if there was output, or false is there was none. * * @global $CFG * @global $DB * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return boolean **/ function wiki_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $DB, $OUTPUT; $sql = "SELECT p.*, w.id as wikiid, sw.groupid\n FROM {wiki_pages} p\n JOIN {wiki_subwikis} sw ON sw.id = p.subwikiid\n JOIN {wiki} w ON w.id = sw.wikiid\n WHERE p.timemodified > ? AND w.course = ?\n ORDER BY p.timemodified ASC"; if (!($pages = $DB->get_records_sql($sql, array($timestart, $course->id)))) { return false; } $modinfo = get_fast_modinfo($course); $wikis = array(); $modinfo = get_fast_modinfo($course); foreach ($pages as $page) { if (!isset($modinfo->instances['wiki'][$page->wikiid])) { // not visible continue; } $cm = $modinfo->instances['wiki'][$page->wikiid]; if (!$cm->uservisible) { continue; } $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('mod/wiki:viewpage', $context)) { continue; } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode) { if ($groupmode == SEPARATEGROUPS and !has_capability('mod/wiki:managewiki', $context)) { // separate mode if (isguestuser()) { // shortcut continue; } if (is_null($modinfo->groups)) { $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo } if (!in_array($page->groupid, $modinfo->groups[0])) { continue; } } } $wikis[] = $page; } unset($pages); if (!$wikis) { return false; } echo $OUTPUT->heading(get_string("updatedwikipages", 'wiki') . ':', 3); foreach ($wikis as $wiki) { $cm = $modinfo->instances['wiki'][$wiki->wikiid]; $link = $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $wiki->id; print_recent_activity_note($wiki->timemodified, $wiki, $cm->name, $link, false, $viewfullnames); } return true; // True if anything was printed, otherwise false }
function journal_print_recent_activity($course, $isteacher, $timestart) { global $CFG; if (!empty($CFG->journal_showrecentactivity)) { // Don't even bother return false; } $content = false; $journals = NULL; // log table should not be used here if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'journal\' AND ' . '(action = \'add entry\' OR action = \'update entry\')', 'time ASC'))) { return false; } foreach ($logs as $log) { ///Get journal info. I'll need it later $j_log_info = journal_log_info($log); $cm = $modinfo->instances['journal'][$j_log_info->id]; if (!$cm->uservisible) { continue; } if (!isset($journals[$log->info])) { $journals[$log->info] = $j_log_info; $journals[$log->info]->time = $log->time; $journals[$log->info]->url = str_replace('&', '&', $log->url); } } if ($journals) { $content = true; print_headline(get_string('newjournalentries', 'journal') . ':'); foreach ($journals as $journal) { print_recent_activity_note($journal->time, $journal, $journal->name, $CFG->wwwroot . '/mod/journal/' . $journal->url); } } return $content; }
/** * Print recent activity from all assignments in a given course * * This is used by the recent activity block */ function assignment_print_recent_activity($course, $isteacher, $timestart) { global $CFG; $content = false; $assignments = array(); if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'assignment\' AND ' . 'action = \'upload\' ', 'time ASC'))) { return false; } foreach ($logs as $log) { //Create a temp valid module structure (course,id) $tempmod = new object(); $tempmod->course = $log->course; $tempmod->id = $log->info; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module, $tempmod); //Only if the mod is visible if ($modvisible) { if ($info = assignment_log_info($log)) { $assignments[$log->info] = $info; $assignments[$log->info]->time = $log->time; $assignments[$log->info]->url = str_replace('&', '&', $log->url); } } } if (!empty($assignments)) { print_headline(get_string('newsubmissions', 'assignment') . ':'); foreach ($assignments as $assignment) { print_recent_activity_note($assignment->time, $assignment, $assignment->name, $CFG->wwwroot . '/mod/assignment/' . $assignment->url); } $content = true; } return $content; }
function wiki_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a time, this module should find recent activity /// that has occurred in wiki activities and print it out. /// Return true if there was output, or false is there was none. global $CFG; $sql = "SELECT l.*, cm.instance FROM {$CFG->prefix}log l \n INNER JOIN {$CFG->prefix}course_modules cm ON l.cmid = cm.id \n WHERE l.time > '{$timestart}' AND l.course = {$course->id} \n AND l.module = 'wiki' AND action LIKE 'edit%'\n ORDER BY l.time ASC"; if (!($logs = get_records_sql($sql))) { return false; } $modinfo = get_fast_modinfo($course); $wikis = array(); foreach ($logs as $log) { $cm = $modinfo->instances['wiki'][$log->instance]; if (!$cm->uservisible) { continue; } /// Process log->url and rebuild it here to properly clean the pagename - MDL-15896 $extractedpage = preg_replace('/^.*&page=/', '', $log->url); $log->url = preg_replace('/page=.*$/', 'page=' . urlencode($extractedpage), $log->url); $wikis[$log->info] = wiki_log_info($log); $wikis[$log->info]->pagename = $log->info; $wikis[$log->info]->time = $log->time; $wikis[$log->info]->url = str_replace('&', '&', $log->url); } if (!$wikis) { return false; } print_headline(get_string('updatedwikipages', 'wiki') . ':', 3); foreach ($wikis as $wiki) { print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot . '/mod/wiki/' . $wiki->url); } return false; }
function survey_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG; $modinfo = get_fast_modinfo($course); $ids = array(); foreach ($modinfo->cms as $cm) { if ($cm->modname != 'survey') { continue; } if (!$cm->uservisible) { continue; } $ids[$cm->instance] = $cm->instance; } if (!$ids) { return false; } $slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right? if (!($rs = get_recordset_sql("SELECT sa.userid, sa.survey, MAX(sa.time) AS time,\n u.firstname, u.lastname, u.email, u.picture\n FROM {$CFG->prefix}survey_answers sa\n JOIN {$CFG->prefix}user u ON u.id = sa.userid\n WHERE sa.survey IN ({$slist}) AND sa.time > {$timestart}\n GROUP BY sa.userid, sa.survey, u.firstname, u.lastname, u.email, u.picture\n ORDER BY time ASC"))) { return false; } $surveys = array(); while ($survey = rs_fetch_next_record($rs)) { $cm = $modinfo->instances['survey'][$survey->survey]; $survey->name = $cm->name; $survey->cmid = $cm->id; $surveys[] = $survey; } rs_close($rs); if (!$surveys) { return false; } print_headline(get_string('newsurveyresponses', 'survey') . ':'); foreach ($surveys as $survey) { $url = $CFG->wwwroot . '/mod/survey/view.php?id=' . $survey->cmid; print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames); } return true; }
/** * Print recent activity from all assignments in a given course * * This is used by the recent activity block * @param mixed $course the course to print activity for * @param bool $viewfullnames boolean to determine whether to show full names or not * @param int $timestart the time the rendering started * @return bool true if activity was printed, false otherwise. */ function assign_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; // Do not use log table if possible, it may be huge. $dbparams = array($timestart, $course->id, 'assign'); $namefields = user_picture::fields('u', null, 'userid'); if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, $namefields FROM {assign_submission} asb JOIN {assign} a ON a.id = asb.assignment JOIN {course_modules} cm ON cm.instance = a.id JOIN {modules} md ON md.id = cm.module JOIN {user} u ON u.id = asb.userid WHERE asb.timemodified > ? AND a.course = ? AND md.name = ? ORDER BY asb.timemodified ASC", $dbparams)) { return false; } $modinfo = get_fast_modinfo($course); $show = array(); $grader = array(); $showrecentsubmissions = get_config('assign', 'showrecentsubmissions'); foreach ($submissions as $submission) { if (!array_key_exists($submission->cmid, $modinfo->get_cms())) { continue; } $cm = $modinfo->get_cm($submission->cmid); if (!$cm->uservisible) { continue; } if ($submission->userid == $USER->id) { $show[] = $submission; continue; } $context = context_module::instance($submission->cmid); // The act of submitting of assignment may be considered private - // only graders will see it if specified. if (empty($showrecentsubmissions)) { if (!array_key_exists($cm->id, $grader)) { $grader[$cm->id] = has_capability('moodle/grade:viewall', $context); } if (!$grader[$cm->id]) { continue; } } $groupmode = groups_get_activity_groupmode($cm, $course); if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context)) { if (isguestuser()) { // Shortcut - guest user does not belong into any group. continue; } // This will be slow - show only users that share group with me in this cm. if (!$modinfo->get_groups($cm->groupingid)) { continue; } $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid); if (is_array($usersgroups)) { $usersgroups = array_keys($usersgroups); $intersect = array_intersect($usersgroups, $modinfo->get_groups($cm->groupingid)); if (empty($intersect)) { continue; } } } $show[] = $submission; } if (empty($show)) { return false; } echo $OUTPUT->heading(get_string('newsubmissions', 'assign').':', 3); foreach ($show as $submission) { $cm = $modinfo->get_cm($submission->cmid); $link = $CFG->wwwroot.'/mod/assign/view.php?id='.$cm->id; print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames); } return true; }
/** * Given a course and a time, this module should find recent activity * that has occurred in wiki activities and print it out. * Return true if there was output, or false is there was none. * * @global $CFG * @global $DB * @uses CONTEXT_MODULE * @uses VISIBLEGROUPS * @param object $course * @param bool $viewfullnames capability * @param int $timestart * @return boolean **/ function wiki_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $DB, $OUTPUT; $sql = "SELECT p.id, p.timemodified, p.subwikiid, sw.wikiid, w.wikimode, sw.userid, sw.groupid\n FROM {wiki_pages} p\n JOIN {wiki_subwikis} sw ON sw.id = p.subwikiid\n JOIN {wiki} w ON w.id = sw.wikiid\n WHERE p.timemodified > ? AND w.course = ?\n ORDER BY p.timemodified ASC"; if (!($pages = $DB->get_records_sql($sql, array($timestart, $course->id)))) { return false; } require_once $CFG->dirroot . "/mod/wiki/locallib.php"; $wikis = array(); $modinfo = get_fast_modinfo($course); $subwikivisible = array(); foreach ($pages as $page) { if (!isset($subwikivisible[$page->subwikiid])) { $subwiki = (object) array('id' => $page->subwikiid, 'wikiid' => $page->wikiid, 'groupid' => $page->groupid, 'userid' => $page->userid); $wiki = (object) array('id' => $page->wikiid, 'course' => $course->id, 'wikimode' => $page->wikimode); $subwikivisible[$page->subwikiid] = wiki_user_can_view($subwiki, $wiki); } if ($subwikivisible[$page->subwikiid]) { $wikis[] = $page; } } unset($subwikivisible); unset($pages); if (!$wikis) { return false; } echo $OUTPUT->heading(get_string("updatedwikipages", 'wiki') . ':', 3); foreach ($wikis as $wiki) { $cm = $modinfo->instances['wiki'][$wiki->wikiid]; $link = $CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $wiki->id; print_recent_activity_note($wiki->timemodified, $wiki, $cm->name, $link, false, $viewfullnames); } return true; // True if anything was printed, otherwise false }
function workshop_print_recent_activity($course, $isteacher, $timestart) { global $CFG; // have a look for agreed assessments for this user (agree) $agreecontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_agree_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $agreecontent = true; break; } } // if we got some "live" ones then output them if ($agreecontent) { print_headline(get_string("workshopagreedassessments", "workshop") . ":"); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { if (!workshop_is_teacher($workshop, $log->userid)) { // don't break anonymous rule $log->firstname = $course->student; $log->lastname = ''; } print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } } // have a look for new assessments for this user (assess) $assesscontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_assess_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $assesscontent = true; break; } } // if we got some "live" ones then output them if ($assesscontent) { print_headline(get_string("workshopassessments", "workshop") . ":"); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { if (!workshop_is_teacher($tempmod->id, $log->userid)) { // don't break anonymous rule $log->firstname = $course->student; $log->lastname = ''; } print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } } // have a look for new comments for this user (comment) $commentcontent = false; if (!$isteacher) { // teachers only need to see submissions if ($logs = workshop_get_comment_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $commentcontent = true; break; } } // if we got some "live" ones then output them if ($commentcontent) { print_headline(get_string("workshopcomments", "workshop") . ":"); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $log->firstname = $course->student; // Keep anonymous $log->lastname = ''; print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } } // have a look for new assessment gradings for this user (grade) $gradecontent = false; if ($logs = workshop_get_grade_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $gradecontent = true; break; } } // if we got some "live" ones then output them if ($gradecontent) { print_headline(get_string("workshopfeedback", "workshop") . ":"); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $log->firstname = $course->teacher; // Keep anonymous $log->lastname = ''; print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } // have a look for new submissions (only show to teachers) (submit) $submitcontent = false; if ($isteacher) { if ($logs = workshop_get_submit_logs($course, $timestart)) { // got some, see if any belong to a visible module foreach ($logs as $log) { // Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { $submitcontent = true; break; } } // if we got some "live" ones then output them if ($submitcontent) { print_headline(get_string("workshopsubmissions", "workshop") . ":"); foreach ($logs as $log) { //Create a temp valid module structure (only need courseid, moduleid) $tempmod->course = $course->id; $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop", $tempmod)) { print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot . '/mod/workshop/' . $log->url); } } } } } return $agreecontent or $assesscontent or $commentcontent or $gradecontent or $submitcontent; }