MDL-12945 a slightly bigger patch for performance in recent activity and various group related issues + some other fixes - see list of subtasks in tracker

This commit is contained in:
skodak
2008-01-24 20:29:31 +00:00
parent f954aeaecd
commit 94cbbdbd2e
63 changed files with 2315 additions and 1918 deletions
@@ -7,21 +7,7 @@ class block_activity_modules extends block_list {
}
function get_content() {
global $USER, $CFG;
// TODO: FIX: HACK: (any other tags I should add? :P)
// Hacker's improvised caching scheme: avoid fetching the mod
// data from db if the course format has already fetched them
if(!isset($GLOBALS['modnamesplural']) || !isset($GLOBALS['modnamesused'])) {
require_once($CFG->dirroot.'/course/lib.php');
if (!empty($this->instance)) {
get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
}
}
else {
$modnamesplural = $GLOBALS['modnamesplural'];
$modnamesused = $GLOBALS['modnamesused'];
}
global $CFG, $COURSE;
if($this->content !== NULL) {
return $this->content;
@@ -32,12 +18,30 @@ class block_activity_modules extends block_list {
$this->content->icons = array();
$this->content->footer = '';
if (isset($modnamesused) && $modnamesused) {
foreach ($modnamesused as $modname => $modfullname) {
if ($modname != 'label') {
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modnamesplural[$modname].'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" class="icon" alt="" />';
}
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
require_once($CFG->dirroot.'/course/lib.php');
$modinfo = get_fast_modinfo($course);
$modfullanmes = array();
foreach($modinfo->cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$modfullnames[$cm->modname] = $cm->modplural;
}
asort($modfullnames, SORT_LOCALE_STRING);
foreach ($modfullnames as $modname => $modfullname) {
if ($modname != 'label') {
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modfullname.'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" class="icon" alt="" />';
}
}
+21 -17
View File
@@ -49,7 +49,7 @@ class block_admin extends block_list {
/// Course editing on/off
if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
if (isediting($this->instance->pageid)) {
$this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
@@ -63,7 +63,7 @@ class block_admin extends block_list {
/// Assign roles to the course
if (has_capability('moodle/role:assign', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/role:assign', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
@@ -71,16 +71,20 @@ class block_admin extends block_list {
/// View course grades (or just your own grades, same link)
/// find all accessible reports
if ($course->id!==SITEID) {
if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
foreach ($reports as $key => $plugin) { // Remove ones we can't see
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
unset($reports[$key]);
if ($course->id !== SITEID) {
$reportavailable = false;
if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
arsort($reports); // user is last, we want to test it first
foreach ($reports as $plugin) {
if (has_capability('gradereport/'.$plugin.':view', $context)) {
//stop when fisrt visible found
$reportavailable = true;
break;
}
}
}
if (!empty($reports)) {
if ($reportavailable) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
}
@@ -88,7 +92,7 @@ class block_admin extends block_list {
/// Course outcomes (to help give it more prominence because it's important)
if (!empty($CFG->enableoutcomes)) {
if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
}
@@ -110,7 +114,7 @@ class block_admin extends block_list {
/// Manage groups in this course
if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && ($course->id!==SITEID)) {
if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
$strgroups = get_string('groups');
$this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
@@ -118,37 +122,37 @@ class block_admin extends block_list {
/// Backup this course
if (has_capability('moodle/site:backup', $context)&& ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
}
/// Restore to this course
if (has_capability('moodle/site:restore', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}
/// Import data from other courses
if (has_capability('moodle/site:import', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}
/// Reset this course
if (has_capability('moodle/course:reset', $context) && ($course->id!==SITEID)) {
if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
}
/// View course reports
if (has_capability('moodle/site:viewreports', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
}
/// Manage questions
if ($course->id!==SITEID){
if ($course->id !== SITEID){
$questionlink = '';
$questioncaps = array(
'moodle/question:add',
@@ -176,7 +180,7 @@ class block_admin extends block_list {
/// Manage files
if (has_capability('moodle/course:managefiles', $context) && ($course->id!==SITEID)) {
if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt="" />';
}
@@ -20,8 +20,8 @@ class block_calendar_month extends block_base {
if ($this->content !== NULL) {
return $this->content;
}
// Initialize the session variables
calendar_session_vars();
// Reset the session variables
calendar_session_vars($COURSE);
$this->content = new stdClass;
$this->content->text = '';
@@ -35,11 +35,12 @@ class block_calendar_month extends block_base {
if($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
// the list of courses it will be grabbing events from.
$filtercourse = NULL;
}
else {
$filtercourse = NULL;
$groupeventsfrom = NULL;
} else {
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => 1);
$filtercourse = array($courseshown => $COURSE);
$groupeventsfrom = array($courseshown => 1);
}
// We 'll need this later
@@ -53,7 +54,7 @@ class block_calendar_month extends block_base {
// Be VERY careful with the format for default courses arguments!
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse);
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
if ($courseshown == SITEID) {
// For the front page
$this->content->text .= calendar_overlib_html();
@@ -16,8 +16,8 @@ class block_calendar_upcoming extends block_base {
if ($this->content !== NULL) {
return $this->content;
}
// Initialize the session variables
calendar_session_vars();
// Reset the session variables
calendar_session_vars($COURSE);
$this->content = new stdClass;
$this->content->text = '';
@@ -42,10 +42,12 @@ class block_calendar_upcoming extends block_base {
if ($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting
// the list of courses it will be grabbing events from.
$filtercourse = NULL;
$filtercourse = NULL;
$groupeventsfrom = NULL;
} else {
// Forcibly filter events to include only those from the particular course we are in.
$filtercourse = array($courseshown => 1);
$filtercourse = array($courseshown => $COURSE);
$groupeventsfrom = array($courseshown => 1);
}
}
@@ -55,7 +57,7 @@ class block_calendar_upcoming extends block_base {
// Be VERY careful with the format for default courses arguments!
// Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions.
calendar_set_filters($courses, $group, $user, $filtercourse, $filtercourse, false);
calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false);
$events = calendar_get_upcoming($courses, $group, $user,
get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS),
get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS));
+6
View File
@@ -110,6 +110,12 @@ class block_course_list extends block_list {
function get_remote_courses() {
global $THEME, $CFG, $USER;
if (!is_enabled_auth('mnet')) {
// no need to query anything remote related
return;
}
$icon = '<img src="'.$CFG->pixpath.'/i/mnethost.gif" class="icon" alt="'.get_string('course').'" />';
// only for logged in users!
@@ -24,10 +24,11 @@ class block_course_summary extends block_base {
return '';
}
$this->content = New stdClass;
$this->content = new object();
$options = new object();
$options->noclean = true; // Don't clean Javascripts etc
$this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
if(isediting($COURSE->id)) {
if (isediting($COURSE->id)) { // ?? courseid param not there??
if($COURSE->id == SITEID) {
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
} else {
@@ -189,13 +189,10 @@ class block_glossary_random extends block_base {
// place link to glossary in the footer if the glossary is visible
//Create a temp valid module structure (course,id)
$tempmod->course = $this->course->id;
$tempmod->id = $glossaryid;
$cm = get_coursemodule_from_instance('glossary',$glossaryid, $this->course->id) ;
//Obtain the visible property from the instance
if (instance_is_visible('glossary', $tempmod)) {
$cm = get_coursemodule_from_instance('glossary',$glossaryid, $this->course->id) ;
if (coursemodule_visible_for_user($cm)) {
if (has_capability('mod/glossary:write', get_context_instance(CONTEXT_MODULE, $cm->id))) {
$this->content->footer = '<a href="'.$CFG->wwwroot.'/mod/glossary/edit.php?id='.$cm->id
.'" title="'.$this->config->addentry.'">'.$this->config->addentry.'</a><br />';
+5
View File
@@ -26,6 +26,11 @@ class block_mnet_hosts extends block_list {
return false;
}
if (!is_enabled_auth('mnet')) {
// no need to query anything remote related
return '';
}
// check for outgoing roaming permission first
if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
return '';
+3 -1
View File
@@ -32,9 +32,11 @@ class block_news_items extends block_base {
return '';
}
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $COURSE->id)) {
$modinfo = get_fast_modinfo($COURSE);
if (empty($modinfo->instances['forum'][$forum->id])) {
return '';
}
$cm = $modinfo->instances['forum'][$forum->id];
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+16 -13
View File
@@ -83,23 +83,26 @@ class block_online_users extends block_base {
$pcontext = get_related_contexts_string($context);
if ($pusers = get_records_sql($SQL, 0, 50)) { // We'll just take the most recent 50 maximum
foreach ($pusers as $puser) {
$hidden = false;
if (!has_capability('moodle/role:viewhiddenassigns', $context)) {
// if current user can't view hidden role assignment in this context and
// user has a hidden role assigned at this context or any parent contexts,
// ignore this user
$SQL = "SELECT id FROM {$CFG->prefix}role_assignments
WHERE userid = $puser->id
AND contextid $pcontext
AND hidden = 1";
if (!has_capability('moodle/role:viewhiddenassigns', $context) && record_exists_sql($SQL)) {
// can't see this user as the current user has no capability
// and this user has a hidden assignment at this context or higher
continue;
$userids = array_keys($pusers);
$userids = implode(',', $userids);
$sql = "SELECT userid
FROM {$CFG->prefix}role_assignments
WHERE userid IN ($userids) AND contextid $pcontext AND hidden = 1
GROUP BY userid";
$hidden = get_records_sql($sql);
}
foreach ($pusers as $puser) {
if ($hidden and isset($hidden[$puser->id])) {
continue;
}
$puser->fullname = fullname($puser);
$users[$puser->id] = $puser;
}
+30 -18
View File
@@ -75,25 +75,37 @@ class block_section_links extends block_base {
} else {
$link = '#section-';
}
$text = '<ol class="inline-list">';
for ($i = $inc; $i <= $course->numsections; $i += $inc) {
$isvisible = get_field('course_sections', 'visible', 'course', $this->instance->pageid, 'section', $i);
if (!$isvisible and !has_capability('moodle/course:update', $context)) {
continue;
}
$style = ($isvisible) ? '' : ' class="dimmed"';
if ($i == $highlight) {
$text .= "<li><a href=\"$link$i\"$style><strong>$i</strong></a></li>\n";
} else {
$text .= "<li><a href=\"$link$i\"$style>$i</a></li>\n";
}
}
$text .= '</ol>';
if ($highlight) {
$isvisible = get_field('course_sections', 'visible', 'course', $this->instance->pageid, 'section', $highlight);
if ($isvisible or has_capability('moodle/course:update', $context)) {
$sql = "SELECT section, visible
FROM {$CFG->prefix}course_sections
WHERE course = $course->id AND
section < ".($course->numsections+1)."
ORDER BY section";
if ($sections = get_records_sql($sql)) {
$text = '<ol class="inline-list">';
for ($i = $inc; $i <= $course->numsections; $i += $inc) {
if (!isset($sections[$i])) {
continue;
}
$isvisible = $sections[$i]->visible;
if (!$isvisible and !has_capability('moodle/course:update', $context)) {
continue;
}
$style = ($isvisible) ? '' : ' class="dimmed"';
$text .= "\n<a href=\"$link$highlight\"$style>$linktext</a>";
if ($i == $highlight) {
$text .= "<li><a href=\"$link$i\"$style><strong>$i</strong></a></li>\n";
} else {
$text .= "<li><a href=\"$link$i\"$style>$i</a></li>\n";
}
}
$text .= '</ol>';
if ($highlight and isset($sections[$highlight])) {
$isvisible = $sections[$highlight]->visible;
if ($isvisible or has_capability('moodle/course:update', $context)) {
$style = ($isvisible) ? '' : ' class="dimmed"';
$text .= "\n<a href=\"$link$highlight\"$style>$linktext</a>";
}
}
}
+53 -17
View File
@@ -11,13 +11,13 @@ class block_site_main_menu extends block_list {
}
function get_content() {
global $USER, $CFG;
global $USER, $CFG, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content = new object();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
@@ -26,19 +26,57 @@ class block_site_main_menu extends block_list {
return $this->content;
}
$course = get_record('course', 'id', $this->instance->pageid);
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
require_once($CFG->dirroot.'/course/lib.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
$ismoving = ismoving($this->instance->pageid);
$modinfo =& get_fast_modinfo($course);
/// extra fast view mode
if (!$isediting) {
if (!empty($modinfo->sections[0])) {
foreach($modinfo->sections[0] as $cmid) {
$cm = $modinfo->cms[$cmid];
if (!$cm->uservisible) {
continue;
}
if ($cm->modname == 'label') {
$this->content->items[] = format_text($cm->extra, FORMAT_HTML);
$this->content->icons[] = '';
} else {
$linkcss = $cm->visible ? '' : ' class="dimmed" ';
$instancename = format_string($cm->name, true, $course->id);
$this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$instancename.'</a>';
//Accessibility: incidental image - should be empty Alt text
if (!empty($cm->icon)) {
$icon = $CFG->pixpath.'/'.$cm->icon;
} else {
$icon = $CFG->modpixpath.'/'.$cm->modname.'/icon.gif';
}
$this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
}
}
}
return $this->content;
}
/// slow & hacky editing mode
$ismoving = ismoving($this->instance->pageid);
$sections = get_all_sections($this->instance->pageid);
if(!empty($sections) && isset($sections[0])) {
$section = $sections[0];
}
if (!empty($section) || $isediting) {
if (!empty($section)) {
get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
}
@@ -52,8 +90,6 @@ class block_site_main_menu extends block_list {
$stractivityclipboard = $USER->activitycopyname;
}
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = unserialize((string)$course->modinfo);
$editbuttons = '';
if ($ismoving) {
@@ -68,7 +104,7 @@ class block_site_main_menu extends block_list {
continue;
}
$mod = $mods[$modnumber];
if ($isediting && !$ismoving) {
if (!$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $course->groupmode;
@@ -89,17 +125,17 @@ class block_site_main_menu extends block_list {
$this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
'<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
$instancename = urldecode($modinfo[$modnumber]->name);
}
$instancename = $modinfo->cms[$modnumber]->name;
$instancename = format_string($instancename, true, $this->instance->pageid);
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
} else {
$extra = '';
}
if (!empty($modinfo[$modnumber]->icon)) {
$icon = $CFG->pixpath.'/'.urldecode($modinfo[$modnumber]->icon);
if (!empty($modinfo->cms[$modnumber]->icon)) {
$icon = $CFG->pixpath.'/'.$modinfo->cms[$modnumber]->icon;
} else {
$icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
}
@@ -110,7 +146,7 @@ class block_site_main_menu extends block_list {
} else {
$this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
//Accessibility: incidental image - should be empty Alt text
//Accessibility: incidental image - should be empty Alt text
$this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
}
}
@@ -123,7 +159,7 @@ class block_site_main_menu extends block_list {
$this->content->icons[] = '';
}
if ($isediting && $modnames) {
if ($modnames) {
$this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
} else {
$this->content->footer = '';
@@ -2,7 +2,7 @@
class block_social_activities extends block_list {
function init(){
$this->title = get_string('blockname','block_social_activities');
$this->title = get_string('blockname', 'block_social_activities');
$this->version = 2004041800;
}
@@ -11,13 +11,13 @@ class block_social_activities extends block_list {
}
function get_content() {
global $USER, $CFG;
global $USER, $CFG, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content = new object();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
@@ -26,20 +26,63 @@ class block_social_activities extends block_list {
return $this->content;
}
$course = get_record('course', 'id', $this->instance->pageid);
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
require_once($CFG->dirroot.'/course/lib.php');
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
$modinfo = get_fast_modinfo($course);
// To make our day, we start with an ugly hack
global $sections, $mods, $modnames;
/// extra fast view mode
if (!$isediting) {
if (!empty($modinfo->sections[0])) {
foreach($modinfo->sections[0] as $cmid) {
$cm = $modinfo->cms[$cmid];
if (!$cm->uservisible) {
continue;
}
if ($cm->modname == 'label') {
$this->content->items[] = format_text($cm->extra, FORMAT_HTML);
$this->content->icons[] = '';
} else {
$linkcss = $cm->visible ? '' : ' class="dimmed" ';
$instancename = format_string($cm->name, true, $course->id);
$this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$instancename.'</a>';
//Accessibility: incidental image - should be empty Alt text
if (!empty($cm->icon)) {
$icon = $CFG->pixpath.'/'.$cm->icon;
} else {
$icon = $CFG->modpixpath.'/'.$cm->modname.'/icon.gif';
}
$this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
}
}
}
return $this->content;
}
$section = $sections[0];
// That wasn't so bad, was it?
/// slow & hacky editing mode
$ismoving = ismoving($this->instance->pageid);
$sections = get_all_sections($this->instance->pageid);
if(!empty($sections) && isset($sections[0])) {
$section = $sections[0];
}
if (!empty($section)) {
get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
}
$groupbuttons = $course->groupmode;
$groupbuttonslink = (!$course->groupmodeforce);
$viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
$isediting = isediting($this->instance->pageid);
$ismoving = ismoving($this->instance->pageid);
if ($ismoving) {
$strmovehere = get_string('movehere');
$strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
@@ -47,7 +90,6 @@ class block_social_activities extends block_list {
$stractivityclipboard = $USER->activitycopyname;
}
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = unserialize((string)$course->modinfo);
$editbuttons = '';
if ($ismoving) {
@@ -55,14 +97,14 @@ class block_social_activities extends block_list {
$this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
}
if (!empty($section->sequence)) {
if (!empty($section) && !empty($section->sequence)) {
$sectionmods = explode(',', $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($isediting && !$ismoving) {
if (!$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $course->groupmode;
@@ -75,25 +117,25 @@ class block_social_activities extends block_list {
} else {
$editbuttons = '';
}
if ($mod->visible || $viewhiddenactivities) {
if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
continue;
}
$this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
'<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
'<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
$instancename = urldecode($modinfo[$modnumber]->name);
$instancename = $modinfo->cms[$modnumber]->name;
$instancename = format_string($instancename, true, $this->instance->pageid);
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
} else {
$extra = '';
}
if (!empty($modinfo[$modnumber]->icon)) {
$icon = $CFG->pixpath.'/'.urldecode($modinfo[$modnumber]->icon);
if (!empty($modinfo->cms[$modnumber]->icon)) {
$icon = $CFG->pixpath.'/'.$modinfo->cms[$modnumber]->icon;
} else {
$icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
}
@@ -104,7 +146,8 @@ class block_social_activities extends block_list {
} else {
$this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
$this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="'.$mod->modfullname.'" />';
//Accessibility: incidental image - should be empty Alt text
$this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
}
}
}
@@ -112,11 +155,11 @@ class block_social_activities extends block_list {
if ($ismoving) {
$this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
'<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
'<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
if ($isediting && $modnames) {
if ($modnames) {
$this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
} else {
$this->content->footer = '';
+51 -35
View File
@@ -69,7 +69,7 @@ $CALENDARDAYS = array('sunday','monday','tuesday','wednesday','thursday','friday
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) {
global $CFG, $USER;
$display = &New stdClass;
$display = new stdClass;
$display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
$display->maxwday = $display->minwday + 6;
@@ -363,9 +363,9 @@ function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
}
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
global $CFG;
global $CFG, $COURSE;
$display = &new stdClass;
$display = new stdClass;
$display->range = $daysinfuture; // How many days in the future we 'll look
$display->maxevents = $maxevents;
@@ -404,42 +404,55 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
}
}
if($events !== false) {
if ($events !== false) {
$modinfo =& get_fast_modinfo($COURSE);
foreach($events as $event) {
if(!empty($event->modulename)) {
$mod = get_coursemodule_from_instance($event->modulename, $event->instance);
if (!groups_course_module_visible($mod)) {
continue;
if (!empty($event->modulename)) {
if ($event->courseid == $COURSE->id) {
if (isset($modinfo->instances[$event->modulename][$event->instance])) {
$cm = $modinfo->instances[$event->modulename][$event->instance];
if (!$cm->uservisible) {
continue;
}
}
} else {
if (!$cm = get_coursemodule_from_instance($event->modulename, $event->instance)) {
continue;
}
if (!coursemodule_visible_for_user($cm)) {
continue;
}
}
}
if ($event->modulename == 'assignment'){
if(!calendar_edit_event_allowed($event)){ // cannot manage entries, eg. student
if(!$assignment = get_record('assignment','id',$event->instance)){
// error("assignment ID was incorrect");
continue;
}
// assign assignment to assignment object to use hidden_is_hidden method
require_once($CFG->dirroot.'/mod/assignment/lib.php');
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php')) {
continue;
}
require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($mod->id,$assignment);
if ($assignmentinstance->description_is_hidden()){//force not to show description before availability
$event->description = get_string('notavailableyet', 'assignment');
if ($event->modulename == 'assignment'){
// TODO: rewrite this hack somehow
if (!calendar_edit_event_allowed($event)){ // cannot manage entries, eg. student
if(!$assignment = get_record('assignment','id',$event->instance)){
// error("assignment ID was incorrect");
continue;
}
// assign assignment to assignment object to use hidden_is_hidden method
require_once($CFG->dirroot.'/mod/assignment/lib.php');
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php')) {
continue;
}
require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm);
if ($assignmentinstance->description_is_hidden()){//force not to show description before availability
$event->description = get_string('notavailableyet', 'assignment');
}
}
}
}
if($processed >= $display->maxevents) {
if ($processed >= $display->maxevents) {
break;
}
@@ -1121,7 +1134,7 @@ function calendar_get_course_cached(&$coursecache, $courseid) {
return $coursecache[$courseid];
}
function calendar_session_vars() {
function calendar_session_vars($course=null) {
global $SESSION, $USER;
if(!empty($USER->id) && isset($USER->realuser) && !isset($SESSION->cal_loggedinas)) {
@@ -1158,9 +1171,12 @@ function calendar_session_vars() {
if(!isset($SESSION->cal_show_user)) {
$SESSION->cal_show_user = true;
}
// if(empty($SESSION->cal_courses_shown)) {
if (isset($course)) {
// speedup hack for calendar related blocks
$SESSION->cal_courses_shown = array($course->id => $course);
} else {
$SESSION->cal_courses_shown = calendar_get_default_courses(true);
//}
}
if(empty($SESSION->cal_users_shown)) {
// The empty() instead of !isset() here makes a whole world of difference,
// as it will automatically change to the user's id when the user first logs
@@ -1204,7 +1220,7 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
$c[$courseeventsfrom] = get_record('course', 'id', $courseeventsfrom);
$courseeventsfrom = $c;
} else if (is_array($courseeventsfrom)) { // case of an array of ints, e.g. course home page
foreach ($courseeventsfrom as $i=>$courseid) {
foreach ($courseeventsfrom as $i=>$courseid) { // TODO: this seems wrong, the array is often constructed as [courseid] => 1 ???
if (is_int($courseid)) {
$courseeventsfrom[$i] = get_record('course', 'id', $courseid);
}
+351 -423
View File
@@ -2,10 +2,6 @@
// Library of useful functions
if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!!
return;
}
define('COURSE_MAX_LOG_DISPLAY', 150); // days
define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
define('COURSE_LIVELOG_REFRESH', 60); // Seconds
@@ -26,221 +22,6 @@ define('MOD_CLASS_ACTIVITY', 0);
define('MOD_CLASS_RESOURCE', 1);
function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin",
$mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") {
global $USER, $CFG;
if ($advancedfilter) {
// Get all the possible users
$users = array();
if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) {
foreach ($courseusers as $courseuser) {
$users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
}
}
if ($guest = get_guest()) {
$users[$guest->id] = fullname($guest);
}
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
if ($ccc = get_records("course", "", "", "fullname")) {
foreach ($ccc as $cc) {
if ($cc->category) {
$courses["$cc->id"] = "$cc->fullname";
} else {
$courses["$cc->id"] = " $cc->fullname (Site)";
}
}
}
asort($courses);
}
$activities = array();
$selectedactivity = $modid;
/// Casting $course->modinfo to string prevents one notice when the field is null
if ($modinfo = unserialize((string)$course->modinfo)) {
$section = 0;
if ($course->format == 'weeks') { // Body
$strsection = get_string("week");
} else {
$strsection = get_string("topic");
}
$activities["activity/All"] = "All activities";
$activities["activity/Assignments"] = "All assignments";
$activities["activity/Chats"] = "All chats";
$activities["activity/Forums"] = "All forums";
$activities["activity/Quizzes"] = "All quizzes";
$activities["activity/Workshops"] = "All workshops";
$activities["section/individual"] = "------------- Individual Activities --------------";
foreach ($modinfo as $mod) {
if ($mod->mod == "label") {
continue;
}
if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $mod->cm))) {
continue;
}
$mod->id = $mod->cm;
if (!groups_course_module_visible($mod)) {
continue;
}
if ($mod->section > 0 and $section <> $mod->section) {
$activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
}
$section = $mod->section;
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
if (strlen($mod->name) > 55) {
$mod->name = substr($mod->name, 0, 50)."...";
}
if (!$mod->visible) {
$mod->name = "(".$mod->name.")";
}
$activities["$mod->cm"] = $mod->name;
if ($mod->cm == $modid) {
$selectedactivity = "$mod->cm";
}
}
}
$strftimedate = get_string("strftimedate");
$strftimedaydate = get_string("strftimedaydate");
asort($users);
// Get all the possible dates
// Note that we are keeping track of real (GMT) time and user time
// User time is only used in displays - all calcs and passing is GMT
$timenow = time(); // GMT
// What day is it now for the user, and when is midnight that day (in GMT).
$timemidnight = $today = usergetmidnight($timenow);
$dates = array();
$dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate);
$dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate);
if (!$course->startdate or ($course->startdate > $timenow)) {
$course->startdate = $course->timecreated;
}
$numdates = 1;
while ($timemidnight > $course->startdate and $numdates < 365) {
$timemidnight = $timemidnight - 86400;
$timenow = $timenow - 86400;
$dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
$numdates++;
}
if ($selecteddate === "lastlogin") {
$selecteddate = $USER->lastlogin;
}
echo '<form action="recent.php" method="get">';
echo '<input type="hidden" name="chooserecent" value="1" />';
echo "<center>";
echo "<table>";
if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
choose_from_menu ($courses, "id", $course->id, "");
echo "</td></tr>";
} else {
echo '<input type="hidden" name="id" value="'.$course->id.'" />';
}
$sortfields = array("default" => get_string("bycourseorder"),"dateasc" => get_string("datemostrecentlast"), "datedesc" => get_string("datemostrecentfirst"));
echo "<tr><td><b>" . get_string("participants") . "</b></td><td>";
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
echo "</td>";
echo '<td align="right"><b>' . get_string("since") . '</b></td><td>';
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
echo "</td></tr>";
echo "<tr><td><b>" . get_string("activities") . "</b></td><td>";
choose_from_menu ($activities, "modid", $selectedactivity, "");
echo "</td>";
echo '<td align="right"><b>' . get_string("sortby") . "</b></td><td>";
choose_from_menu ($sortfields, "sortby", $selectedsort, "");
echo "</td></tr>";
echo '<tr>';
$groupmode = groups_get_course_groupmode($course);
if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
if ($groups = groups_get_all_groups($course->id)) {
$group_names = array();
foreach($groups as $group) {
$group_names[$group->id] = format_string($group->name);
}
echo '<td><b>';
if ($groupmode == VISIBLEGROUPS) {
print_string('groupsvisible');
} else {
print_string('groupsseparate');
}
echo ':</b></td><td>';
choose_from_menu($group_names, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
echo '</td>';
}
}
echo '<td colspan="2" align="right">';
echo '<input type="submit" value="'.get_string('showrecent').'" />';
echo "</td></tr>";
echo "</table>";
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;advancedfilter=0\">" . get_string("normalfilter") . "</a>";
print_heading($advancedlink);
echo "</center>";
echo "</form>";
} else {
$day_list = array("1","7","14","21","30");
$strsince = get_string("since");
$strlastlogin = get_string("lastlogin");
$strday = get_string("day");
$strdays = get_string("days");
$heading = "";
foreach ($day_list as $count) {
if ($count == "1") {
$day = $strday;
} else {
$day = $strdays;
}
$tmpdate = time() - ($count * 3600 * 24);
$heading = $heading .
"<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;date=$tmpdate\"> $count $day</a> | ";
}
$heading = $strsince . ": <a href=\"$CFG->wwwroot/course/recent.php?id=$course->id\">$strlastlogin</a>" . " | " . $heading;
print_heading($heading);
$advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
print_heading($advancedlink);
}
}
function make_log_url($module, $url) {
switch ($module) {
case 'user':
@@ -1018,7 +799,9 @@ function print_recent_activity($course) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$timestart = time() - COURSE_MAX_RECENT_PERIOD;
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
$timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
if (!has_capability('moodle/legacy:guest', $context, NULL, false)) {
if (!empty($USER->lastcourseaccess[$course->id])) {
@@ -1037,123 +820,119 @@ function print_recent_activity($course) {
echo "</div>\n";
// Firstly, have there been any new enrolments?
$heading = false;
$content = false;
/// Firstly, have there been any new enrolments?
$users = get_recent_enrolments($course->id, $timestart);
//Accessibility: new users now appear in an <OL> list.
if ($users) {
echo '<div class="newusers">';
if (! $heading) {
print_headline(get_string("newusers").':', 3);
$heading = true;
$content = true;
}
print_headline(get_string("newusers").':', 3);
$content = true;
echo "<ol class=\"list\">\n";
foreach ($users as $user) {
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
echo '<li class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
$fullname = fullname($user, $viewfullnames);
echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
}
echo "</ol>\n</div>\n";
}
// Next, have there been any modifications to the course structure?
/// Next, have there been any modifications to the course structure?
$logs = get_records_select('log', "time > '$timestart' AND course = '$course->id' AND
module = 'course' AND action LIKE '% mod'", "time ASC");
$modinfo =& get_fast_modinfo($course);
$changelist = array();
$logs = get_records_select('log', "time > $timestart AND course = $course->id AND
module = 'course' AND
(action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
"id ASC");
if ($logs) {
$actions = array('add mod', 'update mod', 'delete mod');
$newgones = array(); // added and later deleted items
foreach ($logs as $key => $log) {
if (!in_array($log->action, $actions)) {
continue;
}
$info = split(' ', $log->info);
if ($info[0] == 'label') { // Labels are special activities
if ($info[0] == 'label') { // Labels are ignored in recent activity
continue;
}
$modname = get_field($info[0], 'name', 'id', $info[1]);
//Create a temp valid module structure (course,id)
$tempmod->course = $log->course;
$tempmod->id = $info[1];
//Obtain the visible property from the instance
$modvisible = instance_is_visible($info[0],$tempmod);
if (count($info) != 2) {
debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
continue;
}
//Only if the mod is visible
if ($modvisible) {
switch ($log->action) {
case 'add mod':
$stradded = get_string('added', 'moodle', get_string('modulename', $info[0]));
$changelist[$log->info] = array ('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
break;
case 'update mod':
$strupdated = get_string('updated', 'moodle', get_string('modulename', $info[0]));
if (empty($changelist[$log->info])) {
$changelist[$log->info] = array ('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
}
break;
case 'delete mod':
if (!empty($changelist[$log->info]['operation']) and
$changelist[$log->info]['operation'] == 'add') {
$changelist[$log->info] = NULL;
} else {
$strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $info[0]));
$changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
}
break;
$modname = $info[0];
$instanceid = $info[1];
if ($log->action == 'delete mod') {
// unfortunately we do not know if the mod was visible
if (!array_key_exists($log->info, $newgones)) {
$strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
$changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
}
} else {
if (!isset($modinfo->instances[$modname][$instanceid])) {
if ($log->action == 'add mod') {
// do not display added and later deleted activities
$newgones[$log->info] = true;
}
continue;
}
$cm = $modinfo->instances[$modname][$instanceid];
if (!$cm->uservisible) {
//continue;
}
if ($log->action == 'add mod') {
$stradded = get_string('added', 'moodle', get_string('modulename', $modname));
$changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
} else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
$strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
$changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
}
}
}
}
if (!empty($changelist)) {
print_headline(get_string('courseupdates').':', 3);
$content = true;
foreach ($changelist as $changeinfo => $change) {
if ($change) {
$changes[$changeinfo] = $change;
}
}
if (isset($changes)){
if (count($changes) > 0) {
print_headline(get_string('courseupdates').':', 3);
$content = true;
foreach ($changes as $changeinfo => $change) {
echo '<p class="activity">'.$change['text'].'</p>';
}
}
echo '<p class="activity">'.$change['text'].'</p>';
}
}
// Now display new things from each module
/// Now display new things from each module
$mods = get_records('modules', 'visible', '1', 'name', 'id, name');
$usedmodules = array();
foreach($modinfo->cms as $cm) {
if (isset($usedmodules[$cm->modname])) {
continue;
}
if (!$cm->uservisible) {
continue;
}
$usedmodules[$cm->modname] = $cm->modname;
}
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
foreach ($mods as $mod) { // Each module gets it's own logs and prints them
if (file_exists($CFG->dirroot.'/mod/'.$mod->name.'/lib.php')) {
include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php');
$print_recent_activity = $mod->name.'_print_recent_activity';
foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
$print_recent_activity = $modname.'_print_recent_activity';
if (function_exists($print_recent_activity)) {
//
// NOTE:
// $isteacher (second parameter below) is to be deprecated!
//
// TODO:
// 1) Make sure that all _print_recent_activity functions are
// not using the $isteacher value.
// 2) Eventually, remove the $isteacher parameter from the
// function calls.
//
$modcontent = $print_recent_activity($course, $viewfullnames, $timestart);
if ($modcontent) {
$content = true;
}
// NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
$content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
}
} else {
/// Really need to indicate an error here to admins. Is there a way to do this?
debugging("Missing lib.php in lib/{$mod->name} - please reinstall files or uninstall the module");
}
}
@@ -1180,7 +959,7 @@ function get_array_of_activities($courseid) {
$mod = array();
if (!$rawmods = get_course_mods($courseid)) {
return NULL;
return $mod; // always return array
}
if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) {
@@ -1191,14 +970,16 @@ function get_array_of_activities($courseid) {
if (empty($rawmods[$seq])) {
continue;
}
$mod[$seq]->cm = $rawmods[$seq]->id;
$mod[$seq]->mod = $rawmods[$seq]->modname;
$mod[$seq]->section = $section->section;
$mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
$mod[$seq]->visible = $rawmods[$seq]->visible;
$mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
$mod[$seq]->id = $rawmods[$seq]->instance;
$mod[$seq]->cm = $rawmods[$seq]->id;
$mod[$seq]->mod = $rawmods[$seq]->modname;
$mod[$seq]->section = $section->section;
$mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
$mod[$seq]->visible = $rawmods[$seq]->visible;
$mod[$seq]->groupmode = $rawmods[$seq]->groupmode;
$mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
$mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
$mod[$seq]->extra = "";
$mod[$seq]->extra = "";
$modname = $mod[$seq]->mod;
$functionname = $modname."_get_coursemodule_info";
@@ -1223,15 +1004,141 @@ function get_array_of_activities($courseid) {
}
/**
* Returns reference to full info about modules in course (including visibility).
* Cached and as fast as possible (0 or 1 db query).
* @param $course object or 'reset' string to reset caches
* @return mixed courseinfo object or nothing if resetting
*/
function &get_fast_modinfo($course, $userid=0) {
global $CFG, $USER;
static $cache = array();
if ($course === 'reset') {
$cache = array();
$nothing = null;
return $nothing; // we must return some reference
}
if (empty($userid)) {
$userid = $USER->id;
}
if (array_key_exists($course->id, $cache) and $cache[$course->id]->userid == $userid) {
return $cache[$course->id];
}
if (empty($course->modinfo)) {
// no modinfo yet - load it
rebuild_course_cache($course->id);
if (!$course = get_record('course', 'id', $course->id)) {
error("Can not find course id: $course->id");
}
}
$modinfo = new object();
$modinfo->courseid = $course->id;
$modinfo->userid = $userid;
$modinfo->sections = array();
$modinfo->cms = array();
$modinfo->instances = array();
$modinfo->groups = null; // loaded only when really needed - the only one db query
$info = unserialize($course->modinfo);
if (!is_array($info)) {
// hmm, something is wrong - lets try to fix it
rebuild_course_cache($course->id);
if (!$course = get_record('course', 'id', $course->id)) {
error("Can not find course id: $course->id");
}
$info = unserialize($course->modinfo);
if (!is_array($info)) {
return $modinfo;
}
}
if ($info) {
// detect if upgrade required
$first = reset($info);
if (!isset($first->id)) {
rebuild_course_cache($course->id);
if (!$course = get_record('course', 'id', $course->id)) {
error("Can not find course id: $course->id");
}
$info = unserialize($course->modinfo);
if (!is_array($info)) {
return $modinfo;
}
}
}
$modlurals = array();
foreach ($info as $mod) {
// reconstruct minimalistic $cm
$cm = new object();
$cm->id = $mod->cm;
$cm->instance = $mod->id;
$cm->course = $course->id;
$cm->modname = $mod->mod;
$cm->name = urldecode($mod->name);
$cm->visible = $mod->visible;
$cm->section = $mod->section;
$cm->groupmode = $mod->groupmode;
$cm->groupingid = $mod->groupingid;
$cm->groupmembersonly = $mod->groupmembersonly;
$cm->extra = isset($mod->extra) ? urldecode($mod->extra) : '';
$cm->icon = isset($mod->icon) ? $mod->icon : '';
$cm->uservisible = true;
// preload long names plurals - used very often
if (!isset($modlurals[$cm->modname])) {
$modlurals[$cm->modname] = get_string('modulenameplural', $cm->modname);
}
$cm->modplural = $modlurals[$cm->modname];
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
$cm->uservisible = false;
} else if (!empty($CFG->enablegroupings) and !empty($cm->groupmembersonly)
and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id, $userid);
}
if (empty($modinfo->groups[$cm->groupingid])) {
$cm->uservisible = false;
}
}
if (!isset($modinfo->instances[$cm->modname])) {
$modinfo->instances[$cm->modname] = array();
}
$modinfo->instances[$cm->modname][$cm->instance] =& $cm;
$modinfo->cms[$cm->id] =& $cm;
// reconstruct sections
if (!isset($modinfo->sections[$cm->section])) {
$modinfo->sections[$cm->section] = array();
}
$modinfo->sections[$cm->section][] = $cm->id;
unset($cm);
}
$cache[$course->id] = $modinfo;
return $cache[$course->id];
}
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
// Returns a number of useful structures for course displays
$mods = NULL; // course modules indexed by id
$modnames = NULL; // all course module names (except resource!)
$modnamesplural= NULL; // all course module names (plural form)
$modnamesused = NULL; // course module names used
$mods = array(); // course modules indexed by id
$modnames = array(); // all course module names (except resource!)
$modnamesplural= array(); // all course module names (plural form)
$modnamesused = array(); // course module names used
if ($allmods = get_records("modules")) {
foreach ($allmods as $mod) {
@@ -1250,15 +1157,16 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
if (empty($modnames[$mod->modname])) {
continue;
}
$mods[$mod->id] = $mod;
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
continue;
}
// Check groupings
if (!groups_course_module_visible($mod)) {
continue;
}
$mods[$mod->id] = $mod;
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
$modnamesused[$mod->modname] = $modnames[$mod->modname];
}
$modnamesused[$mod->modname] = $modnames[$mod->modname];
}
if ($modnamesused) {
asort($modnamesused, SORT_LOCALE_STRING);
@@ -1285,6 +1193,7 @@ function course_set_display($courseid, $display=0) {
} else if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) {
set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid);
} else {
$record = new object();
$record->userid = $USER->id;
$record->course = $courseid;
$record->display = $display;
@@ -1317,41 +1226,43 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
/// Prints a section full of activity modules
global $CFG, $USER;
static $initialised;
static $groupbuttons;
static $groupbuttonslink;
static $isteacher;
static $isediting;
static $ismoving;
static $strmovehere;
static $strmovefull;
static $strunreadpostsone;
static $untracked;
static $usetracking;
static $groupings;
$labelformatoptions = New stdClass;
if (!isset($isteacher)) {
if (!isset($initialised)) {
$groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
$groupbuttonslink = (!$course->groupmodeforce);
$isediting = isediting($course->id);
$ismoving = $isediting && ismoving($course->id);
$isediting = isediting($course->id);
$ismoving = $isediting && ismoving($course->id);
if ($ismoving) {
$strmovehere = get_string("movehere");
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
$strmovehere = get_string("movehere");
$strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
}
include_once($CFG->dirroot.'/mod/forum/lib.php');
if ($usetracking = forum_tp_can_track_forums()) {
$strunreadpostsone = get_string('unreadpostsone', 'forum');
$untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
$strunreadpostsone = get_string('unreadpostsone', 'forum');
$untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
}
$initialised = true;
}
$labelformatoptions = new object();
$labelformatoptions->noclean = true;
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = unserialize((string)$course->modinfo);
$modinfo = get_fast_modinfo($course);
$groupings = groups_get_all_groupings($course->id);
//Acccessibility: replace table with list <ul>, but don't output empty list.
if (!empty($section->sequence)) {
@@ -1364,120 +1275,131 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if (($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) &&
(!$ismoving || $mod->id != $USER->activitycopy) &&
groups_course_module_visible($mod)) {
echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">'; // Unique ID
if ($ismoving) {
echo '<a title="'.$strmovefull.'"'.
' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
'<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
' alt="'.$strmovehere.'" /></a><br />
';
}
$instancename = urldecode($modinfo[$modnumber]->name);
$instancename = format_string($instancename, true, $course->id);
if ($ismoving and $mod->id == $USER->activitycopy) {
// do not display moving mod
continue;
}
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
} else {
$extra = "";
if (isset($modinfo->cms[$modnumber])) {
if (!$modinfo->cms[$modnumber]->uservisible) {
// visibility shortcut
continue;
}
} else {
if (!coursemodule_visible_for_user($mod)) {
// full visibility check
continue;
}
}
echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">'; // Unique ID
if ($ismoving) {
echo '<a title="'.$strmovefull.'"'.
' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
'<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
' alt="'.$strmovehere.'" /></a><br />
';
}
if ($mod->indent) {
print_spacer(12, 20 * $mod->indent, false);
}
$extra = $modinfo->cms[$modnumber]->extra;
if ($mod->modname == "label") {
if (!$mod->visible) {
echo "<span class=\"dimmed_text\">";
}
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
if (!$mod->visible) {
echo "</span>";
}
if (!empty($modinfo[$modnumber]->icon)) {
$icon = "$CFG->pixpath/".urldecode($modinfo[$modnumber]->icon);
} else { // Normal activity
$instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
if (!empty($modinfo->cms[$modnumber]->icon)) {
$icon = "$CFG->pixpath/".$modinfo->cms[$modnumber]->icon;
} else {
$icon = "$CFG->modpixpath/$mod->modname/icon.gif";
}
if ($mod->indent) {
print_spacer(12, 20 * $mod->indent, false);
}
//Accessibility: for files get description via icon.
$altname = '';
if ('resource'==$mod->modname) {
if (!empty($modinfo->cms[$modnumber]->icon)) {
$possaltname = $modinfo->cms[$modnumber]->icon;
if ($mod->modname == "label") {
if (!$mod->visible) {
echo "<span class=\"dimmed_text\">";
}
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
if (!$mod->visible) {
echo "</span>";
}
} else { // Normal activity
//Accessibility: for files get description via icon.
$altname = '';
if ('resource'==$mod->modname) {
if (!empty($modinfo[$modnumber]->icon)) {
$possaltname = $modinfo[$modnumber]->icon;
$mimetype = mimeinfo_from_icon('type', $possaltname);
$altname = get_mimetype_description($mimetype);
} else {
$altname = $mod->modfullname;
}
$mimetype = mimeinfo_from_icon('type', $possaltname);
$altname = get_mimetype_description($mimetype);
} else {
$altname = $mod->modfullname;
}
// Avoid unnecessary duplication.
if (false!==stripos($instancename, $altname)) {
$altname = '';
}
// File type after name, for alphabetic lists (screen reader).
if ($altname) {
$altname = get_accesshide(' '.$altname);
}
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
echo '<a '.$linkcss.' '.$extra. // Title unnecessary!
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
'<img src="'.$icon.'" class="activityicon" alt="" /> <span>'.
$instancename.$altname.'</span></a>';
if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo " <span class=\"groupinglabel\"> - ".format_string($groupings[$mod->groupingid]->name).'</span>';
}
} else {
$altname = $mod->modfullname;
}
if ($usetracking && $mod->modname == 'forum') {
$groupmode = groups_get_course_groupmode($course, $mod);
$groupid = ($groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) ?
groups_get_course_group($course, true) : false;
if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
$unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
if ($unread) {
echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
if ($unread == 1) {
echo $strunreadpostsone;
} else {
print_string('unreadpostsnumber', 'forum', $unread);
}
echo '</a> </span>';
}
}
// Avoid unnecessary duplication.
if (false!==stripos($instancename, $altname)) {
$altname = '';
}
// File type after name, for alphabetic lists (screen reader).
if ($altname) {
$altname = get_accesshide(' '.$altname);
}
if ($isediting) {
// TODO: we must define this as mod property!
if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $course->groupmode;
}
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
echo '<a '.$linkcss.' '.$extra. // Title unnecessary!
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
'<img src="'.$icon.'" class="activityicon" alt="" /> <span>'.
$instancename.$altname.'</span></a>';
} else {
$mod->groupmode = false;
if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
if (!isset($groupings)) {
$groupings = groups_get_all_groupings($course->id);
}
echo '&nbsp;&nbsp;';
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
echo " <span class=\"groupinglabel\"> - ".format_string($groupings[$mod->groupingid]->name).'</span>';
}
echo "</li>\n";
}
if ($usetracking && $mod->modname == 'forum') {
if ($usetracking and !isset($untracked[$mod->instance])) {
$groupid = groups_get_activity_group($mod);
$unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
if ($unread) {
echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
if ($unread == 1) {
echo $strunreadpostsone;
} else {
print_string('unreadpostsnumber', 'forum', $unread);
}
echo '</a> </span>';
}
}
}
if ($isediting) {
// TODO: we must define this as mod property!
if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $course->groupmode;
}
} else {
$mod->groupmode = false;
}
echo '&nbsp;&nbsp;';
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
}
echo "</li>\n";
}
} elseif ($ismoving) {
echo "<ul class=\"section\">\n";
}
if ($ismoving) {
echo '<li><a title="'.$strmovefull.'"'.
' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
@@ -1565,6 +1487,7 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
}
function rebuild_course_cache($courseid=0) {
global $COURSE;
// Rebuilds the cached list of course activities stored in the database
// If a courseid is not specified, then all are rebuilt
@@ -1581,11 +1504,16 @@ function rebuild_course_cache($courseid=0) {
if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
}
// update cached global COURSE too ;-)
if ($course->id == $COURSE->id) {
$COURSE->modinfo = $modinfo;
}
}
}
// reset the fast modinfo cache
get_fast_modinfo('reset');
}
function get_child_categories($parent) {
/// Returns an array of the children categories for the given category
/// ID by caching all of the categories in a static hash
@@ -2640,9 +2568,7 @@ function print_visible_setting($form, $course=NULL) {
echo '<tr valign="top">';
echo '<td align="right"><b>'.get_string('visible', '').':</b></td>';
echo '<td align="left">';
unset($choices);
$choices[1] = get_string('show');
$choices[0] = get_string('hide');
$choices = array(1 => get_string('show'), 0 => get_string('hide'));
choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection);
echo '</td></tr>';
}
@@ -2654,8 +2580,10 @@ function update_restricted_mods($course,$mods) {
}
else {
foreach ($mods as $mod) {
if ($mod == 0)
if ($mod == 0) {
continue; // this is the 'allow none' option
}
$am = new object();
$am->course = $course->id;
$am->module = $mod;
insert_record("course_allowed_modules",$am);
+160 -210
View File
@@ -2,207 +2,164 @@
// Display all recent activity in a flexible way
require_once("../config.php");
require_once("lib.php");
require_once('../config.php');
require_once('lib.php');
require_once('recent_form.php');
$id = required_param('id', PARAM_INT);
$user = optional_param('user', '0', PARAM_INT);
$sortby = optional_param('sortby', 'default', PARAM_ALPHA);
$selectedgroup = optional_param('selectedgroup', 0, PARAM_INT);
$date = optional_param('date', '', PARAM_INT);
$advancedfilter = optional_param('advancedfilter', 0, PARAM_INT);
$modname = optional_param('modname', '', PARAM_ALPHA); // not used??
$modid = optional_param('modid', 'activity/All', PARAM_FILE); // not a file, but looks like it anyway
$modaction = optional_param('modaction', '', PARAM_ALPHA); // not used??
$chooserecent = optional_param('chooserecent', 0, PARAM_INT);
$id = required_param('id', PARAM_INT);
if (! $course = get_record("course", "id", $id) ) {
if (!$course = get_record('course', 'id', $id) ) {
error("That's an invalid course id");
}
require_login($course->id);
require_login($course);
add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", "$course->id");
add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$strrecentactivity = get_string("recentactivity");
$meta = '<meta name="robots" content="none" />'; // prevent duplicate content in search engines MDL-7299
$loggedinas = user_login_string($course, $USER);
$navlinks = array();
if (!empty($chooserecent)) {
$userinfo = get_string("allparticipants");
$dateinfo = get_string("alldays");
if ($user) {
if (!$u = get_record("user", "id", $user) ) {
error("That's an invalid user!");
}
$userinfo = fullname($u);
$lastlogin = time() - COURSE_MAX_RECENT_PERIOD;
if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) {
if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) {
$lastlogin = $USER->lastcourseaccess[$COURSE->id];
}
if ($date)
$dateinfo = userdate($date, get_string("strftimedaydate"));
$navlinks[] = array('name' => $strrecentactivity, 'link' => "recent.php?id=$course->id", 'type' => 'misc');
$navlinks[] = array('name' => "$userinfo, $dateinfo", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strrecentactivity", $course->fullname, $navigation, "", $meta);
print_heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")", '', 3);
$advancedfilter = 1;
print_recent_selector_form($course, $advancedfilter, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby);
} else {
if (empty($date)) { // no date picked, default to last login time
$date = time() - COURSE_MAX_RECENT_PERIOD;
if (!empty($USER->lastcourseaccess[$course->id])) {
if ($USER->lastcourseaccess[$course->id] > $date) {
$date = $USER->lastcourseaccess[$course->id];
}
}
}
$navlinks[] = array('name' => $strrecentactivity, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strrecentactivity", $course->fullname, $navigation, "", $meta);
print_heading(get_string("activitysince", "", userdate($date)));
print_recent_selector_form($course, $advancedfilter);
}
$tmpmodid = $modid;
$param = new object();
$param->user = 0;
$param->modid = 'all';
$param->group = 0;
$param->sortby = 'default';
$param->date = $lastlogin;
$param->id = $COURSE->id;
switch ($tmpmodid) {
case "activity/Assignments" : $filter = "assignment"; break;
case "activity/Chats" : $filter = "chat"; break;
case "activity/Forums" : $filter = "forum"; break;
case "activity/Quizzes" : $filter = "quiz"; break;
case "activity/Workshops" : $filter = "workshop"; break;
default : $filter = "";
$mform = new recent_form();
$mform->set_data($param);
if ($formdata = $mform->get_data(false)) {
$param = $formdata;
}
$userinfo = get_string('allparticipants');
$dateinfo = get_string('alldays');
if (!empty($param->user)) {
if (!$u = get_record('user', 'id', $param->user) ) {
error("That's an invalid user!");
}
$userinfo = fullname($u);
}
$strrecentactivity = get_string('recentactivity');
$navlinks = array();
$navlinks[] = array('name' => $strrecentactivity, 'link' => "recent.php?id=$course->id", 'type' => 'misc');
$navlinks[] = array('name' => $userinfo, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strrecentactivity", $course->fullname, $navigation, '', $meta);
print_heading(format_string($course->fullname) . ": $userinfo", '', 3);
$mform->display();
$modinfo =& get_fast_modinfo($course);
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
if (has_capability('moodle/course:viewhiddensections', $context)) {
$hiddenfilter = "";
} else {
$hiddenfilter = "AND cs.visible = 1";
}
$sections = array();
if ($ss = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
FROM {$CFG->prefix}course_sections cs
WHERE cs.course = $course->id AND cs.section <= $course->numsections
$hiddenfilter
ORDER BY section")) {
foreach ($ss as $section) {
$sections[$section->section] = $section;
}
}
if ($param->modid === 'all') {
// ok
} else if (strpos($param->modid, 'mod/') === 0) {
$modname = substr($param->modid, strlen('mod/'));
if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
$filter = $modname;
}
} else if (strpos($param->modid, 'section/') === 0) {
$sectionid = substr($param->modid, strlen('section/'));
if (isset($sections[$sectionid])) {
$sections = array($sectionid=>$sections[$sectionid]);
}
} else if (is_numeric($param->modid)) {
$section = $sections[$modinfo->cms[$param->modid]->section];
$section->sequence = $param->modid;
$sections = array($section->sequence=>$section);
}
switch ($course->format) {
case 'weeks': $sectiontitle = get_string('week'); break;
case 'topics': $sectiontitle = get_string('topic'); break;
default: $sectiontitle = get_string('section'); break;
}
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$activities = array();
$sections = array();
switch ($course->format) {
case "weeks": $sectiontitle = get_string("week"); break;
case "topics": $sectiontitle = get_string("topic"); break;
default: $sectiontitle = get_string("section"); break;
}
$index = 0;
if (is_numeric($modid)) { // you chose a single activity
foreach ($sections as $section) {
$sections[0]->sequence = "$modid";
} else { // you chose a group of activities
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfilter = "";
$activity = new object();
$activity->type = 'section';
if ($section->section > 0) {
$activity->name = $sectiontitle.' '.$section->section;
} else {
$hiddenfilter = " AND cs.visible = '1' ";
$activity->name = '';
}
$sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
FROM {$CFG->prefix}course_sections cs
WHERE course = '$course->id' $hiddenfilter
ORDER by section");
}
$activity->visible = $section->visible;
$activities[$index++] = $activity;
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
if (!empty($sections)) {
echo "<hr />";
$i = 0;
if (!empty($filter)) {
$activityfilter = "AND m.name = '$filter'";
} else {
$activityfilter = "";
if (empty($section->sequence)) {
continue;
}
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfilter = "";
} else {
$hiddenfilter = " AND cm.visible = '1' ";
}
$sectionmods = explode(",", $section->sequence);
foreach ($sections as $section) {
if ($i <= $course->numsections) {
$activity = new Object;
$activity->type = "section";
if ($i) {
$activity->name = $sectiontitle . " $i";
} else {
$activity->name = '';
}
$activity->visible = $section->visible;
$activities[$index] = $activity;
foreach ($sectionmods as $cmid) {
if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) {
continue;
}
$index++;
$i++;
$sectionmods = explode(",", $section->sequence);
$cm = $modinfo->cms[$cmid];
foreach ($sectionmods as $sectionmod) {
if (!$cm->uservisible) {
continue;
}
if (empty($mods[$sectionmod])) {
continue;
}
$mod = $mods[$sectionmod];
$instance = get_record("$mod->modname", "id", "$mod->instance");
if (!empty($filter) and $cm->modname != $filter) {
continue;
}
$coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode, cm.visible, cm.course, cm.groupingid
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules m
WHERE course = '$course->id' $hiddenfilter
AND m.id = cm.module $activityfilter
AND cm.id = '$sectionmod'");
$libfile = "$CFG->dirroot/mod/$cm->modname/lib.php";
if (!$coursemod) {
continue;
}
if (file_exists($libfile)) {
require_once($libfile);
$get_recent_mod_activity = $cm->modname."_get_recent_mod_activity";
$groupmode = groups_get_activity_groupmode($coursemod);
switch ($groupmode) {
case SEPARATEGROUPS :
$groupid = 0;
if ($mygroups = groups_get_all_groups($course->id, $USER->id, $coursemod->groupingid)) {
if (array_key_exists($selectedgroup, $mygroups)) {
$groupid = $selectedgroup;
}
}
break;
case VISIBLEGROUPS : $groupid = $selectedgroup; break;
case NOGROUPS :
default : $groupid = 0;
}
$libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
if (file_exists($libfile)) {
require_once($libfile);
$get_recent_mod_activity = $coursemod->name."_get_recent_mod_activity";
if (function_exists($get_recent_mod_activity)) {
$activity = new Object;
$activity->type = "activity";
$activity->name = $instance->name;
$activity->visible = $coursemod->visible;
$activity->content->modfullname = $mod->modfullname;
$activity->content->modname = $mod->modname;
$activity->content->modid =$mod->id;
$activities[$index] = $activity;
$index++;
$get_recent_mod_activity($activities, $index, $date, $course->id, $sectionmod, $user, $groupid);
}
if (function_exists($get_recent_mod_activity)) {
$activity = new object();
$activity->type = 'activity';
$activity->cmid = $cmid;
$activities[$index++] = $activity;
$get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group);
}
}
}
@@ -210,81 +167,76 @@
$detail = true;
switch ($sortby) {
case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
case "default" :
default : $detail = false; $sortby = "default";
switch ($param->sortby) {
case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break;
case 'dateasc' : usort($activities, 'compare_activities_by_time_asc'); break;
case 'default' :
default : $detail = false; $sortby = 'default';
}
if (!empty($activities)) {
$newsection = true;
$lastsection = "";
$newinstance = true;
$lastinstance = "";
$inbox = false;
$newsection = true;
$lastsection = '';
$newinstance = true;
$lastinstance = '';
$inbox = false;
$section = 0;
if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
$teacher = true;
} else {
$teacher = false;
}
$activity_count = count($activities);
foreach ($activities as $key => $activity) {
// peak at next activity. If it's another section, don't print this one!
// this means there are no activities in the current section
if (($activity->type == "section") &&
if (($activity->type == 'section') &&
(($activity_count == ($key + 1)) ||
($activities[$key+1]->type == "section"))) {
($activities[$key+1]->type == 'section'))) {
continue;
}
if (($activity->type == "section") && ($sortby == "default")) {
if (($activity->type == 'section') && ($sortby == 'default')) {
if ($inbox) {
print_simple_box_end();
print_spacer(30);
}
print_simple_box_start("center", "90%");
print_simple_box_start('center', '90%');
echo "<h2>$activity->name</h2>";
$inbox = true;
} else if ($activity->type == "activity") {
} else if ($activity->type == 'activity') {
if ($sortby == "default") {
if ($teacher && $activity->visible == 0) {
$linkformat = 'class="dimmed"';
} else {
$linkformat = '';
}
$image = "<img src=\"$CFG->modpixpath/" . $activity->content->modname . "/icon.gif\"" .
" class=\"icon\" alt=\"" . $activity->content->modfullname . "\" />";
echo "<ul><h4>$image " . $activity->content->modfullname .
" <a href=\"$CFG->wwwroot/mod/" . $activity->content->modname . "/view.php?" .
"id=" . $activity->content->modid . "\" $linkformat>" .
format_string($activity->name,true) . "</a></h4></ul>";
if ($sortby == 'default') {
$cm = $modinfo->cms[$activity->cmid];
if ($cm->visible) {
$linkformat = '';
} else {
$linkformat = 'class="dimmed"';
}
$name = format_string($cm->name);
$modfullname = $modnames[$cm->modname];
$image = "<img src=\"$CFG->modpixpath/$cm->modname/icon.gif\" class=\"icon\" alt=\"$modfullname\" />";
echo "<h4>$image $modfullname".
" <a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\" $linkformat>$name</a></h4>";
}
} else {
if (!$inbox) {
print_simple_box_start("center", "90%");
print_simple_box_start('center', '90%');
$inbox = true;
}
$print_recent_mod_activity = $activity->type."_print_recent_mod_activity";
$print_recent_mod_activity = $activity->type.'_print_recent_mod_activity';
if (function_exists($print_recent_mod_activity)) {
echo '<ul><ul>';
$print_recent_mod_activity($activity, $course->id, $detail);
echo '</ul></ul>';
$print_recent_mod_activity($activity, $course->id, $detail, $modnames);
}
}
}
@@ -296,17 +248,15 @@
} else {
echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
echo '<h4><center>' . get_string('norecentactivity') . '</center></h2>';
}
// fix modid for selection form
$modid =$tmpmodid;
print_footer($course);
function compare_activities_by_time_desc($a, $b) {
// make sure the activities actually have a timestamp property
if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) {
return 0;
}
if ($a->timestamp == $b->timestamp)
@@ -316,7 +266,7 @@ function compare_activities_by_time_desc($a, $b) {
function compare_activities_by_time_asc($a, $b) {
// make sure the activities actually have a timestamp property
if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) {
return 0;
}
if ($a->timestamp == $b->timestamp)
+111
View File
@@ -0,0 +1,111 @@
<?php //$$
require_once($CFG->libdir.'/formslib.php');
class recent_form extends moodleform {
function definition() {
global $CFG, $COURSE, $USER;
$mform =& $this->_form;
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$modinfo = get_fast_modinfo($COURSE);
$mform->addElement('header', 'filters', get_string('managefilters')); //TODO: add better string
if ($COURSE->id == SITEID) {
$viewparticipants = has_capability('moodle/site:viewparticipants', get_context_instance(CONTEXT_SYSTEM));
} else {
$viewparticipants = has_capability('moodle/course:viewparticipants', $context);
}
$viewfullnames = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $COURSE->id));
if ($viewparticipants) {
$options = array();
$options[0] = get_string('allparticipants');
if ($guest = get_guest()) {
$options[$guest->id] = fullname($guest);
}
if ($courseusers = get_users_by_capability($context, 'moodle/course:view', 'u.id, u.firstname, u.lastname', 'lastname ASC, firstname DESC')) {
foreach ($courseusers as $courseuser) {
$options[$courseuser->id] = fullname($courseuser, $viewfullnames);
}
}
$mform->addElement('select', 'user', get_string('participants'), $options);
$mform->setAdvanced('user');
}
switch ($COURSE->format) {
case 'weeks': $sectiontitle = get_string('week'); break;
case 'topics': $sectiontitle = get_string('topic'); break;
default: $sectiontitle = get_string('section'); break;
}
$options = array(''=>get_string('allactivities'));
$modsused = array();
foreach($modinfo->cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$modsused[$cm->modname] = true;
}
foreach ($modsused as $modname=>$unused) {
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
if (!file_exists($libfile)) {
unset($modsused[$modname]);
continue;
}
include_once($libfile);
$libfunction = $modname."_get_recent_mod_activity";
if (!function_exists($libfunction)) {
unset($modsused[$modname]);
continue;
}
$options["mod/$modname"] = get_string('allmods', '', get_string('modulenameplural', $modname));
}
foreach ($modinfo->sections as $section=>$cmids) {
$options["section/$section"] = "-- $sectiontitle $section --";
foreach ($cmids as $cmid) {
$cm = $modinfo->cms[$cmid];
if (empty($modsused[$cm->modname]) or !$cm->uservisible) {
continue;
}
$options[$cm->id] = format_string($cm->name);
}
}
$mform->addElement('select', 'modid', get_string('activities'), $options);
$mform->setAdvanced('modid');
if (has_capability('moodle/site:accessallgroups', $context)) {
if ($groups = groups_get_all_groups($COURSE->id)) {
$options = array('0'=>get_string('allgroups'));
foreach($groups as $group) {
$options[$group->id] = format_string($group->name);
}
$mform->addElement('select', 'group', get_string('groups'), $options);
$mform->setAdvanced('group');
}
} else {
$mform->addElement('hidden','group');
$mform->setConstants(array('group'=>0));
}
$options = array('default' => get_string('bycourseorder'),
'dateasc' => get_string('datemostrecentlast'),
'datedesc' => get_string('datemostrecentfirst'));
$mform->addElement('select', 'sortby', get_string('sortby'), $options);
$mform->setAdvanced('sortby');
$mform->addElement('date_time_selector', 'date', get_string('since'), array('optional'=>true));
$mform->addElement('hidden','id');
$mform->setType('courseid', PARAM_INT);
$this->add_action_buttons(false, get_string('showrecent'));
}
}
+24 -11
View File
@@ -6,10 +6,10 @@
function activitynames_filter($courseid, $text) {
global $CFG;
global $CFG, $COURSE;
// Trivial-cache - keyed on $cachedcourseid
static $activitylist;
static $activitylist = null;
static $cachedcourseid;
if (empty($courseid)) {
@@ -18,15 +18,25 @@
// Initialise/invalidate our trivial cache if dealing with a different course
if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) {
$activitylist = array();
$activitylist = null;
}
$cachedcourseid = (int)$courseid;
/// It may be cached
if (empty($activitylist)) {
if (is_null($activitylist)) {
$activitylist = array();
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$course = get_record("course", "id", $courseid);
}
if (!isset($course->modinfo)) {
return $text;
}
$course = get_record("course","id",$courseid);
/// Casting $course->modinfo to string prevents one notice when the field is null
$modinfo = unserialize((string)$course->modinfo);
@@ -35,15 +45,14 @@
$activitylist = array(); /// We will store all the activities here
//Sort modinfo by name length
usort($modinfo,'comparemodulenamesbylength');
usort($modinfo, 'comparemodulenamesbylength');
foreach ($modinfo as $activity) {
//Exclude labels and hidden items
if ($activity->mod != "label" && $activity->visible) {
$title = trim(strip_tags(urldecode($activity->name)));
//Exclude labels, hidden activities and activities for group members only
if ($activity->mod != "label" and $activity->visible and empty($activity->groupmembersonly)) {
$title = s(trim(strip_tags(urldecode($activity->name))));
/// Avoid empty or unlinkable activity names
if (!empty($title)) {
$title = str_replace('"', "'", $title);
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>";
$currentname = urldecode($activity->name);
if ($currentname = trim($currentname)) {
@@ -55,7 +64,11 @@
}
}
return $text = filter_phrases ($text, $activitylist);
if ($activitylist) {
return $text = filter_phrases ($text, $activitylist);
} else {
return $text;
}
}
+3
View File
@@ -26,6 +26,7 @@ $string['comment'] = 'Comment';
$string['commentinline'] = 'Comment inline';
$string['configitemstocount'] = 'Nature of items to be counted for student submissions in online assignments.';
$string['configmaxbytes'] = 'Default maximum assignment size for all assignments on the site (subject to course limits and other local settings)';
$string['configshowrecentsubmissions'] = 'Everyone can see notifications of submissions in recent activity reports.';
$string['confirmdeletefile'] = 'Are you absolutely sure you want to delete this file?<br /><strong>$a</strong>';
$string['deleteallsubmissions'] = 'Delete all submissions';
$string['deletefilefailed'] = 'Deleting of file failed.';
@@ -91,6 +92,7 @@ $string['notesempty'] = 'No entry';
$string['notesupdateerror'] = 'Error when updating notes';
$string['notgradedyet'] = 'Not graded yet';
$string['notsubmittedyet'] = 'Not submitted yet';
$string['nosubmitusers'] = 'No users were found with permissions to submit this assignment';
$string['onceassignmentsent'] = 'Once the assignment is sent for marking, you will no longer be able to delete or attach file(s). Do you want to continue?';
$string['overwritewarning'] = 'Warning: uploading again will REPLACE your current submission';
$string['pagesize'] = 'Submissions shown per page';
@@ -100,6 +102,7 @@ $string['responsefiles'] = 'Response files';
$string['reviewed'] = 'Reviewed';
$string['saveallfeedback'] = 'Save all my feedback';
$string['sendformarking'] = 'Send for marking';
$string['showrecentsubmissions'] = 'Show recent submissions';
$string['submission'] = 'Submission';
$string['submissiondraft'] = 'Submission draft';
$string['submissionfeedback'] = 'Submission feedback';
+1
View File
@@ -50,6 +50,7 @@ $string['normalkeepalive'] = 'KeepAlive';
$string['normalstream'] = 'Stream';
$string['noscheduledsession'] = 'No scheduled session';
$string['oldping'] = 'Disconnect timeout';
$string['pastchats'] = 'Past chat sessions';
$string['refreshroom'] = 'Refresh room';
$string['refreshuserlist'] = 'Refresh user list';
$string['removemessages'] = 'Remove all messages';
+1
View File
@@ -99,6 +99,7 @@ $string['allfieldsrequired'] = 'All fields are required';
$string['allfiles'] = 'All files';
$string['allgroups'] = 'All groups';
$string['alllogs'] = 'All logs';
$string['allmods'] = 'All $a';
$string['allow'] = 'Allow';
$string['allowguests'] = 'This course allows guest users to enter';
$string['allowinternal'] = 'Allow internal methods as well';
+48 -2
View File
@@ -1642,6 +1642,28 @@ function get_coursemodule_from_instance($modulename, $instance, $courseid=0) {
}
/**
* Returns all course modules of given activity in course
* @param string $modulename (forum, quiz, etc.)
* @param int $courseid
* @param string $extrafields extra fields starting with m.
* @return array of cm objects, false if not found or error
*/
function get_coursemodules_in_course($modulename, $courseid, $extrafields='') {
global $CFG;
if (!empty($extrafields)) {
$extrafields = ", $extrafields";
}
return get_records_sql("SELECT cm.*, m.name, md.name as modname $extrafields
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}modules md,
{$CFG->prefix}$modulename m
WHERE cm.course = $courseid AND
cm.instance = m.id AND
md.name = '$modulename' AND
md.id = cm.module");
}
/**
* Returns an array of all the active instances of a particular module in given courses, sorted in the order they are defined
*
@@ -1781,7 +1803,7 @@ function get_all_instances_in_course($modulename, $course, $userid=NULL, $includ
*
* Given a valid module object with info about the id and course,
* and the module's type (eg "forum") returns whether the object
* is visible or not
* is visible or not, groupmembersonly visibility not tested
*
* @uses $CFG
* @param $moduletype Name of the module eg 'forum'
@@ -1802,13 +1824,37 @@ function instance_is_visible($moduletype, $module) {
cm.instance = '$module->id'")) {
foreach ($records as $record) { // there should only be one - use the first one
return $record->visible && groups_course_module_visible($record);
return $record->visible;
}
}
}
return true; // visible by default!
}
/**
* Determine whether a course module is visible within a course,
* this is different from instance_is_visible() - faster and visibility for user
*
* @param object $cm object
* @param int $userid empty means current user
* @return bool
*/
function coursemodule_visible_for_user($cm, $userid=0) {
global $USER;
if (empty($cm->id)) {
debugging("Incorrect course module parameter!", DEBUG_DEVELOPER);
return false;
}
if (empty($userid)) {
$userid = $USER->id;
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
return false;
}
return groups_course_module_visible($cm, $userid);
}
+2 -2
View File
@@ -712,8 +712,8 @@ function main_upgrade($oldversion=0) {
}
if ($oldversion < 2004042600) { /// Rebuild course caches for resource icons
include_once("$CFG->dirroot/course/lib.php");
rebuild_course_cache();
//include_once("$CFG->dirroot/course/lib.php");
//rebuild_course_cache();
}
if ($oldversion < 2004042700) { /// Increase size of lang fields
+2 -2
View File
@@ -456,8 +456,8 @@ function main_upgrade($oldversion=0) {
}
if ($oldversion < 2004042600) { /// Rebuild course caches for resource icons
include_once("$CFG->dirroot/course/lib.php");
rebuild_course_cache();
//include_once("$CFG->dirroot/course/lib.php");
//rebuild_course_cache();
}
if ($oldversion < 2004042700) { /// Increase size of lang fields
+14 -2
View File
@@ -46,8 +46,8 @@ function xmldb_main_upgrade($oldversion=0) {
// Hide all activities
set_field('course_modules', 'visible', '0', 'module', $module->id);
require_once($CFG->dirroot.'/course/lib.php');
rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
//require_once($CFG->dirroot.'/course/lib.php');
//rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
}
}
@@ -2663,6 +2663,18 @@ function xmldb_main_upgrade($oldversion=0) {
upgrade_main_savepoint($result, 2007101506);
}
if ($result && $oldversion < 2007101507) {
$db->debug = false;
require_once($CFG->dirroot.'/course/lib.php');
notify('Started rebuilding of course cache...', 'notifysuccess');
rebuild_course_cache(); // Rebuild course cache - new group related fields there
notify('...finished rebuilding of course cache.', 'notifysuccess');
$db->debug = true;
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101507);
}
return $result;
}
+52 -13
View File
@@ -128,6 +128,42 @@ function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
ORDER BY name ASC");
}
/**
* Returns info about user's groups in course.
* @param int $courseid
* @param int $userid $USER if not specified
* @return array[groupingid][groupid] including grouping id 0 which means all groups
*/
function groups_get_user_groups($courseid, $userid=0) {
global $CFG, $USER;
if (empty($userid)) {
$userid = $USER->id;
}
if (!$groups = get_records_sql("SELECT g.id, gg.groupingid
FROM {$CFG->prefix}groups g
JOIN {$CFG->prefix}groups_members gm ON gm.groupid = g.id
LEFT JOIN {$CFG->prefix}groupings_groups gg ON gg.groupid = g.id
WHERE gm.userid = $userid AND g.courseid = $courseid")) {
return array('0' => array());
}
$result = array('0' => array_keys($groups)); // all groups
foreach ($groups as $group) {
if (is_null($group->groupingid)) {
continue;
}
if (!array_key_exists($group->groupingid, $result)) {
$result[$group->groupingid] = array();
}
$result[$group->groupingid][$group->id] = $group->id;
}
return $result;
}
/**
* Gets array of all groupings in a specified course.
* @param int $courseid return only groupings in this with this courseid
@@ -259,13 +295,16 @@ function groups_get_course_groupmode($course) {
* Returns effective groupmode used in activity, course setting
* overrides activity setting if groupmodeforce enabled.
* @param $cm the course module object. Only the ->course and ->groupmode need to be set.
* @param $course object optional course object to improve perf
* @return integer group mode
*/
function groups_get_activity_groupmode($cm) {
function groups_get_activity_groupmode($cm, $course=null) {
global $COURSE;
// get course object (reuse COURSE if possible)
if ($cm->course == $COURSE->id) {
if (isset($course->id) and $course->id == $cm->course) {
//ok
} else if ($cm->course == $COURSE->id) {
$course = $COURSE;
} else {
if (!$course = get_record('course', 'id', $cm->course)) {
@@ -302,13 +341,13 @@ function groups_print_course_menu($course, $urlroot, $return=false) {
if (!array_key_exists($SESSION->activegroup[$course->id][VISIBLEGROUPS][0], $allowedgroups)) {
// active does not exist anymore
unset($SESSION->activegroup[$course->id][VISIBLEGROUPS][0]);
}
}
}
if (!empty($SESSION->activegroup[$course->id]['aag'][0])) {
if (!array_key_exists($SESSION->activegroup[$course->id]['aag'][0], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$course->id]['aag'][0]);
}
}
}
} else {
@@ -324,7 +363,7 @@ function groups_print_course_menu($course, $urlroot, $return=false) {
if (!array_key_exists($SESSION->activegroup[$course->id][SEPARATEGROUPS][0], $allowedgroups)) {
// active group not allowed or does not exist anymore
unset($SESSION->activegroup[$course->id][SEPARATEGROUPS][0]);
}
}
}
}
}
@@ -402,13 +441,13 @@ function groups_print_activity_menu($cm, $urlroot, $return=false, $hideallpartic
if (!array_key_exists($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid]);
}
}
}
if (!empty($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid])) {
if (!array_key_exists($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid]);
}
}
}
} else {
@@ -424,7 +463,7 @@ function groups_print_activity_menu($cm, $urlroot, $return=false, $hideallpartic
if (!array_key_exists($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group not allowed or does not exist anymore
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
}
}
}
}
}
@@ -654,15 +693,15 @@ function groups_course_module_visible($cm, $userid=null) {
$userid = $USER->id;
}
if (empty($CFG->enablegroupings)) {
return(true);
return true;
}
if (empty($cm->groupmembersonly)) {
return(true);
return true;
}
if (groups_has_membership($cm, $userid) || has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
return(true);
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid) or groups_has_membership($cm, $userid)) {
return true;
}
return(false);
return false;
}
?>
+77 -90
View File
@@ -4742,23 +4742,22 @@ function print_table($table, $return=false) {
return true;
}
function print_recent_activity_note($time, $user, $text, $link, $return=false) {
static $strftimerecent;
function print_recent_activity_note($time, $user, $text, $link, $return=false, $viewfullnames=null) {
static $strftimerecent = null;
$output = '';
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
if (is_null($viewfullnames)) {
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
}
if (empty($strftimerecent)) {
if (is_null($strftimerecent)) {
$strftimerecent = get_string('strftimerecent');
}
$date = userdate($time, $strftimerecent);
$name = fullname($user, $viewfullnames);
$output .= '<div class="head">';
$output .= '<div class="date">'.$date.'</div> '.
'<div class="name">'.fullname($user, $viewfullnames).'</div>';
$output .= '<div class="date">'.userdate($time, $strftimerecent).'</div>';
$output .= '<div class="name">'.fullname($user, $viewfullnames).'</div>';
$output .= '</div>';
$output .= '<div class="info"><a href="'.$link.'">'.format_string($text,true).'</a></div>';
@@ -5222,10 +5221,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
}
$strjumpto = get_string('jumpto');
/// Casting $course->modinfo to string prevents one notice when the field is null
if (!$modinfo = unserialize((string)$course->modinfo)) {
return '';
}
$modinfo = get_fast_modinfo($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$section = -1;
@@ -5246,21 +5242,20 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
$THEME->navmenulist = navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $width, $cm);
}
foreach ($modinfo as $mod) {
if ($mod->mod == 'label') {
foreach ($modinfo->cms as $mod) {
if ($mod->modname == 'label') {
continue;
}
if ($mod->section > $course->numsections) { /// Don't show excess hidden sections
break;
}
$mod->id = $mod->cm;
$mod->course = $course->id;
if (!groups_course_module_visible($mod)) {
if (!$mod->uservisible) { // do not icnlude empty sections at all
continue;
}
if ($mod->section > 0 and $section <> $mod->section) {
if ($mod->section > 0 and $section != $mod->section) {
$thissection = $sections[$mod->section];
if ($thissection->visible or !$course->hiddensections or
@@ -5275,41 +5270,39 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
$menu[] = '--'.substr($thissection->summary, 0, $width).'...';
}
}
}
}
$section = $mod->section;
//Only add visible or teacher mods to jumpmenu
if ($mod->visible or has_capability('moodle/course:viewhiddenactivities',
get_context_instance(CONTEXT_MODULE, $mod->cm))) {
$url = $mod->mod .'/view.php?id='. $mod->cm;
if ($flag) { // the current mod is the "next" mod
$nextmod = $mod;
$flag = false;
}
if ($cm == $mod->cm) {
$selected = $url;
$selectmod = $mod;
$backmod = $previousmod;
$flag = true; // set flag so we know to use next mod for "next"
$mod->name = $strjumpto;
$strjumpto = '';
$section = $mod->section;
} else {
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
if (strlen($mod->name) > ($width+5)) {
$mod->name = substr($mod->name, 0, $width).'...';
}
if (!$mod->visible) {
$mod->name = '('.$mod->name.')';
}
// no activities from this hidden section shown
continue;
}
$menu[$url] = $mod->name;
if (empty($THEME->navmenuiconshide)) {
$menustyle[$url] = 'style="background-image: url('.$CFG->modpixpath.'/'.$mod->mod.'/icon.gif);"'; // Unfortunately necessary to do this here
}
$previousmod = $mod;
}
$url = $mod->modname.'/view.php?id='. $mod->id;
if ($flag) { // the current mod is the "next" mod
$nextmod = $mod;
$flag = false;
}
if ($cm == $mod->id) {
$selected = $url;
$selectmod = $mod;
$backmod = $previousmod;
$flag = true; // set flag so we know to use next mod for "next"
$mod->name = $strjumpto;
$strjumpto = '';
} else {
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
if (strlen($mod->name) > ($width+5)) {
$mod->name = substr($mod->name, 0, $width).'...';
}
if (!$mod->visible) {
$mod->name = '('.$mod->name.')';
}
}
$menu[$url] = $mod->name;
if (empty($THEME->navmenuiconshide)) {
$menustyle[$url] = 'style="background-image: url('.$CFG->modpixpath.'/'.$mod->modname.'/icon.gif);"'; // Unfortunately necessary to do this here
}
$previousmod = $mod;
}
//Accessibility: added Alt text, replaced &gt; &lt; with 'silent' character and 'accesshide' text.
@@ -5318,23 +5311,23 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
$logslink = '<li>'."\n".'<a title="'.$logstext.'" '.
$CFG->frametarget.'onclick="this.target=\''.$CFG->framename.'\';"'.' href="'.
$CFG->wwwroot.'/course/report/log/index.php?chooselog=1&amp;user=0&amp;date=0&amp;id='.
$course->id.'&amp;modid='.$selectmod->cm.'">'.
$course->id.'&amp;modid='.$selectmod->id.'">'.
'<img class="icon log" src="'.$CFG->pixpath.'/i/log.gif" alt="'.$logstext.'" /></a>'."\n".'</li>';
}
if ($backmod) {
$backtext= get_string('activityprev', 'access');
$backmod = '<li><form action="'.$CFG->wwwroot.'/mod/'.$backmod->mod.'/view.php" '.
$backmod = '<li><form action="'.$CFG->wwwroot.'/mod/'.$backmod->modname.'/view.php" '.
'onclick="this.target=\''.$CFG->framename.'\';"'.'><fieldset class="invisiblefieldset">'.
'<input type="hidden" name="id" value="'.$backmod->cm.'" />'.
'<input type="hidden" name="id" value="'.$backmod->id.'" />'.
'<button type="submit" title="'.$backtext.'">'.link_arrow_left($backtext, $url='', $accesshide=true).
'</button></fieldset></form></li>';
}
if ($nextmod) {
$nexttext= get_string('activitynext', 'access');
$nextmod = '<li><form action="'.$CFG->wwwroot.'/mod/'.$nextmod->mod.'/view.php" '.
$nextmod = '<li><form action="'.$CFG->wwwroot.'/mod/'.$nextmod->modname.'/view.php" '.
'onclick="this.target=\''.$CFG->framename.'\';"'.'><fieldset class="invisiblefieldset">'.
'<input type="hidden" name="id" value="'.$nextmod->cm.'" />'.
'<input type="hidden" name="id" value="'.$nextmod->id.'" />'.
'<button type="submit" title="'.$nexttext.'">'.link_arrow_right($nexttext, $url='', $accesshide=true).
'</button></fieldset></form></li>';
}
@@ -5362,21 +5355,15 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
global $CFG;
$section = -1;
$selected = '';
$url = '';
$previousmod = NULL;
$backmod = NULL;
$nextmod = NULL;
$selectmod = NULL;
$logslink = NULL;
$flag = false;
$menu = array();
$doneheading = false;
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$menu[] = '<ul class="navmenulist"><li class="jumpto section"><span>'.$strjumpto.'</span><ul>';
foreach ($modinfo as $mod) {
if ($mod->mod == 'label') {
foreach ($modinfo->cms as $mod) {
if ($mod->modname == 'label') {
continue;
}
@@ -5384,13 +5371,17 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
break;
}
if ($mod->section >= 0 and $section <> $mod->section) {
if (!$mod->uservisible) { // do not icnlude empty sections at all
continue;
}
if ($mod->section >= 0 and $section != $mod->section) {
$thissection = $sections[$mod->section];
if ($thissection->visible or !$course->hiddensections or
has_capability('moodle/course:viewhiddensections', $coursecontext)) {
$thissection->summary = strip_tags(format_string($thissection->summary,true));
if (!empty($doneheading)) {
if (!$doneheading) {
$menu[] = '</ul></li>';
}
if ($course->format == 'weeks' or empty($thissection->summary)) {
@@ -5405,33 +5396,29 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
$menu[] = '<li class="section"><span>'.$item.'</span>';
$menu[] = '<ul>';
$doneheading = true;
$section = $mod->section;
} else {
// no activities from this hidden section shown
continue;
}
}
$section = $mod->section;
//Only add visible or teacher mods to jumpmenu
if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->cm))) {
$url = $mod->mod .'/view.php?id='. $mod->cm;
if ($flag) { // the current mod is the "next" mod
$nextmod = $mod;
$flag = false;
}
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
if (strlen($mod->name) > ($width+5)) {
$mod->name = substr($mod->name, 0, $width).'...';
}
if (!$mod->visible) {
$mod->name = '('.$mod->name.')';
}
$class = 'activity '.$mod->mod;
$class .= ($cmid == $mod->cm) ? ' selected' : '';
$menu[] = '<li class="'.$class.'">'.
'<img src="'.$CFG->modpixpath.'/'.$mod->mod.'/icon.gif" alt="" />'.
'<a href="'.$CFG->wwwroot.'/mod/'.$url.'">'.$mod->name.'</a></li>';
$previousmod = $mod;
$url = $mod->modname .'/view.php?id='. $mod->id;
$mod->name = strip_tags(format_string(urldecode($mod->name),true));
if (strlen($mod->name) > ($width+5)) {
$mod->name = substr($mod->name, 0, $width).'...';
}
if (!$mod->visible) {
$mod->name = '('.$mod->name.')';
}
$class = 'activity '.$mod->modname;
$class .= ($cmid == $mod->cm) ? ' selected' : '';
$menu[] = '<li class="'.$class.'">'.
'<img src="'.$CFG->modpixpath.'/'.$mod->modname.'/icon.gif" alt="" />'.
'<a href="'.$CFG->wwwroot.'/mod/'.$url.'">'.$mod->name.'</a></li>';
}
if ($doneheading) {
$menu[] = '</ul></li>';
}
+27 -26
View File
@@ -29,7 +29,7 @@
print_header_simple($strassignments, "", $navigation, "", "", true, "", navmenu($course));
if (! $assignments = get_all_instances_in_course("assignment", $course)) {
if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'm.assignmenttype, m.timedue')) {
notice(get_string('noassignments', 'assignment'), "../../course/view.php?id=$course->id");
die;
}
@@ -51,41 +51,42 @@
$types = assignment_types();
foreach ($assignments as $assignment) {
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php')) {
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($assignment->coursemodule);
$submitted = $assignmentinstance->submittedlink();
$grading_info = grade_get_grades($course->id, 'mod', 'assignment', $assignment->id, $USER->id);
$grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
$type = $types[$assignment->assignmenttype];
$due = $assignment->timedue ? userdate($assignment->timedue) : '-';
if (!$assignment->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$assignment->coursemodule\">".format_string($assignment->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$assignment->coursemodule\">".format_string($assignment->name,true)."</a>";
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) {
continue;
}
require_once ($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$cm->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
$submitted = $assignmentinstance->submittedlink(true);
$grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
$grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
$type = $types[$cm->assignmenttype];
$due = $cm->timedue ? userdate($cm->timedue) : '-';
//Show dimmed if the mod is hidden
$class = $cm->visible ? '' : 'class="dimmed"';
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
$printsection = "";
if ($assignment->section !== $currentsection) {
if ($assignment->section) {
$printsection = $assignment->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $assignment->section;
$currentsection = $cm->section;
}
if ($course->format == "weeks" or $course->format == "topics") {
+287 -180
View File
@@ -41,6 +41,8 @@ class assignment_base {
* @param course object, usually null, but if we have it we pass it to save db access
*/
function assignment_base($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
global $COURSE;
if ($cmid == 'staticonly') {
//use static functions only!
return;
@@ -54,10 +56,12 @@ class assignment_base {
error('Course Module ID was incorrect');
}
$this->context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
if ($course) {
$this->course = $course;
} else if ($this->cm->course == $COURSE->id) {
$this->course = $COURSE;
} else if (! $this->course = get_record('course', 'id', $this->cm->course)) {
error('Course is misconfigured');
}
@@ -147,8 +151,8 @@ class assignment_base {
navmenu($this->course, $this->cm));
$groupmode = groups_get_activity_groupmode($this->cm);
$this->currentgroup = groups_get_activity_group($this->cm);
groups_print_activity_menu($this->cm, 'view.php?id=' . $this->cm->id);
$this->currentgroup = groups_get_activity_group($this->cm); // must be done after the printing!
echo '<div class="reportlink">'.$this->submittedlink().'</div>';
echo '<div class="clearer"></div>';
@@ -288,25 +292,28 @@ class assignment_base {
* For teachers it gives the number of submitted assignments with a link
* For students it gives the time of their submission.
* This will be suitable for most assignment types.
* @param bool $allgroup print all groups info if user can access all groups, suitable for index.php
* @return string
*/
function submittedlink() {
function submittedlink($allgroups=false) {
global $USER;
$submitted = '';
$context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
if (has_capability('mod/assignment:grade', $context)) {
// if this user can mark and is put in a group
// then he can only see/mark submission in his own groups
if (!has_capability('moodle/course:managegroups', $context) and (groups_get_activity_groupmode($this->cm) == SEPARATEGROUPS)) {
$count = $this->count_real_submissions($this->currentgroup); // Only their groups
if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
$group = 0;
} else {
$count = $this->count_real_submissions($this->currentgroup); // Everyone
$group = $this->currentgroup;
}
if ($count = $this->count_real_submissions($group)) {
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
get_string('viewsubmissions', 'assignment', $count).'</a>';
} else {
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
get_string('noattempts', 'assignment').'</a>';
}
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
get_string('viewsubmissions', 'assignment', $count).'</a>';
} else {
if (!empty($USER->id)) {
if ($submission = $this->get_submission($USER->id)) {
@@ -767,6 +774,7 @@ class assignment_base {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/tablelib.php');
$userid = required_param('userid', PARAM_INT);
$offset = required_param('offset', PARAM_INT);//offset for where to start looking for student.
@@ -796,30 +804,39 @@ class assignment_base {
/// Get all ppl that can submit assignments
$currentgroup = groups_get_activity_group($cm);
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
$users = array_keys($users);
}
$users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id, u.id', '', '', '', $currentgroup, '', false);
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
s.id AS submissionid, s.grade, s.submissioncomment,
s.timemodified, s.timemarked,
COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
$sql = 'FROM '.$CFG->prefix.'user u '.
'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid
AND s.assignment = '.$this->assignment->id.' '.
'WHERE u.id IN ('.implode(',', array_keys($users)).') ';
require_once($CFG->libdir.'/tablelib.php');
if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
$sort = 'ORDER BY '.$sort.' ';
// if groupmembersonly used, remove users who are not in any group
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
$nextid = 0;
if (($auser = get_records_sql($select.$sql.$sort, $offset+1, 1)) !== false) {
$nextuser = array_shift($auser);
/// Calculate user status
$nextuser->status = ($nextuser->timemarked > 0) && ($nextuser->timemarked >= $nextuser->timemodified);
$nextid = $nextuser->id;
if ($users) {
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
s.id AS submissionid, s.grade, s.submissioncomment,
s.timemodified, s.timemarked,
COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
$sql = 'FROM '.$CFG->prefix.'user u '.
'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid
AND s.assignment = '.$this->assignment->id.' '.
'WHERE u.id IN ('.implode(',', $users).') ';
if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
$sort = 'ORDER BY '.$sort.' ';
}
if (($auser = get_records_sql($select.$sql.$sort, $offset+1, 1)) !== false) {
$nextuser = array_shift($auser);
/// Calculate user status
$nextuser->status = ($nextuser->timemarked > 0) && ($nextuser->timemarked >= $nextuser->timemodified);
$nextid = $nextuser->id;
}
}
print_header(get_string('feedback', 'assignment').':'.fullname($user, true).':'.format_string($this->assignment->name));
@@ -1006,7 +1023,6 @@ class assignment_base {
$uses_outcomes = false;
}
$teacherattempts = true; /// Temporary measure
$page = optional_param('page', 0, PARAM_INT);
$strsaveallfeedback = get_string('saveallfeedback', 'assignment');
@@ -1030,20 +1046,23 @@ class assignment_base {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Check to see if groups are being used in this assignment
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
/// Get all ppl that are allowed to submit assignments
if ($users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false)) {
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
$users = array_keys($users);
}
if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
$groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
$users = array_intersect($users, array_keys($groupingusers));
// if groupmembersonly used, remove users who are not in any group
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
$tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
@@ -1101,20 +1120,8 @@ class assignment_base {
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
/// Check to see if groups are being used in this assignment
if (!$teacherattempts) {
$teachers = get_course_teachers($course->id);
if (!empty($teachers)) {
$keys = array_keys($teachers);
}
foreach ($keys as $key) {
unset($users[$key]);
}
}
if (empty($users)) {
print_heading(get_string('noattempts','assignment'));
print_heading(get_string('nosubmitusers','assignment'));
return true;
}
@@ -1503,7 +1510,7 @@ class assignment_base {
* @return int The number of submissions
*/
function count_real_submissions($groupid=0) {
return assignment_count_real_submissions($this->assignment, $groupid);
return assignment_count_real_submissions($this->cm, $groupid);
}
/**
@@ -1875,7 +1882,7 @@ class assignment_base {
}
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallsubmissions','assignment').': '.$typestr, 'error'=>false);
if (empty($data->reset_gradebook_grades)) {
// remove all grades from gradebook
assignment_reset_gradebook($data->courseid, $this->type);
@@ -2348,111 +2355,219 @@ function assignment_refresh_events($courseid = 0) {
*
* This is used by the recent activity block
*/
function assignment_print_recent_activity($course, $isteacher, $timestart) {
global $CFG;
function assignment_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $USER;
$content = false;
$assignments = array();
// do not use log table if possible, it may be huge
if (!$logs = get_records_select('log', 'time > \''.$timestart.'\' AND '.
'course = \''.$course->id.'\' AND '.
'module = \'assignment\' AND '.
'action = \'upload\' ', 'time ASC')) {
if (!$submissions = get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}assignment_submissions asb
JOIN {$CFG->prefix}assignment a ON a.id = asb.assignment
JOIN {$CFG->prefix}course_modules cm ON cm.instance = a.id
JOIN {$CFG->prefix}modules md ON md.id = cm.module
JOIN {$CFG->prefix}user u ON u.id = asb.userid
WHERE asb.timemodified > $timestart AND
a.course = {$course->id} AND
md.name = 'assignment'
ORDER BY asb.timemodified ASC")) {
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 sumitting of assignemnt 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, $cm->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$show[] = $submission;
}
if (empty($show)) {
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);
print_headline(get_string('newsubmissions', 'assignment').':');
//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('&', '&amp;', $log->url);
}
}
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);
}
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;
return true;
}
/**
* Returns all assignments since a given time.
*
* If assignment is specified then this restricts the results
* Returns all assignments since a given time in specified forum.
*/
function assignment_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $assignment="0", $user="", $groupid="") {
function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $CFG;
global $CFG, $COURSE, $USER;
if ($assignment) {
$assignmentselect = " AND cm.id = '$assignment'";
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$assignmentselect = "";
$course = get_record('course', 'id', $courseid);
}
if ($user) {
$userselect = " AND u.id = '$user'";
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
if ($userid) {
$userselect = "AND u.id = $userid";
} else {
$userselect = "";
}
$assignments = get_records_sql("SELECT asub.*, u.firstname, u.lastname, u.picture, u.id as userid,
a.grade as maxgrade, name, cm.instance, cm.section, a.assignmenttype
FROM {$CFG->prefix}assignment_submissions asub,
{$CFG->prefix}user u,
{$CFG->prefix}assignment a,
{$CFG->prefix}course_modules cm
WHERE asub.timemodified > '$sincetime'
AND asub.userid = u.id $userselect
AND a.id = asub.assignment $assignmentselect
AND cm.course = '$courseid'
AND cm.instance = a.id
ORDER BY asub.timemodified ASC");
if ($groupid) {
$groupselect = "AND gm.groupid = $groupid";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
} else {
$groupselect = "";
$groupjoin = "";
}
if (empty($assignments))
return;
if (!$submissions = get_records_sql("SELECT asb.id, asb.timemodified, asb.userid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}assignment_submissions asb
JOIN {$CFG->prefix}assignment a ON a.id = asb.assignment
JOIN {$CFG->prefix}user u ON u.id = asb.userid
$groupjoin
WHERE asb.timemodified > $timestart AND a.id = $cm->instance
$userselect $groupselect
ORDER BY asb.timemodified ASC")) {
return;
}
foreach ($assignments as $assignment) {
if (empty($groupid) || groups_is_member($groupid, $assignment->userid)) {
$groupmode = groups_get_activity_groupmode($cm, $course);
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$grader = has_capability('moodle/grade:viewall', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
$tmpactivity = new Object;
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$tmpactivity->type = "assignment";
$tmpactivity->defaultindex = $index;
$tmpactivity->instance = $assignment->instance;
$tmpactivity->name = $assignment->name;
$tmpactivity->section = $assignment->section;
$show = array();
$tmpactivity->content->grade = $assignment->grade;
$tmpactivity->content->maxgrade = $assignment->maxgrade;
$tmpactivity->content->type = $assignment->assignmenttype;
$tmpactivity->user->userid = $assignment->userid;
$tmpactivity->user->fullname = fullname($assignment);
$tmpactivity->user->picture = $assignment->picture;
$tmpactivity->timestamp = $assignment->timemodified;
$activities[] = $tmpactivity;
$index++;
foreach($submissions as $submission) {
if ($submission->userid == $USER->id) {
$show[] = $submission;
continue;
}
// the act of sumitting of assignemnt may be considered private - only graders will see it if specified
if (!empty($CFG->assignment_limitrecentsubmissions)) {
if (!$grader) {
continue;
}
}
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
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 (empty($modinfo->groups[$cm->id])) {
continue;
}
$usersgroups = groups_get_all_groups($course->id, $cm->userid, $cm->groupingid);
if (is_array($usersgroups)) {
$usersgroups = array_keys($usersgroups);
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$show[] = $submission;
}
if (empty($show)) {
return;
}
if ($grader) {
require_once($CFG->libdir.'/gradelib.php');
$userids = array();
foreach ($show as $id=>$submission) {
$userids[] = $submission->userid;
}
$grades = grade_get_grades($courseid, 'mod', 'assignment', $cm->instance, $userids);
}
$aname = format_string($cm->name,true);
foreach ($show as $submission) {
$tmpactivity = new object();
$tmpactivity->type = 'assignment';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->timestamp = $submission->timemodified;
if ($grader) {
$tmpactivity->grade = $grades->items[0]->grades[$submission->userid]->str_long_grade;
}
$tmpactivity->user->userid = $submission->userid;
$tmpactivity->user->fullname = fullname($submission, $viewfullnames);
$tmpactivity->user->picture = $submission->picture;
$activities[$index++] = $tmpactivity;
}
return;
@@ -2463,41 +2578,37 @@ function assignment_get_recent_mod_activity(&$activities, &$index, $sincetime, $
*
* This is used by course/recent.php
*/
function assignment_print_recent_mod_activity($activity, $course, $detail=false) {
function assignment_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
global $CFG;
echo '<table border="0" cellpadding="3" cellspacing="0">';
echo '<table border="0" cellpadding="3" cellspacing="0" class="assignment-recent">';
echo "<tr><td class=\"userpicture\" valign=\"top\">";
print_user_picture($activity->user->userid, $course, $activity->user->picture);
echo "</td><td width=\"100%\"><font size=2>";
print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
echo "</td><td>";
if ($detail) {
echo "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
"class=\"icon\" alt=\"$activity->type\"> ";
echo "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id=" . $activity->instance . "\">"
. format_string($activity->name,true) . "</a> - ";
$modname = $modnames[$activity->type];
echo '<div class="title">';
echo "<img src=\"$CFG->modpixpath/assignment/icon.gif\" ".
"class=\"icon\" alt=\"$modname\">";
echo "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id={$activity->cmid}\">{$activity->name}</a>";
echo '</div>';
}
if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_COURSE, $course))) {
$grades = "(" . $activity->content->grade . " / " . $activity->content->maxgrade . ") ";
$assignment->id = $activity->instance;
$assignment->course = $course;
$user->id = $activity->user->userid;
echo $grades;
echo "<br />";
if (isset($activity->grade)) {
echo '<div class="grade">';
echo get_string('grade').': ';
echo $activity->grade;
echo '</div>';
}
echo "<a href=\"$CFG->wwwroot/user/view.php?id="
. $activity->user->userid . "&amp;course=$course\">"
. $activity->user->fullname . "</a> ";
echo " - " . userdate($activity->timestamp);
echo '<div class="user">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->userid}&amp;course=$courseid\">"
."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
echo '</div>';
echo "</font></td></tr>";
echo "</table>";
echo "</td></tr></table>";
}
/// GENERIC SQL FUNCTIONS
@@ -2555,38 +2666,34 @@ function assignment_get_unmailed_submissions($starttime, $endtime) {
* @param $groupid int optional If nonzero then count is restricted to this group
* @return int The number of submissions
*/
function assignment_count_real_submissions($assignment, $groupid=0) {
function assignment_count_real_submissions($cm, $groupid=0) {
global $CFG;
if ($groupid) { /// How many in a particular group?
return count_records_sql("SELECT COUNT(DISTINCT g.userid, g.groupid)
FROM {$CFG->prefix}assignment_submissions a,
{$CFG->prefix}groups_members g
WHERE a.assignment = $assignment->id
AND a.timemodified > 0
AND g.groupid = '$groupid'
AND a.userid = g.userid ");
} else {
$cm = get_coursemodule_from_instance('assignment', $assignment->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// this is all the users with this capability set, in this context or higher
if ($users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', 0, '', false)) {
foreach ($users as $user) {
$array[] = $user->id;
}
// this is all the users with this capability set, in this context or higher
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $groupid, '', false)) {
$users = array_keys($users);
}
$userlists = '('.implode(',',$array).')';
return count_records_sql("SELECT COUNT(*)
FROM {$CFG->prefix}assignment_submissions
WHERE assignment = '$assignment->id'
AND timemodified > 0
AND userid IN $userlists ");
} else {
return 0; // no users enroled in course
// if groupmembersonly used, remove users who are not in any group
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
if (empty($users)) {
return 0;
}
$userlists = implode(',', $users);
return count_records_sql("SELECT COUNT('x')
FROM {$CFG->prefix}assignment_submissions
WHERE assignment = $cm->instance AND
timemodified > 0 AND
userid IN ($userlists)");
}
+3
View File
@@ -10,4 +10,7 @@ $options = array(ASSIGNMENT_COUNT_WORDS => trim(get_string('numwords', '')),
$settings->add(new admin_setting_configselect('assignment_itemstocount', get_string('itemstocount', 'assignment'),
get_string('configitemstocount', 'assignment'), ASSIGNMENT_COUNT_WORDS, $options));
$settings->add(new admin_setting_configcheckbox('assignment_showrecentsubmissions', get_string('showrecentsubmissions', 'assignment'),
get_string('configshowrecentsubmissions', 'assignment'), 1));
?>
+12 -12
View File
@@ -30,7 +30,7 @@
/// Get all the appropriate data
if (! $chats = get_all_instances_in_course('chat', $course)) {
if (!$cms = get_coursemodules_in_course('chat', $course->id)) {
notice(get_string('thereareno', 'moodle', $strchats), "../../course/view.php?id=$course->id");
die();
}
@@ -54,23 +54,23 @@
}
$currentsection = '';
foreach ($chats as $chat) {
if (!$chat->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$chat->coursemodule\">".format_string($chat->name,true)."</a>";
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$class = $cm->visible ? '' : 'class="dimmed"';
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
$printsection = '';
if ($chat->section !== $currentsection) {
if ($chat->section) {
$printsection = $chat->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $chat->section;
$currentsection = $cm->section;
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array ($printsection, $link);
+119 -40
View File
@@ -133,60 +133,139 @@ function chat_user_complete($course, $user, $mod, $chat) {
return true;
}
function chat_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a date, prints a summary of all chat rooms
/// that currently have people in them.
function chat_print_recent_activity($course, $viewfullnames, $timestart) {
/// Given a course and a date, prints a summary of all chat rooms past and present
/// This function is called from course/lib.php: print_recent_activity()
global $CFG;
global $CFG, $USER;
$timeold = time() - $CFG->chat_old_ping;
// this is approximate only, but it is really fast ;-)
$timeout = $CFG->chat_old_ping * 10;
$lastpingsearch = ($CFG->chat_method == 'sockets') ? '': 'AND cu.lastping > \''.$timeold.'\'';
if (!$cms = get_records_sql("SELECT cm.*, ch.name, 'chat' AS modname, MAX(chm.timestamp) AS lasttime
FROM {$CFG->prefix}course_modules cm
JOIN {$CFG->prefix}modules md ON md.id = cm.module
JOIN {$CFG->prefix}chat ch ON ch.id = cm.instance
JOIN {$CFG->prefix}chat_messages chm ON chm.chatid = ch.id
WHERE chm.timestamp > $timestart AND ch.course = {$course->id} AND md.name = 'chat'
GROUP BY cm.id
ORDER BY chm.timestamp ASC")) {
return false;
}
if (!$chatusers = get_records_sql("SELECT u.id, cu.chatid, u.firstname, u.lastname
FROM {$CFG->prefix}chat_users cu,
{$CFG->prefix}chat ch,
{$CFG->prefix}user u
WHERE cu.userid = u.id
AND cu.chatid = ch.id $lastpingsearch
AND ch.course = '$course->id'
ORDER BY cu.chatid ASC") ) {
$past = array();
$current = array();
$modinfo =& get_fast_modinfo($course); // reference needed because we might load the groups
foreach ($cms as $cm) {
if (!array_key_exists($cm->id, $modinfo->cms)) {
continue;
}
if (!$modinfo->cms[$cm->id]->uservisible) {
continue;
}
if (groups_get_activity_groupmode($cm) != SEPARATEGROUPS
or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
if ($timeout > time() - $cm->lasttime) {
$current[] = $cm;
} else {
$past[] = $cm;
}
continue;
}
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
// verify groups in separate mode
if (!$mygroupids = $modinfo->groups[$cm->groupingid]) {
continue;
}
// ok, last post was not for my group - we have to query db to get last message from one of my groups
// only minor problem is that the order will not be correct
$mygroupids = implode(',', $mygroupids);
$cm->mygroupids = $mygroupids;
if (!$cm = get_record_sql("SELECT cm.*, ch.name, 'chat' AS modname, MAX(chm.timestamp) AS lasttime
FROM {$CFG->prefix}course_modules cm
JOIN {$CFG->prefix}chat ch ON ch.id = cm.instance
JOIN {$CFG->prefix}chat_messages chm ON chm.chatid = ch.id
WHERE chm.timestamp > $timestart AND cm.id = {$cm->id} AND
(chm.groupid IN ($mygroupids) OR chm.groupid = 0)
GROUP BY cm.id")) {
continue;
}
if ($timeout > time() - $cm->lasttime) {
$current[] = $cm;
} else {
$past[] = $cm;
}
}
if (!$past and !$current) {
return false;
}
$outputstarted = false;
$current = 0;
foreach ($chatusers as $chatuser) {
if ($current != $chatuser->chatid) {
if ($current) {
echo '</ul></div>'; // room
$current = 0;
}
if ($chat = get_record('chat', 'id', $chatuser->chatid)) {
$strftimerecent = get_string('strftimerecent');
// we find the course module id
$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($past) {
print_headline(get_string('pastchats', 'chat').':');
// needs to be fixed
if (!(has_capability('mod/chat:readlog', $context) or instance_is_visible('chat', $chat))) { // Chat hidden to students
continue;
}
if (!$outputstarted) {
print_headline(get_string('currentchats', 'chat').':');
$outputstarted = true;
}
echo '<div class="room"><p class="head"><a href="'.$CFG->wwwroot.'/mod/chat/view.php?c='.$chat->id.'">'.format_string($chat->name,true).'</a></p><ul>';
}
$current = $chatuser->chatid;
foreach ($past as $cm) {
$link = $CFG->wwwroot.'/mod/chat/view.php?id='.$cm->id;
$date = userdate($cm->lasttime, $strftimerecent);
echo '<div class="head"><div class="date">'.$date.'</div></div>';
echo '<div class="info"><a href="'.$link.'">'.format_string($cm->name,true).'</a></div>';
}
$fullname = fullname($chatuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
echo '<li class="info name">'.$fullname.'</li>';
}
if ($current) {
echo '</ul></div>'; // room
print_headline(get_string('currentchats', 'chat').':');
$oldest = floor((time()-$CFG->chat_old_ping)/10)*10; // better db caching
$timeold = time() - $CFG->chat_old_ping;
$timeold = floor($timeold/10)*10; // better db caching
$timeoldext = time() - ($CFG->chat_old_ping*10); // JSless gui_basic needs much longer timeouts
$timeoldext = floor($timeoldext/10)*10; // better db caching
$timeout = "AND (chu.version<>'basic' AND chu.lastping<$timeold) OR (chu.version='basic' AND chu.lastping<$timeoldext)";
foreach ($current as $cm) {
//count users first
if (isset($cm->mygroupids)) {
$groupselect = "AND (chu.groupid IN ({$cm->mygroupids}) OR chu.groupid = 0)";
} else {
$groupselect = "";
}
if (!$users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}course_modules cm
JOIN {$CFG->prefix}chat ch ON ch.id = cm.instance
JOIN {$CFG->prefix}chat_users chu ON chu.chatid = ch.id
JOIN {$CFG->prefix}user u ON u.id = chu.userid
WHERE cm.id = {$cm->id} $timeout $groupselect
GROUP BY u.id")) {
}
$link = $CFG->wwwroot.'/mod/chat/view.php?id='.$cm->id;
$date = userdate($cm->lasttime, $strftimerecent);
echo '<div class="head"><div class="date">'.$date.'</div></div>';
echo '<div class="info"><a href="'.$link.'">'.format_string($cm->name,true).'</a></div>';
echo '<div class="userlist">';
if ($users) {
echo '<ul>';
foreach ($users as $user) {
echo '<li>'.fullname($user, $viewfullnames).'</li>';
}
echo '</ul>';
}
echo '</div>';
}
}
return true;
+19 -20
View File
@@ -22,11 +22,11 @@
print_header_simple("$strchoices", "", $navigation, "", "", true, "", navmenu($course));
if (! $choices = get_all_instances_in_course("choice", $course)) {
if (!$cms = get_coursemodules_in_course('choice', $course->id)) {
notice(get_string('thereareno', 'moodle', $strchoices), "../../course/view.php?id=$course->id");
}
if ( !empty($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) {
if ( !empty($USER->id) and $allanswers = get_records("choice_answers", "userid", $USER->id)) { // TODO: limit to choices from this course only
foreach ($allanswers as $aa) {
$answers[$aa->choiceid] = $aa;
}
@@ -51,36 +51,35 @@
$currentsection = "";
foreach ($choices as $choice) {
if (!empty($answers[$choice->id])) {
$answer = $answers[$choice->id];
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
if (!empty($answers[$cm->instance])) {
$answer = $answers[$cm->instance];
} else {
$answer = "";
}
if (!empty($answer->optionid)) {
$aa = format_string(choice_get_option_text($choice, $answer->optionid));
$aa = format_string(choice_get_option_text(null, $answer->optionid));
} else {
$aa = "";
}
$printsection = "";
if ($choice->section !== $currentsection) {
if ($choice->section) {
$printsection = $choice->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $choice->section;
}
//Calculate the href
if (!$choice->visible) {
//Show dimmed if the mod is hidden
$tt_href = "<a class=\"dimmed\" href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
} else {
//Show normal if the mod is visible
$tt_href = "<a href=\"view.php?id=$choice->coursemodule\">".format_string($choice->name,true)."</a>";
$currentsection = $cm->section;
}
$class = $cm->visible ? '' : 'class="dimmed"';
$tt_href = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
if ($course->format == "weeks" || $course->format == "topics") {
$table->data[] = array ($printsection, $tt_href, $aa);
} else {
@@ -91,5 +90,5 @@
print_table($table);
print_footer($course);
?>
+22 -23
View File
@@ -42,14 +42,14 @@
$strname = get_string('name');
$strdata = get_string('modulename','data');
$strdataplural = get_string('modulenameplural','data');
$navlinks = array();
$navlinks[] = array('name' => $strdata, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navlinks[] = array('name' => $strdata, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header_simple($strdata, '', $navigation, '', '', true, "", navmenu($course));
if (! $datas = get_all_instances_in_course("data", $course)) {
if (!$cms = get_coursemodules_in_course('data', $course->id, 'm.intro, m.approval, m.rssarticles')) {
notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
}
@@ -82,49 +82,48 @@
$currentsection = "";
foreach ($datas as $data) {
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$printsection = "";
//Calculate the href
if (!$data->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
}
$class = $cm->visible ? '' : 'class="dimmed"';
$link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name,true)."</a>";
// TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
$numrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
'data_records r WHERE r.dataid ='.$data->id);
'data_records r WHERE r.dataid ='.$cm->instance);
if ($data->approval == 1) {
if ($cm->approval == 1) {
$numunapprovedrecords = count_records_sql('SELECT COUNT(r.id) FROM '.$CFG->prefix.
'data_records r WHERE r.dataid ='.$data->id.
'data_records r WHERE r.dataid ='.$cm->instance.
' AND r.approved <> 1');
} else {
$numunapprovedrecords = '-';
}
$rsslink = '';
if ($rss && $data->rssarticles > 0) {
$rsslink = rss_get_link($course->id, $USER->id, 'data', $data->id, 'RSS');
if ($rss && $cm->rssarticles > 0) {
$rsslink = rss_get_link($course->id, $USER->id, 'data', $cm->instance, 'RSS');
}
if ($course->format == 'weeks' or $course->format == 'topics') {
if ($data->section !== $currentsection) {
if ($data->section) {
$printsection = $data->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $data->section;
$currentsection = $cm->section;
}
$row = array ($printsection, $link, $data->intro, $numrecords, $numunapprovedrecords);
$row = array ($printsection, $link, $cm->intro, $numrecords, $numunapprovedrecords);
} else {
$row = array ($link, $data->intro, $numrecords, $numunapprovedrecords);
$row = array ($link, $cm->intro, $numrecords, $numunapprovedrecords);
}
if ($rss) {
-15
View File
@@ -895,21 +895,6 @@ function data_get_participants($dataid) {
return $participants;
}
function data_get_coursemodule_info($coursemodule) {
/// Given a course_module object, this function returns any
/// "extra" information that may be needed when printing
/// this activity in a course listing.
///
/// See get_array_of_activities() in course/lib.php
///
global $CFG;
$info = NULL;
return $info;
}
///junk functions
/************************************************************************
* takes a list of records, the current data, a search string, *
+29 -59
View File
@@ -326,37 +326,23 @@ function exercise_grades($exerciseid) {
/*******************************************************************/
function exercise_print_recent_activity($course, $isteacher, $timestart) {
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)) {
// 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->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible('exercise',$tempmod)) {
$submitcontent = true;
break;
}
}
// if we got some 'live' ones then output them
if ($submitcontent) {
print_headline(get_string('exercisesubmissions', 'exercise').':');
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible('exercise',$tempmod)) {
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&amp;', $log->url));
}
}
$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('&', '&amp;', $log->url));
}
}
}
@@ -365,28 +351,20 @@ function exercise_print_recent_activity($course, $isteacher, $timestart) {
$gradecontent = false;
if ($logs = exercise_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->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible("exercise",$tempmod)) {
$gradecontent = true;
break;
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 ($gradecontent) {
if ($logs) {
$gradecontent = true;
print_headline(get_string('exercisefeedback', 'exercise').':');
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible('exercise',$tempmod)) {
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&amp;', $log->url));
}
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&amp;', $log->url));
}
}
}
@@ -396,28 +374,20 @@ function exercise_print_recent_activity($course, $isteacher, $timestart) {
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 $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible("exercise",$tempmod)) {
$assesscontent = true;
break;
}
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 ($assesscontent) {
if ($logs) {
$assesscontent = true;
print_headline(get_string('exerciseassessments', 'exercise').':');
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->exerciseid;
//Obtain the visible property from the instance
if (instance_is_visible('exercise',$tempmod)) {
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&amp;', $log->url));
}
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&amp;', $log->url));
}
}
}
+14 -19
View File
@@ -80,7 +80,7 @@
$generalforums = array(); // For now
$learningforums = get_all_instances_in_course("forum", $course);
if ($forums = get_records("forum", "course", $id, "name ASC")) { // All known forums
if ($learningforums) { // Copy "full" data into this complete array
@@ -91,7 +91,7 @@
}
foreach ($forums as $forum) {
$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -101,15 +101,13 @@
}
continue;
}
if (!isset($forum->visible)) {
$forum->visible = instance_is_visible("forum", $forum);
if (!$forum->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
if (isset($forum->keyreference)) {
unset($learningforums[$forum->keyreference]);
}
continue;
if (!coursemodule_visible_for_user($cm)) {
if (isset($forum->keyreference)) {
unset($learningforums[$forum->keyreference]);
}
continue;
}
switch ($forum->type) {
case "news":
case "social":
@@ -159,10 +157,10 @@
if ($generalforums) {
foreach ($generalforums as $forum) {
$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!groups_course_module_visible($cm)) {
continue;
}
@@ -296,19 +294,16 @@
if ($learningforums) {
$currentsection = "";
foreach ($learningforums as $key => $forum) {
$forum->visible = instance_is_visible("forum", $forum)
|| has_capability('moodle/course:view', $coursecontext);
$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!groups_course_module_visible($cm)) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
$cantaccessagroup = $groupmode && !has_capability('moodle/site:accessallgroups', $context) && !mygroupid($course->id);
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
+206 -154
View File
@@ -1002,90 +1002,102 @@ function forum_print_overview($courses,&$htmlarray) {
* Given a course and a date, prints a summary of all the new
* messages posted in the course since that date
*/
function forum_print_recent_activity($course, $isteacher, $timestart) {
function forum_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $USER;
global $CFG;
$LIKE = sql_ilike();
// do not use log table if possible, it may be huge and is expensive to join with other tables
$heading = false;
$content = false;
if (!$logs = get_records_select('log', 'time > \''.$timestart.'\' AND '.
'course = \''.$course->id.'\' AND '.
'module = \'forum\' AND '.
'action '.$LIKE.' \'add %\' ', 'time ASC')){
return false;
if (!$posts = get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
d.timestart, d.timeend, d.userid AS duserid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_posts p
JOIN {$CFG->prefix}forum_discussions d ON d.id = p.discussion
JOIN {$CFG->prefix}forum f ON f.id = d.forum
JOIN {$CFG->prefix}user u ON u.id = p.userid
WHERE p.created > $timestart AND f.course = {$course->id}
ORDER BY p.id ASC")) { // order by initial posting date
return false;
}
$modinfo =& get_fast_modinfo($course);
$groupmodes = array();
$cms = array();
$strftimerecent = get_string('strftimerecent');
$mygroupid = mygroupid($course->id);
$groupmode = array(); // To cache group modes
$count = 0;
foreach ($logs as $log) {
//Get post info, I'll need it later
if ($post = forum_get_post_from_log($log)) {
//Create a temp valid module structure (course,id)
$tempmod = new object;
$tempmod->course = $log->course;
$tempmod->id = $post->forum;
//Obtain the visible property from the instance
$coursecontext = get_context_instance(CONTEXT_COURSE, $tempmod->course);
$modvisible = instance_is_visible('forum', $tempmod)
|| has_capability('moodle/course:viewhiddenactivities', $coursecontext);
$printposts = array();
foreach ($posts as $post) {
if (!isset($modinfo->instances['forum'][$post->forum])) {
// not visible
continue;
}
$cm = $modinfo->instances['forum'][$post->forum];
if (!$cm->uservisible) {
continue;
}
//Only if the post exists and mod is visible
if ($post && $modvisible) {
if (!isset($cm[$post->forum])) {
$cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id);
if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid
and (($post->timestart > 0 and $post->timestart > time()) or ($post->timeend > 0 and $post->timeend < time()))) {
if (!has_capability('mod/forum:viewhiddentimedposts', get_context_instance(CONTEXT_MODULE, $cm->id))) {
continue;
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm[$post->forum]->id);
}
// Check whether this is belongs to a discussion in a group that
// should NOT be accessible to the current user
if (!has_capability('moodle/site:accessallgroups', $modcontext)
&& $post->groupid != -1) { // Open discussions have groupid -1
$groupmode = groups_get_activity_groupmode($cm, $course);
$groupmode[$post->forum] = groups_get_activity_groupmode($cm[$post->forum]);
if ($groupmode) {
if ($post->groupid == -1 or $groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cms[$post->forum]->id))) {
// oki (Open discussions have groupid -1)
} else {
// separate mode
if (isguestuser()) {
// shortcut
continue;
}
if ($groupmode[$post->forum]) {
//hope i didn't break anything
if (!@in_array($mygroupid, $post->groupid))/*$mygroupid != $post->groupid*/{
continue;
}
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
if (!array_key_exists($post->groupid, $modinfo->groups[0])) {
continue;
}
}
if (! $heading) {
print_headline(get_string('newforumposts', 'forum').':', 3);
$heading = true;
$content = true;
}
$date = userdate($post->modified, $strftimerecent);
$subjectclass = ($log->action == 'add discussion') ? ' bold' : '';
//Accessibility: markup as a list.
if ($count < 1) {
echo "\n<ul class='unlist'>\n";
}
$count++;
echo '<li><div class="head">'.
'<div class="date">'.$date.'</div>'.
'<div class="name">'.fullname($post, has_capability('moodle/site:viewfullnames', $coursecontext)).'</div>'.
'</div>';
echo '<div class="info'.$subjectclass.'">';
echo '"<a href="'.$CFG->wwwroot.'/mod/forum/'.str_replace('&', '&amp;', $log->url).'">';
$post->subject = break_up_long_words(format_string($post->subject,true));
echo $post->subject;
echo "</a>\"</div></li>\n";
}
$printposts[] = $post;
}
unset($posts);
if (!$printposts) {
return false;
}
print_headline(get_string('newforumposts', 'forum').':', 3);
echo "\n<ul class='unlist'>\n";
foreach ($printposts as $post) {
$subjectclass = empty($post->parent) ? ' bold' : '';
echo '<li><div class="head">'.
'<div class="date">'.userdate($post->modified, $strftimerecent).'</div>'.
'<div class="name">'.fullname($post, $viewfullnames).'</div>'.
'</div>';
echo '<div class="info'.$subjectclass.'">';
if (empty($post->parent)) {
echo '"<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
} else {
echo '"<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'&amp;parent='.$post->parent.'#p'.$post->id.'">';
}
$post->subject = break_up_long_words(format_string($post->subject, true));
echo $post->subject;
echo "</a>\"</div></li>\n";
}
echo "</ul>\n";
return $content;
return true;
}
/**
@@ -1492,8 +1504,12 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5
if (is_array($forums[$i]->onlydiscussions)) {
// Show question posts as well as posts from discussions in
// which the user has posted a reply.
$onlydiscussions = implode(' OR d.id = ', $forums[$i]->onlydiscussions);
$selectdiscussion .= " AND ((d.id = $onlydiscussions) OR p.parent = 0)";
if (!empty($forums[$i]->onlydiscussions)) {
$onlydiscussions = "(d.id = ".implode(' OR d.id = ', $forums[$i]->onlydiscussions).") OR";
} else {
$onlydiscussions = "";
}
$selectdiscussion .= " AND ($onlydiscussions p.parent = 0)";
} else {
// Show only the question posts.
$selectdiscussion .= ' AND (p.parent = 0)';
@@ -3023,8 +3039,19 @@ function forum_update_post($post,&$message) {
$post->modified = time();
if (!$post->parent) { // Post is a discussion starter - update discussion title too
set_field("forum_discussions", "name", $post->subject, "id", $post->discussion);
$updatediscussion = new object();
$updatediscussion->id = $post->discussion;
$updatediscussion->timemodified = $post->modified; // last modified tracking
$updatediscussion->usermodified = $post->userid; // last modified tracking
if (!$post->parent) { // Post is a discussion starter - update discussion title and times too
$updatediscussion->name = $post->subject;
$updatediscussion->timestart = $post->timestart;
$updatediscussion->timeend = $post->timeend;
}
if (!update_record('forum_discussions', $updatediscussion)) {
return false;
}
if ($newfilename = forum_add_attachment($post, 'attachment',$message)) {
@@ -3033,15 +3060,11 @@ function forum_update_post($post,&$message) {
unset($post->attachment);
}
// Update discussion modified date
set_field("forum_discussions", "timemodified", $post->modified, "id", $post->discussion);
set_field("forum_discussions", "usermodified", $post->userid, "id", $post->discussion);
if (forum_tp_can_track_forums($post->forum) && forum_tp_is_tracked($post->forum)) {
forum_tp_mark_post_read($post->userid, $post, $post->forum);
}
return update_record("forum_posts", $post);
return update_record('forum_posts', $post);
}
/**
@@ -4119,81 +4142,113 @@ function forum_print_posts_nested($parent, $courseid, $ratings, $reply, &$user_r
}
/**
* TODO document
* Returns all forum posts since a given time in specified forum.
*/
function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid="0", $user="", $groupid="") {
// Returns all forum posts since a given time. If forum is specified then
// this restricts the results
function forum_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $CFG, $COURSE, $USER;
global $CFG;
if ($cmid) {
$forumselect = " AND cm.id = '$cmid'";
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$forumselect = "";
$course = get_record('course', 'id', $courseid);
}
if ($user) {
$userselect = " AND u.id = '$user'";
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
if ($userid) {
$userselect = "AND u.id = $userid";
} else {
$userselect = "";
}
$posts = get_records_sql("SELECT p.*, d.name, u.firstname, u.lastname,
u.picture, d.groupid, cm.instance, f.name,
cm.section, cm.id AS cmid
FROM {$CFG->prefix}forum_posts p,
{$CFG->prefix}forum_discussions d,
{$CFG->prefix}user u,
{$CFG->prefix}course_modules cm,
{$CFG->prefix}forum f
WHERE p.modified > '$sincetime' $forumselect
AND p.userid = u.id $userselect
AND d.course = '$courseid'
AND p.discussion = d.id
AND cm.instance = f.id
AND cm.course = d.course
AND cm.course = f.course
AND f.id = d.forum
ORDER BY p.discussion ASC,p.created ASC");
if ($groupid) {
$groupselect = "AND gm.groupid = $groupid";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
} else {
$groupselect = "";
$groupjoin = "";
}
if (empty($posts)) {
if (!$posts = get_records_sql("SELECT p.*, f.type AS forumtype, d.forum, d.groupid,
d.timestart, d.timeend, d.userid AS duserid,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}forum_posts p
JOIN {$CFG->prefix}forum_discussions d ON d.id = p.discussion
JOIN {$CFG->prefix}forum f ON f.id = d.forum
JOIN {$CFG->prefix}user u ON u.id = p.userid
$groupjoin
WHERE p.created > $timestart AND f.id = $cm->instance
$userselect $groupselect
ORDER BY p.id ASC")) { // order by initial posting date
return;
}
$groupmode = groups_get_activity_groupmode($cm, $course);
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewhiddentimed = has_capability('mod/forum:viewhiddentimedposts', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$printposts = array();
foreach ($posts as $post) {
if (!empty($CFG->forum_enabletimedposts) and $USER->id != $post->duserid
and (($post->timestart > 0 and $post->timestart > time()) or ($post->timeend > 0 and $post->timeend < time()))) {
if (!$viewhiddentimed) {
continue;
}
}
if ($groupmode) {
if ($post->groupid == -1 or $groupmode == VISIBLEGROUPS or $accessallgroups) {
// oki (Open discussions have groupid -1)
} else {
// separate mode
if (isguestuser()) {
// shortcut
continue;
}
if (!array_key_exists($post->groupid, $modinfo->groups[0])) {
continue;
}
}
}
$printposts[] = $post;
}
if (!$printposts) {
return;
}
foreach ($posts as $post) {
$aname = format_string($cm->name,true);
$modcontext = get_context_instance(CONTEXT_MODULE, $post->cmid);
$canviewallgroups = has_capability('moodle/site:accessallgroups', $modcontext);
foreach ($printposts as $post) {
$tmpactivity = new object();
if ($groupid and ($post->groupid != -1 and $groupid != $post->groupid and !$canviewallgroups)) {
continue;
}
if (!groups_course_module_visible($post->cmid)) {
continue;
}
$tmpactivity->type = 'forum';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->timestamp = $post->modified;
$tmpactivity = new Object;
$tmpactivity->type = "forum";
$tmpactivity->defaultindex = $index;
$tmpactivity->instance = $post->instance;
$tmpactivity->name = $post->name;
$tmpactivity->section = $post->section;
$tmpactivity->content->id = $post->id;
$tmpactivity->content->id = $post->id;
$tmpactivity->content->discussion = $post->discussion;
$tmpactivity->content->subject = $post->subject;
$tmpactivity->content->parent = $post->parent;
$tmpactivity->content->subject = format_string($post->subject);
$tmpactivity->content->parent = $post->parent;
$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post, $viewfullnames);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->timestamp = $post->modified;
$activities[] = $tmpactivity;
$index++;
$activities[$index++] = $tmpactivity;
}
return;
@@ -4202,39 +4257,36 @@ function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $cours
/**
*
*/
function forum_print_recent_mod_activity($activity, $course, $detail=false) {
function forum_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
global $CFG;
echo '<table border="0" cellpadding="3" cellspacing="0">';
if ($activity->content->parent) {
$openformat = "<font size=\"2\"><i>";
$closeformat = "</i></font>";
$class = 'reply';
} else {
$openformat = "<b>";
$closeformat = "</b>";
$class = 'discussion';
}
echo "<tr><td class=\"forumpostpicture\" width=\"35\" valign=\"top\">";
print_user_picture($activity->user->userid, $course, $activity->user->picture);
echo "</td><td>$openformat";
echo '<table border="0" cellpadding="3" cellspacing="0" class="forum-recent">';
echo "<tr><td class=\"userpicture\" valign=\"top\">";
print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
echo "</td><td class=\"$class\">";
echo '<div class="title">';
if ($detail) {
$aname = s($activity->name);
echo "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
"class=\"icon\" alt=\"".strip_tags(format_string($activity->name,true))."\" /> ";
"class=\"icon\" alt=\"{$aname}\" />";
}
echo "<a href=\"$CFG->wwwroot/mod/forum/discuss.php?d=" . $activity->content->discussion
. "#p" . $activity->content->id . "\">";
echo "<a href=\"$CFG->wwwroot/mod/forum/discuss.php?d={$activity->content->discussion}"
."#p{$activity->content->id}\">{$activity->content->subject}</a>";
echo '</div>';
echo format_string($activity->content->subject,true);
echo "</a>$closeformat";
echo "<br /><font size=\"2\">";
echo "<a href=\"$CFG->wwwroot/user/view.php?id=" . $activity->user->userid . "&amp;course=" . "$course\">"
. $activity->user->fullname . "</a>";
echo " - " . userdate($activity->timestamp) . "</font></td></tr>";
echo "</table>";
echo '<div class="user">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->userid}&amp;course=$courseid\">"
."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
echo '</div>';
echo "</td></tr></table>";
return;
}
+3 -13
View File
@@ -473,18 +473,8 @@
error("You can not update this post");
}
if ($forum->type == 'news' && !$fromform->parent) {
$updatediscussion = new object;
$updatediscussion->id = $fromform->discussion;
$updatediscussion->timestart = $fromform->timestart;
$updatediscussion->timeend = $fromform->timeend;
if (!update_record('forum_discussions', $updatediscussion)) {
error(get_string("couldnotupdate", "forum"), $errordestination);
}
}
$updatepost=$fromform; //realpost
$updatepost->forum=$forum->id;
$updatepost = $fromform; //realpost
$updatepost->forum = $forum->id;
if (!forum_update_post($updatepost, $message)) {
error(get_string("couldnotupdate", "forum"), $errordestination);
}
@@ -741,7 +731,7 @@
'format'=>$post->format):
array())+
(isset($dicussion->timestart)?array(
(isset($discussion->timestart)?array(
'timestart'=>$discussion->timestart):
array())+
+5 -17
View File
@@ -386,30 +386,18 @@ function forum_menu_list($course) {
$menu = array();
if ($forums = get_all_instances_in_course("forum", $course)) {
if ($cms = get_coursemodules_in_course('forum', $course->id)) {
if ($course->format == 'weeks') {
$strsection = get_string('week');
} else {
$strsection = get_string('topic');
}
foreach ($forums as $forum) {
if ($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$currentgroup = groups_get_activity_group($cm);
if (!isset($forum->visible)) {
if (!instance_is_visible("forum", $forum) &&
!has_capability('moodle/course:viewhiddenactivities', $context)) {
continue;
}
}
$groupmode = groups_get_activity_groupmode($cm); // Groups are being used
if ($groupmode == SEPARATEGROUPS && ($currentgroup === false) &&
!has_capability('moodle/site:accessallgroups', $context)) {
continue;
}
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$menu[$forum->id] = format_string($forum->name,true);
$menu[$cm->instance] = format_string($cm->name,true);
}
}
+5 -4
View File
@@ -12,7 +12,7 @@
if (! $cm = get_coursemodule_from_id('glossary', $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
@@ -21,13 +21,14 @@
error("Course module is incorrect");
}
require_login($course->id, false, $cm);
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:approve', $context);
$newentry->id = $eid;
$newentry->approved = 1;
$newentry->approved = 1;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
if (! update_record("glossary_entries", $newentry)) {
error("Could not update your glossary");
+18 -19
View File
@@ -30,12 +30,12 @@
$navlinks = array();
$navlinks[] = array('name' => $strglossarys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header_simple("$strglossarys", "", $navigation, "", "", true, "", navmenu($course));
/// Get all the appropriate data
if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
if (!$cms = get_coursemodules_in_course('data', $course->id, 'm.rsstype, m.rssarticles')) {
notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id");
die;
}
@@ -67,43 +67,42 @@
$currentsection = "";
foreach ($glossarys as $glossary) {
if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) {
// Show dimmed if the mod is hidden.
$link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else if ($glossary->visible) {
// Show normal if the mod is visible.
$link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else {
// Don't show the glossary.
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$class = $cm->visible ? '' : 'class="dimmed"';
$link = "<a class=\"dimmed\" href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
$printsection = "";
if ($glossary->section !== $currentsection) {
if ($glossary->section) {
$printsection = $glossary->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $glossary->section;
$currentsection = $cm->section;
}
$count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $glossary->id or sourceglossaryid = $glossary->id)");
// TODO: count only approved if not allowed to see them
$count = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}glossary_entries where (glossaryid = $cm->instance or sourceglossaryid = $cm->instance)");
//If this glossary has RSS activated, calculate it
if ($show_rss) {
$rsslink = '';
if ($glossary->rsstype and $glossary->rssarticles) {
if ($cm->rsstype and $cm->rssarticles) {
//Calculate the tolltip text
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($cm->name));
if (empty($USER->id)) {
$userid = 0;
} else {
$userid = $USER->id;
}
//Get html code for RSS link
$rsslink = rss_get_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
$rsslink = rss_get_link($course->id, $userid, "glossary", $cm->instance, $tooltiptext);
}
}
+54 -32
View File
@@ -209,57 +209,79 @@ function glossary_user_complete($course, $user, $mod, $glossary) {
}
}
function glossary_print_recent_activity($course, $isteacher, $timestart) {
function glossary_print_recent_activity($course, $viewfullnames, $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;
global $CFG, $USER;
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')) {
//TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0
$modinfo = get_fast_modinfo($course);
$ids = array();
foreach ($modinfo->cms as $cm) {
if ($cm->modname != 'glossary') {
continue;
}
if (!$cm->uservisible) {
continue;
}
$ids[$cm->instance] = $cm->instance;
}
if (!$ids) {
return false;
}
$entries = array();
$glist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
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) {
if (!$entries = get_records_sql("SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
ge.userid, u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}glossary_entries ge
JOIN {$CFG->prefix}user u ON u.id = ge.userid
WHERE ge.glossaryid IN ($glist) AND ge.timemodified > $timestart
ORDER BY ge.timemodified ASC")) {
return false;
}
$editor = array();
foreach ($entries as $entryid=>$entry) {
if ($entry->approved) {
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('&', '&amp;', $log->url);
if (!isset($editor[$entry->glossaryid])) {
$editor[$entry->glossaryid] = has_capability('mod/glossary:approve', get_context_instance(CONTEXT_MODULE, $modinfo->instances['glossary'][$entry->glossaryid]->id));
}
if (!$editor[$entry->glossaryid]) {
unset($entries[$entryid]);
}
}
$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');
if (!$entries) {
return false;
}
print_headline(get_string('newentries', 'glossary').':');
print_recent_activity_note($entry->timemodified, $user, $entry->concept,
$CFG->wwwroot.'/mod/glossary/view.php?g='.$entry->glossaryid.
'&amp;mode=entry&amp;hook='.$entry->id);
$strftimerecent = get_string('strftimerecent');
foreach ($entries as $entry) {
$link = $CFG->wwwroot.'/mod/glossary/view.php?g='.$entry->glossaryid.'&amp;mode=entry&amp;hook='.$entry->id;
if ($entry->approved) {
$dimmed = '';
} else {
$dimmed = ' dimmed_text';
}
echo '<div class="head'.$dimmed.'">';
echo '<div class="date">'.userdate($entry->timemodified, $strftimerecent).'</div>';
echo '<div class="name">'.fullname($entry, $viewfullnames).'</div>';
echo '</div>';
echo '<div class="info"><a href="'.$link.'">'.format_text($entry->concept, true).'</a></div>';
}
return $content;
return true;
}
+9 -3
View File
@@ -16,12 +16,12 @@
$strjournals = get_string("modulenameplural", "journal");
$strweek = get_string("week");
$strtopic = get_string("topic");
$navlinks = array();
$navlinks[] = array('name' => $strjournals, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header_simple("$strjournals", "", $navigation,
print_header_simple("$strjournals", "", $navigation,
"", "", true, "", navmenu($course));
@@ -41,6 +41,12 @@
}
foreach ($journals as $journal) {
$cm = get_coursemodule_from_instance('journal', $journal->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$journal->timestart = $course->startdate + (($journal->section - 1) * 608400);
if (!empty($journal->daysopen)) {
@@ -58,5 +64,5 @@
echo "<br />";
print_footer($course);
?>
+10 -12
View File
@@ -192,6 +192,8 @@ function journal_print_recent_activity($course, $isteacher, $timestart) {
$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 '.
@@ -203,19 +205,15 @@ function journal_print_recent_activity($course, $isteacher, $timestart) {
///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);
$cm = $modinfo->instances['journal'][$j_log_info->id];
if (!$cm->uservisible) {
continue;
}
//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('&', '&amp;', $log->url);
}
if (!isset($journals[$log->info])) {
$journals[$log->info] = $j_log_info;
$journals[$log->info]->time = $log->time;
$journals[$log->info]->url = str_replace('&', '&amp;', $log->url);
}
}
+7 -8
View File
@@ -70,14 +70,13 @@ function label_get_coursemodule_info($coursemodule) {
/// this activity in a course listing.
///
/// See get_array_of_activities() in course/lib.php
$info = NULL;
if ($label = get_record("label", "id", $coursemodule->instance)) {
$info->extra = urlencode($label->content);
}
return $info;
if ($label = get_record("label", "id", $coursemodule->instance)) {
$info = new object();
$info->extra = urlencode($label->content);
return $info;
} else {
return null;
}
}
function label_get_view_actions() {
-10
View File
@@ -82,16 +82,6 @@ function lams_user_complete($course, $user, $mod, $lams) {
return true;
}
function lams_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity
/// that has occurred in lams activities and print it out.
/// Return true if there was output, or false is there was none.
global $CFG;
return false; // True if anything was printed, otherwise false
}
function lams_cron () {
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
+9 -9
View File
@@ -31,7 +31,7 @@
/// Print the header
$navlinks = array();
$navlinks[] = array('name' => $strlessons, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: $strlessons", $course->fullname, $navigation, "", "", true, "", navmenu($course));
@@ -65,16 +65,16 @@
}
foreach ($lessons as $lesson) {
if (!$lesson->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
}
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
$cm = get_coursemodule_from_instance('lesson', $lesson->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$class = $cm->visible ? '' : 'class="dimmed"';
$link = "<a $class href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name)."</a>";
if ($lesson->deadline > $timenow) {
$due = userdate($lesson->deadline);
} else {
-11
View File
@@ -232,17 +232,6 @@ function lesson_user_complete($course, $user, $mod, $lesson) {
return true;
}
/*******************************************************************/
function lesson_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity
/// that has occurred in lesson activities and print it out.
/// Return true if there was output, or false is there was none.
global $CFG;
return false; // True if anything was printed, otherwise false
}
/**
* Prints lesson summaries on MyMoodle Page
*
+7 -3
View File
@@ -69,9 +69,13 @@
// Poplate the table with the list of instances.
$currentsection = '';
foreach ($quizzes as $quiz) {
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$data = array();
// Section number if necessary.
@@ -102,7 +106,7 @@
}
if ($showing == 'stats') {
// The $quiz objects returned by get_all_instances_in_course have the necessary $cm
// The $quiz objects returned by get_all_instances_in_course have the necessary $cm
// fields set to make the following call work.
$attemptcount = quiz_num_attempt_summary($quiz, $quiz);
if ($attemptcount) {
+99 -72
View File
@@ -509,108 +509,135 @@ function quiz_refresh_events($courseid = 0) {
return true;
}
/**
* Returns all quiz graded users since a given time for specified quiz
*/
function quiz_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $CFG, $COURSE, $USER;
function quiz_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $quiz="0", $user="", $groupid="") {
// Returns all quizzes since a given time. If quiz is specified then
// this restricts the results
global $CFG;
if ($quiz) {
$quizselect = " AND cm.id = '$quiz'";
if ($COURSE->id == $courseid) {
$course = $COURSE;
} else {
$quizselect = "";
$course = get_record('course', 'id', $courseid);
}
if ($user) {
$userselect = " AND u.id = '$user'";
$modinfo =& get_fast_modinfo($course);
$cm = $modinfo->cms[$cmid];
if ($userid) {
$userselect = "AND u.id = $userid";
} else {
$userselect = "";
}
$quizzes = get_records_sql("SELECT qa.*, q.name, u.firstname, u.lastname, u.picture,
q.course, q.sumgrades as maxgrade, cm.instance, cm.section, cm.id as cmid
FROM {$CFG->prefix}quiz_attempts qa,
{$CFG->prefix}quiz q,
{$CFG->prefix}user u,
{$CFG->prefix}course_modules cm
WHERE qa.timefinish > '$sincetime'
AND qa.userid = u.id $userselect
AND qa.quiz = q.id $quizselect
AND cm.instance = q.id
AND cm.course = '$courseid'
AND q.course = cm.course
ORDER BY qa.timefinish ASC");
if ($groupid) {
$groupselect = "AND gm.groupid = $groupid";
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
} else {
$groupselect = "";
$groupjoin = "";
}
if (empty($quizzes))
return;
if (!$attempts = get_records_sql("SELECT qa.*, q.sumgrades AS maxgrade,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}quiz_attempts qa
JOIN {$CFG->prefix}quiz q ON q.id = qa.quiz
JOIN {$CFG->prefix}user u ON u.id = qa.userid
$groupjoin
WHERE qa.timefinish > $timestart AND q.id = $cm->instance
$userselect $groupselect
ORDER BY qa.timefinish ASC")) {
return;
}
foreach ($quizzes as $quiz) {
if (empty($groupid) || groups_is_member($groupid, $quiz->userid)) {
$tmpactivity = new Object;
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
$grader = has_capability('moodle/grade:viewall', $cm_context);
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
$grader = has_capability('mod/quiz:grade', $cm_context);
$groupmode = groups_get_activity_groupmode($cm, $course);
$tmpactivity->type = "quiz";
$tmpactivity->defaultindex = $index;
$tmpactivity->instance = $quiz->quiz;
$tmpactivity->cmid = $quiz->cmid;
if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
}
$tmpactivity->name = $quiz->name;
$tmpactivity->section = $quiz->section;
$aname = format_string($cm->name,true);
foreach ($attempts as $attempt) {
if ($attempt->userid != $USER->id) {
if (!$grader) {
// grade permission required
continue;
}
$tmpactivity->content->attemptid = $quiz->id;
$tmpactivity->content->sumgrades = $quiz->sumgrades;
$tmpactivity->content->maxgrade = $quiz->maxgrade;
$tmpactivity->content->attempt = $quiz->attempt;
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
$usersgroups = groups_get_all_groups($course->id, $attempt->userid, $cm->groupingid);
if (!is_array($usersgroups)) {
continue;
}
$usersgroups = array_keys($usersgroups);
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
if (empty($intersect)) {
continue;
}
}
}
$tmpactivity->user->userid = $quiz->userid;
$tmpactivity->user->fullname = fullname($quiz);
$tmpactivity->user->picture = $quiz->picture;
$tmpactivity = new object();
$tmpactivity->timestamp = $quiz->timefinish;
$activities[] = $tmpactivity;
$index++;
}
$tmpactivity->type = 'quiz';
$tmpactivity->cmid = $cm->id;
$tmpactivity->name = $aname;
$tmpactivity->section = $cm->section;
$tmpactivity->timestamp = $attempt->timefinish;
$tmpactivity->content->attemptid = $attempt->id;
$tmpactivity->content->sumgrades = $attempt->sumgrades;
$tmpactivity->content->maxgrade = $attempt->maxgrade;
$tmpactivity->content->attempt = $attempt->attempt;
$tmpactivity->user->userid = $attempt->userid;
$tmpactivity->user->fullname = fullname($attempt, $viewfullnames);
$tmpactivity->user->picture = $attempt->picture;
$activities[$index++] = $tmpactivity;
}
return;
}
function quiz_print_recent_mod_activity($activity, $course, $detail=false) {
function quiz_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
global $CFG;
echo '<table border="0" cellpadding="3" cellspacing="0">';
echo '<table border="0" cellpadding="3" cellspacing="0" class="forum-recent">';
echo "<tr><td class=\"forumpostpicture\" width=\"35\" valign=\"top\">";
print_user_picture($activity->user->userid, $course, $activity->user->picture);
echo "</td><td style=\"width:100%;\"><font size=\"2\">";
echo "<tr><td class=\"userpicture\" valign=\"top\">";
print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
echo "</td><td>";
if ($detail) {
echo "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
"class=\"icon\" alt=\"$activity->type\" /> ";
echo "<a href=\"$CFG->wwwroot/mod/quiz/view.php?id=" . $activity->instance . "\">"
. format_string($activity->name,true) . "</a> - ";
$modname = $modnames[$activity->type];
echo '<div class="title">';
echo "<img src=\"$CFG->modpixpath/{$activity->type}/icon.gif\" ".
"class=\"icon\" alt=\"$modname\" />";
echo "<a href=\"$CFG->wwwroot/mod/quiz/view.php?id={$activity->cmid}\">{$activity->name}</a>";
echo '</div>';
}
if (has_capability('mod/quiz:grade', get_context_instance(CONTEXT_MODULE, $activity->cmid))) {
$grades = "(" . $activity->content->sumgrades . " / " . $activity->content->maxgrade . ") ";
echo "<a href=\"$CFG->wwwroot/mod/quiz/review.php?q="
. $activity->instance . "&amp;attempt="
. $activity->content->attemptid . "\">" . $grades . "</a> ";
echo '<div class="grade">';
echo get_string("attempt", "quiz")." {$activity->content->attempt}: ";
$grades = "({$activity->content->sumgrades} / {$activity->content->maxgrade})";
echo "<a href=\"$CFG->wwwroot/mod/quiz/review.php?attempt={$activity->content->attemptid}\">$grades</a>";
echo '</div>';
echo get_string("attempt", "quiz") . " - " . $activity->content->attempt . "<br />";
}
echo "<a href=\"$CFG->wwwroot/user/view.php?id="
. $activity->user->userid . "&amp;course=$course\">"
. $activity->user->fullname . "</a> ";
echo '<div class="user">';
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->userid}&amp;course=$courseid\">"
."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
echo '</div>';
echo " - " . userdate($activity->timestamp);
echo "</font></td></tr>";
echo "</table>";
echo "</td></tr></table>";
return;
}
+15 -21
View File
@@ -30,7 +30,7 @@
print_header("$course->shortname: $strresources", $course->fullname, $navigation,
"", "", true, "", navmenu($course));
if (! $resources = get_all_instances_in_course("resource", $course)) {
if (!$cms = get_coursemodules_in_course('resource', $course->id, 'm.timemodified, m.summary')) {
notice(get_string('thereareno', 'moodle', $strresources), "../../course/view.php?id=$course->id");
exit;
}
@@ -48,36 +48,30 @@
$currentsection = "";
$options->para = false;
foreach ($resources as $resource) {
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
if ($course->format == "weeks" or $course->format == "topics") {
$printsection = "";
if ($resource->section !== $currentsection) {
if ($resource->section) {
$printsection = $resource->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $resource->section;
$currentsection = $cm->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($resource->timemodified)."</span>";
$printsection = '<span class="smallinfo">'.userdate($cm->timemodified)."</span>";
}
if (!empty($resource->extra)) {
$extra = urldecode($resource->extra);
} else {
$extra = "";
}
if (!$resource->visible) { // Show dimmed if the mod is hidden
$table->data[] = array ($printsection,
"<a class=\"dimmed\" $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->summary, FORMAT_MOODLE, $options) );
} else { //Show normal if the mod is visible
$table->data[] = array ($printsection,
"<a $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->summary, FORMAT_MOODLE, $options) );
}
$class = $cm->visible ? '' : 'class="dimmed"';
$table->data[] = array ($printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>",
format_text($cm->summary, FORMAT_MOODLE, $options) );
}
echo "<br />";
+1
View File
@@ -350,6 +350,7 @@ function resource_get_coursemodule_info($coursemodule) {
$info = NULL;
if ($resource = get_record("resource", "id", $coursemodule->instance)) {
$info = new object();
if (!empty($resource->popup)) {
$info->extra = urlencode("onclick=\"this.target='resource$resource->id'; return ".
"openpopup('/mod/resource/view.php?inpopup=true&amp;id=".
+12 -12
View File
@@ -25,7 +25,7 @@
$strsummary = get_string("summary");
$strreport = get_string("report",'scorm');
$strlastmodified = get_string("lastmodified");
$navlinks = array();
$navlinks[] = array('name' => $strscorms, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($navlinks);
@@ -56,8 +56,13 @@
}
foreach ($scorms as $scorm) {
$cm = get_coursemodule_from_instance('scorm', $forum->id, $course->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$context = get_context_instance(CONTEXT_MODULE,$scorm->coursemodule);
$tt = "";
if ($course->format == "weeks" or $course->format == "topics") {
if ($scorm->section) {
@@ -77,17 +82,12 @@
} else if (has_capability('mod/scorm:viewscores', $context)) {
require_once('locallib.php');
$report = scorm_grade_user($scorm, $USER->id);
$reportshow = get_string('score','scorm').": ".$report;
}
if (!$scorm->visible) {
//Show dimmed if the mod is hidden
$table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
format_text($scorm->summary), $reportshow);
} else {
//Show normal if the mod is visible
$table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name,true)."</a>",
format_text($scorm->summary), $reportshow);
$reportshow = get_string('score','scorm').": ".$report;
}
$class = $cm->visible ? '' : 'class="dimmed"';
$table->data[] = array ($tt, "<a $class href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name)."</a>",
format_text($scorm->summary), $reportshow);
}
echo "<br />";
-14
View File
@@ -356,20 +356,6 @@ function scorm_user_complete($course, $user, $mod, $scorm) {
return true;
}
/**
* Given a list of logs, assumed to be those since the last login
* this function prints a short list of changes related to this module
* If isteacher is true then perhaps additional information is printed.
* This function is called from course/lib.php: print_recent_activity()
*
* @param reference $logs Logs reference
* @param boolean $isteacher
* @return boolean
*/
function scorm_print_recent_activity(&$logs, $isteacher=false) {
return false; // True if anything was printed, otherwise false
}
/**
* Function to be run periodically according to the moodle cron
* This function searches for things that need to be done, such
+19 -20
View File
@@ -20,18 +20,18 @@
$strstatus = get_string("status");
$strdone = get_string("done", "survey");
$strnotdone = get_string("notdone", "survey");
$navlinks = array();
$navlinks[] = array('name' => $strsurveys, 'link' => '', 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header_simple("$strsurveys", "", $navigation,
print_header_simple("$strsurveys", "", $navigation,
"", "", true, "", navmenu($course));
if (! $surveys = get_all_instances_in_course("survey", $course)) {
if (!$cms = get_coursemodules_in_course('survey', $course->id)) {
notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");
}
if ($course->format == "weeks") {
$table->head = array ($strweek, $strname, $strstatus);
$table->align = array ("CENTER", "LEFT", "LEFT");
@@ -45,35 +45,34 @@
$currentsection = '';
foreach ($surveys as $survey) {
if (!empty($USER->id) and survey_already_done($survey->id, $USER->id)) {
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
if (!empty($USER->id) and survey_already_done($cm->instance, $USER->id)) {
$ss = $strdone;
} else {
$ss = $strnotdone;
}
$printsection = "";
if ($survey->section !== $currentsection) {
if ($survey->section) {
$printsection = $survey->section;
if ($cm->section !== $currentsection) {
if ($cm->section) {
$printsection = $cm->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $survey->section;
$currentsection = $cm->section;
}
//Calculate the href
if (!$survey->visible) {
//Show dimmed if the mod is hidden
$tt_href = "<a class=\"dimmed\" href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
} else {
//Show normal if the mod is visible
$tt_href = "<a href=\"view.php?id=$survey->coursemodule\">".format_string($survey->name,true)."</a>";
}
$class = $cm->visible ? '' : 'class="dimmed"';
$tt_href = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name,true)."</a>";
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
$table->data[] = array ($printsection, $tt_href, "<a href=\"view.php?id=$cm->id\">$ss</a>");
} else {
$table->data[] = array ($tt_href, "<a href=\"view.php?id=$survey->coursemodule\">$ss</a>");
$table->data[] = array ($tt_href, "<a href=\"view.php?id=$cm->id\">$ss</a>");
}
}
+42 -28
View File
@@ -132,44 +132,58 @@ function survey_user_complete($course, $user, $mod, $survey) {
}
}
function survey_print_recent_activity($course, $isteacher, $timestart) {
function survey_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG;
$content = false;
$surveys = NULL;
$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 (!$logs = get_records_select('log', 'time > \''.$timestart.'\' AND '.
'course = \''.$course->id.'\' AND '.
'module = \'survey\' AND '.
'action = \'submit\' ', 'time ASC')) {
if (!$ids) {
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('&', '&amp;', $log->url);
}
$slist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right?
if (!$rs = get_recordset_sql("SELECT sa.userid, sa.survey, sa.time,
u.firstname, u.lastname, u.email, u.picture
FROM {$CFG->prefix}survey_answers sa
JOIN {$CFG->prefix}user u ON u.id = sa.userid
WHERE sa.survey IN ($slist) AND sa.time > $timestart
GROUP BY sa.userid, sa.survey
ORDER BY sa.id ASC")) {
return false;
}
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);
}
$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.pgp?id='.$survey->cmid;
print_recent_activity_note($survey->time, $survey, $survey->name, $url, false, $viewfullnames);
}
return $content;
return true;
}
function survey_get_participants($surveyid) {
+12 -13
View File
@@ -27,12 +27,12 @@
$navlinks = array();
$navlinks[] = array('name' => $strwikis, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navigation = build_navigation($navlinks);
print_header_simple("$strwikis", "", $navigation, "", "", true, "", navmenu($course));
/// Get all the appropriate data
if (! $wikis = get_all_instances_in_course("wiki", $course)) {
if (!$cms = get_coursemodules_in_course('wiki', $course->id, 'm.summary, m.wtype, m.timemodified')) {
notice(get_string('thereareno', 'moodle', $strwikis), "../../course/view.php?id=$course->id");
die;
}
@@ -58,20 +58,19 @@
$table->align = array ('LEFT', 'LEFT', 'LEFT', 'LEFT');
}
foreach ($wikis as $wiki) {
if (!$wiki->visible) {
//Show dimmed if the mod is hidden
$link = '<a class="dimmed" href="view.php?id='.$wiki->coursemodule.'">'.format_string($wiki->name,true).'</a>';
} else {
//Show normal if the mod is visible
$link = '<a href="view.php?id='.$wiki->coursemodule.'">'.format_string($wiki->name,true).'</a>';
foreach ($cms as $cm) {
if (!coursemodule_visible_for_user($cm)) {
continue;
}
$timmod = '<span class="smallinfo">'.userdate($wiki->timemodified).'</span>';
$summary = '<span class="smallinfo">'.format_text($wiki->summary).'</span>';
$class = $cm->visible ? '' : 'class="dimmed"';
$link = '<a '.$class.' href="view.php?id='.$cm->id.'">'.format_string($cm->name).'</a>';
$timmod = '<span class="smallinfo">'.userdate($cm->timemodified).'</span>';
$summary = '<span class="smallinfo">'.format_text($cm->summary).'</span>';
$site = get_site();
switch ($wiki->wtype) {
switch ($cm->wtype) {
case 'teacher':
$wtype = $site->teacher;
@@ -90,7 +89,7 @@
$wtype = '<span class="smallinfo">'.$wtype.'</span>';
if ($course->format == "weeks" or $course->format == "topics") {
$table->data[] = array ($wiki->section, $link, $summary, $wtype, $timmod);
$table->data[] = array ($cm->section, $link, $summary, $wtype, $timmod);
} else {
$table->data[] = array ($link, $summary, $wtype, $timmod);
}
+20 -22
View File
@@ -188,33 +188,31 @@ function wiki_print_recent_activity($course, $isteacher, $timestart) {
return false;
}
$modinfo = get_fast_modinfo($course);
$wikis = array();
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('&', '&amp;', $log->url);
$cm = $modinfo->instances['wiki'][$log->instance];
if (!$cm->uservisible) {
continue;
}
$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('&', '&amp;', $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);
}
if (!$wikis) {
return false;
}
return true; // True if anything was printed, otherwise 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 wiki_log_info($log) {
+7
View File
@@ -48,6 +48,13 @@
}
foreach ($workshops as $workshop) {
$cm = get_coursemodule_from_instance('workshop', $workshop->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!coursemodule_visible_for_user($cm)) {
continue;
}
if (workshop_is_teacher($workshop, $USER->id)) { // teacher see info (students see grade)
$info = workshop_phase($workshop, 'short');
if (time() > $workshop->submissionstart) {
+59 -106
View File
@@ -644,41 +644,26 @@ function workshop_is_recent_activity($course, $isteacher, $timestart) {//jlw1 ad
// NOTE: $isteacher usage should be converted to use roles.
// TODO: Fix this function.
//
function workshop_print_recent_activity($course, $isteacher, $timestart) {
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)) {
// got some, see if any belong to a visible module
$agreecontent = true;
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)) {
$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);
}
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);
}
}
}
@@ -688,32 +673,24 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
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;
}
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 ($assesscontent) {
if ($logs) {
$assesscontent = true;
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);
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);
}
}
}
@@ -723,30 +700,22 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
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;
}
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 ($commentcontent) {
if ($logs) {
$commentcontent = true;
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);
}
$log->firstname = $course->student; // Keep anonymous
$log->lastname = '';
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/workshop/'.$log->url);
}
}
}
@@ -756,30 +725,22 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
$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;
}
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 ($gradecontent) {
if ($logs) {
$gradecontent = true;
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);
}
$log->firstname = $course->teacher; // Keep anonymous
$log->lastname = '';
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/workshop/'.$log->url);
}
}
}
@@ -789,28 +750,20 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) {
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;
}
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 ($submitcontent) {
if ($logs) {
$submitcontent = true;
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);
}
print_recent_activity_note($log->time, $log, $log->name,
$CFG->wwwroot.'/mod/workshop/'.$log->url);
}
}
}
+20
View File
@@ -479,6 +479,26 @@ table.minicalendar {
font-size:1.1em;
}
#course-recent .user {
font-size:0.75em;
}
#course-recent .grade {
font-style: italic;
font-size:0.9em;
}
#course-recent .forum-recent .reply .title {
font-style: italic;
font-size:0.9em;
}
#course-recent .forum-recent .discussion .title {
font-weight:bold;
font-style: italic;
font-size:0.9em;
}
h2.headingblock {
font-size:1.1em;
}
+1 -1
View File
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2007101506; // YYYYMMDD = date of the 1.9 branch (don't change)
$version = 2007101507; // YYYYMMDD = date of the 1.9 branch (don't change)
// X = release number 1.9.[0,1,2,3...]
// Y = micro-increments between releases