From: vyshane Date: Sun, 24 Sep 2006 14:01:50 +0000 (+0000) Subject: Changed _print_recent_activity() functions so that they don't use $isteacher... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=583b57b42dbde6d94639cbbbed48c96972232288;p=moodle.git Changed _print_recent_activity() functions so that they don't use $isteacher. However, I've left the $isteacher parameter in the functions, for backward compatibility so as not to break thrid party modules. Should we remove the parameter now? --- diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 621075c789..962546e0da 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1986,7 +1986,7 @@ function assignment_print_recent_activity($course, $isteacher, $timestart) { if ($assignments) { print_headline(get_string('newsubmissions', 'assignment').':'); foreach ($assignments as $assignment) { - print_recent_activity_note($assignment->time, $assignment, $isteacher, $assignment->name, + print_recent_activity_note($assignment->time, $assignment, $assignment->name, $CFG->wwwroot.'/mod/assignment/'.$assignment->url); } $content = true; diff --git a/mod/exercise/lib.php b/mod/exercise/lib.php index 8ebee7e5a6..81c4c4c9a3 100644 --- a/mod/exercise/lib.php +++ b/mod/exercise/lib.php @@ -357,7 +357,7 @@ function exercise_print_recent_activity($course, $isteacher, $timestart) { $tempmod->id = $log->exerciseid; //Obtain the visible property from the instance if (instance_is_visible('exercise',$tempmod)) { - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&', $log->url)); } } @@ -388,7 +388,7 @@ function exercise_print_recent_activity($course, $isteacher, $timestart) { $tempmod->id = $log->exerciseid; //Obtain the visible property from the instance if (instance_is_visible('exercise',$tempmod)) { - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&', $log->url)); } } @@ -419,7 +419,7 @@ function exercise_print_recent_activity($course, $isteacher, $timestart) { $tempmod->id = $log->exerciseid; //Obtain the visible property from the instance if (instance_is_visible('exercise',$tempmod)) { - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/exercise/'.str_replace('&', '&', $log->url)); } } diff --git a/mod/forum/index.php b/mod/forum/index.php index 0e02e72fcd..efd50e6cc3 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -20,7 +20,7 @@ require_course_login($course); $currentgroup = get_current_group($course->id); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); - + unset($SESSION->fromdiscussion); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f5fad5e17e..a9b09d003f 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -853,11 +853,6 @@ function forum_print_overview($courses,&$htmlarray) { } } -/** - * NOTE: - * $isteacher is to be deprecated. We will need to remove it from all - * _print_recent_activity functions for all modules. - */ function forum_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a date, prints a summary of all the new /// messages posted in the course since that date @@ -876,9 +871,7 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $strftimerecent = get_string('strftimerecent'); - $isteacheredit = isteacheredit($course->id); $mygroupid = mygroupid($course->id); - $groupmode = array(); /// To cache group modes foreach ($logs as $log) { @@ -888,28 +881,26 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $tempmod->course = $log->course; $tempmod->id = $post->forum; //Obtain the visible property from the instance - $modvisible = instance_is_visible('forum', $tempmod); + $coursecontext = get_context_instance(COURSE_CONTEXT, $tempmod->course); + $modvisible = instance_is_visible('forum', $tempmod) + || has_capability('moodle/course:viewhiddenactivities', $coursecontext); } //Only if the post exists and mod is visible if ($post && $modvisible) { - /// Check whether this is for teachers only - $teacheronly = ''; - if ($post->forumtype == 'teacher') { - if ($isteacher) { - $teacheronly = 'class=\'teacheronly\''; - } else { - continue; - } + + if (!isset($cm[$post->forum])) { + $cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id); } + $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 - if (!$isteacheredit and $post->groupid != -1) { /// Editing teachers or open discussions - if (!isset($cm[$post->forum])) { - $cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id); - $groupmode[$post->forum] = groupmode($course, $cm[$post->forum]); - } + $groupmode[$post->forum] = groupmode($course, $cm[$post->forum]); + if ($groupmode[$post->forum]) { //hope i didn't break anything if (!@in_array($mygroupid, $post->groupid))/*$mygroupid != $post->groupid*/{ @@ -927,9 +918,9 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $subjectclass = ($log->action == 'add discussion') ? ' bold' : ''; - echo '
'. + echo '
'. '
'.$date.'
'. - '
'.fullname($post, $isteacher).'
'. + '
'.fullname($post, has_capability('moodle/site:viewfullnames', $coursecontext)).'
'. '
'; echo ''; } } - return $content; } @@ -1149,6 +1139,7 @@ function forum_get_readable_forums($userid, $courseid=0) { } $selectforums = "SELECT DISTINCT(f.id) AS id, + f.name AS name, f.type AS type, f.course AS course, cm.id AS cmid, @@ -1159,7 +1150,8 @@ function forum_get_readable_forums($userid, $courseid=0) { WHERE cm.instance = f.id AND cm.course = {$course->id} AND cm.module = {$forummod->id} - $selecthidden"; + $selecthidden + ORDER BY f.name ASC"; if ($forums = get_records_sql($selectforums)) { @@ -1314,114 +1306,6 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5 return get_records_sql($searchsql, $limitfrom, $limitnum); } - -/** - * - * PRE-ROLES VERSION. - * TODO: Remove this after testing. This is left here for convenience so that - * we can compare with new implementation above. - * Note that the argument $sepgroups has been removed in the new version. - */ -/* - function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50, - &$totalcount, $sepgroups=0, $extrasql='') { - - global $CFG, $USER; - require_once($CFG->libdir.'/searchlib.php'); - - if (!isteacher($courseid)) { - $notteacherforum = "AND f.type <> 'teacher'"; - $forummodule = get_record("modules", "name", "forum"); - $onlyvisible = "AND d.forum = f.id AND f.id = cm.instance AND cm.visible = 1 AND cm.module = $forummodule->id"; - $onlyvisibletable = ", {$CFG->prefix}course_modules cm, {$CFG->prefix}forum f"; - if (!empty($sepgroups)) { - $separategroups = SEPARATEGROUPS; - $selectgroup = " AND ( NOT (cm.groupmode='$separategroups'". - " OR (c.groupmode='$separategroups' AND c.groupmodeforce='1') )";//. - $selectgroup .= " OR d.groupid = '-1'"; //search inside discussions for all groups too - foreach ($sepgroups as $sepgroup){ - $selectgroup .= " OR d.groupid = '$sepgroup->id'"; - } - $selectgroup .= ")"; - - // " OR d.groupid = '$groupid')"; - $selectcourse = " AND d.course = '$courseid' AND c.id='$courseid'"; - $coursetable = ", {$CFG->prefix}course c"; - } else { - $selectgroup = ''; - $selectcourse = " AND d.course = '$courseid'"; - $coursetable = ''; - } - } else { - $notteacherforum = ""; - $selectgroup = ''; - $onlyvisible = ""; - $onlyvisibletable = ""; - $coursetable = ''; - if ($courseid == SITEID && isadmin()) { - $selectcourse = ''; - } else { - $selectcourse = " AND d.course = '$courseid'"; - } - } - - $timelimit = ''; - if (!empty($CFG->forum_enabletimedposts) && (!((isadmin() and !empty($CFG->admineditalways)) || isteacher($courseid)))) { - $now = time(); - $timelimit = " AND (d.userid = $USER->id OR ((d.timestart = 0 OR d.timestart <= $now) AND (d.timeend = 0 OR d.timeend > $now)))"; - } - - $limitfrom = $page; - $limitnum = $recordsperpage; - - /// Some differences in syntax for PostgreSQL - if ($CFG->dbtype == "postgres7") { - $LIKE = "ILIKE"; // case-insensitive - $NOTLIKE = "NOT ILIKE"; // case-insensitive - $REGEXP = "~*"; - $NOTREGEXP = "!~*"; - } else { //Note the LIKE are casesensitive for Oracle. Oracle 10g is required to use - $LIKE = "LIKE"; //the caseinsensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-( - $NOTLIKE = "NOT LIKE"; //See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches - $REGEXP = "REGEXP"; - $NOTREGEXP = "NOT REGEXP"; - } - - $messagesearch = ""; - $searchstring = ""; - // Need to concat these back together for parser to work. - foreach($searchterms as $searchterm){ - if ($searchstring != "") { - $searchstring .= " "; - } - $searchstring .= $searchterm; - } - - // We need to allow quoted strings for the search. The quotes *should* be stripped - // by the parser, but this should be examined carefully for security implications. - $searchstring = str_replace("\\\"","\"",$searchstring); - $parser = new search_parser(); - $lexer = new search_lexer($parser); - - if ($lexer->parse($searchstring)) { - $parsearray = $parser->get_parsed_array(); - $messagesearch = search_generate_SQL($parsearray,'p.message','p.subject','p.userid','u.id','u.firstname','u.lastname','p.modified', 'd.forum'); - } - - $selectsql = "{$CFG->prefix}forum_posts p, - {$CFG->prefix}forum_discussions d, - {$CFG->prefix}user u $onlyvisibletable $coursetable - WHERE ($messagesearch) - AND p.userid = u.id - AND p.discussion = d.id $selectcourse $notteacherforum $onlyvisible $selectgroup $timelimit $extrasql"; - - $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql"); - - return get_records_sql("SELECT p.*,d.forum, u.firstname,u.lastname,u.email,u.picture FROM - $selectsql ORDER BY p.modified DESC", $limitfrom, $limitnum); - }*/ - - function forum_get_ratings($postid, $sort="u.firstname ASC") { /// Returns a list of ratings for a particular post - sorted. global $CFG; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 06a4af9f61..f9b8120764 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -276,7 +276,7 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) { foreach ($entries as $entry) { $user = get_record('user','id',$entry->userid, '','', '','', 'firstname,lastname'); - print_recent_activity_note($entry->timemodified, $user, $isteacher, $entry->concept, + print_recent_activity_note($entry->timemodified, $user, $entry->concept, $CFG->wwwroot.'/mod/glossary/view.php?g='.$entry->glossaryid. '&mode=entry&hook='.$entry->id); } diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 2e3d6624d7..336ca4b451 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -890,40 +890,43 @@ function hotpot_print_recent_activity($course, $isteacher, $timestart) { /// Return true if there was output, or false is there was none. global $CFG; - $result = false; - if($isteacher){ - - $records = get_records_sql(" - SELECT - h.id AS id, - h.name AS name, - COUNT(*) AS count_attempts - FROM - {$CFG->prefix}hotpot AS h, - {$CFG->prefix}hotpot_attempts AS a - WHERE - h.course = $course->id - AND h.id = a.hotpot - AND a.id = a.clickreportid - AND a.starttime > $timestart - GROUP BY - h.id, h.name - "); - // note that PostGreSQL requires h.name in the GROUP BY clause - if($records) { - - $names = array(); - foreach ($records as $id => $record){ - $href = "$CFG->wwwroot/mod/hotpot/view.php?hp=$id"; - $name = ' '.$record->name.''; - if ($record->count_attempts > 1) { - $name .= " ($record->count_attempts)"; + $records = get_records_sql(" + SELECT + h.id AS id, + h.name AS name, + COUNT(*) AS count_attempts + FROM + {$CFG->prefix}hotpot AS h, + {$CFG->prefix}hotpot_attempts AS a + WHERE + h.course = $course->id + AND h.id = a.hotpot + AND a.id = a.clickreportid + AND a.starttime > $timestart + GROUP BY + h.id, h.name + "); + // note that PostGreSQL requires h.name in the GROUP BY clause + + if($records) { + $names = array(); + foreach ($records as $id => $record){ + if ($cm = get_coursemodule_from_instance('hotpot', $record->id, $course->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + + if (has_capability('mod/hotpot:viewreport', $context)) { + $href = "$CFG->wwwroot/mod/hotpot/view.php?hp=$id"; + $name = ' '.$record->name.''; + if ($record->count_attempts > 1) { + $name .= " ($record->count_attempts)"; + } + $names[] = $name; } - $names[] = $name; } - + } + if (count($names) > 0) { print_headline(get_string('modulenameplural', 'hotpot').':'); if ($CFG->version >= 2005050500) { // Moodle 1.5+ @@ -931,7 +934,6 @@ function hotpot_print_recent_activity($course, $isteacher, $timestart) { } else { // Moodle 1.4.x (or less) echo ''.implode('
', $names).'
'; } - $result = true; } } diff --git a/mod/journal/lib.php b/mod/journal/lib.php index c1056b44b3..6dca25a020 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -223,7 +223,7 @@ function journal_print_recent_activity($course, $isteacher, $timestart) { $content = true; print_headline(get_string('newjournalentries', 'journal').':'); foreach ($journals as $journal) { - print_recent_activity_note($journal->time, $journal, $isteacher, $journal->name, + print_recent_activity_note($journal->time, $journal, $journal->name, $CFG->wwwroot.'/mod/journal/'.$journal->url); } } diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 2c402991d1..263c364f9c 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -164,7 +164,7 @@ function survey_print_recent_activity($course, $isteacher, $timestart) { $content = true; print_headline(get_string('newsurveyresponses', 'survey').':'); foreach ($surveys as $survey) { - print_recent_activity_note($survey->time, $survey, $isteacher, $survey->name, + print_recent_activity_note($survey->time, $survey, $survey->name, $CFG->wwwroot.'/mod/survey/'.$survey->url); } } diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index a8a905f5db..57e0348ea6 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -206,7 +206,7 @@ function wiki_print_recent_activity($course, $isteacher, $timestart) { $content = true; print_headline(get_string('updatedwikipages', 'wiki').':', 3); foreach ($wikis as $wiki) { - print_recent_activity_note($wiki->time, $wiki, $isteacher, $wiki->pagename, + print_recent_activity_note($wiki->time, $wiki, $wiki->pagename, $CFG->wwwroot.'/mod/wiki/'.$wiki->url); } } diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 0f0b7e9fbf..f3d6a54e29 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -638,6 +638,10 @@ 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) { global $CFG; @@ -669,7 +673,7 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) { $log->firstname = $course->student; $log->lastname = ''; } - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/workshop/'.$log->url); } } @@ -705,7 +709,7 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) { $log->firstname = $course->student; $log->lastname = ''; } - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/workshop/'.$log->url); } } @@ -738,7 +742,7 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) { if (instance_is_visible("workshop",$tempmod)) { $log->firstname = $course->student; // Keep anonymous $log->lastname = ''; - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/workshop/'.$log->url); } } @@ -771,7 +775,7 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) { if (instance_is_visible("workshop",$tempmod)) { $log->firstname = $course->teacher; // Keep anonymous $log->lastname = ''; - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/workshop/'.$log->url); } } @@ -802,7 +806,7 @@ function workshop_print_recent_activity($course, $isteacher, $timestart) { $tempmod->id = $log->workshopid; //Obtain the visible property from the instance if (instance_is_visible("workshop",$tempmod)) { - print_recent_activity_note($log->time, $log, $isteacher, $log->name, + print_recent_activity_note($log->time, $log, $log->name, $CFG->wwwroot.'/mod/workshop/'.$log->url); } }