]> git.mjollnir.org Git - moodle.git/commitdiff
Changed <module>_print_recent_activity() functions so that they don't use $isteacher...
authorvyshane <vyshane>
Sun, 24 Sep 2006 14:01:50 +0000 (14:01 +0000)
committervyshane <vyshane>
Sun, 24 Sep 2006 14:01:50 +0000 (14:01 +0000)
mod/assignment/lib.php
mod/exercise/lib.php
mod/forum/index.php
mod/forum/lib.php
mod/glossary/lib.php
mod/hotpot/lib.php
mod/journal/lib.php
mod/survey/lib.php
mod/wiki/lib.php
mod/workshop/lib.php

index 621075c789b681b6ac23c45ea9aec860f45db0cb..962546e0da1d03466c2244d33c0617c23d7570a0 100644 (file)
@@ -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;
index 8ebee7e5a6c85b512ea5f8542c35fd59a8e003f0..81c4c4c9a30bd6f5beaf2172238e2ff754f35b80 100644 (file)
@@ -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('&', '&amp;', $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('&', '&amp;', $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('&', '&amp;', $log->url));
                     }
                 }
index 0e02e72fcd8a8607bbc6cfada300631f59a2e000..efd50e6cc37535a1e7f2e0cdb143727da909f842 100644 (file)
@@ -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);
 
index f5fad5e17e8e606d525725d3e981af826a21e8dd..a9b09d003f52b79d7a951fe08eb691b4ea9d2a60 100644 (file)
@@ -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 '<div class="head'.$teacheronly.'">'.
+            echo '<div class="head">'.
                    '<div class="date">'.$date.'</div>'.
-                   '<div class="name">'.fullname($post, $isteacher).'</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).'">';
@@ -938,7 +929,6 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
             echo '</a>"</div>';
         }
     }
-
     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;
index 06a4af9f6125d2084f88bd116bda76715ab73faa..f9b81207641ceba5fd6af5bfe2c3fddeb5860e6b 100644 (file)
@@ -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.
                                        '&amp;mode=entry&amp;hook='.$entry->id);
         }
index 2e3d6624d726fab130141764018167184b70dbdd..336ca4b4510bcd430816d8dd5b92774bc9668668 100644 (file)
@@ -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 = '&nbsp;<a href="'.$href.'">'.$record->name.'</a>';
-                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 = '&nbsp;<a href="'.$href.'">'.$record->name.'</a>';
+                    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 '<font size="1">'.implode('<br />', $names).'</font>';
             }
-
             $result = true;
         }
     }
index c1056b44b37f2ddd6feb9940949eeec8352e3d57..6dca25a0205278c6afc33fdbda6d803a7682a88a 100644 (file)
@@ -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);
         }
     }
index 2c402991d12df3c098afa1575ffa24609d2b69b2..263c364f9c3185d7f9ef062580476623e7bd6032 100644 (file)
@@ -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);
         }
     }
index a8a905f5db0159e1b94c1b757eca5da2ffbb3ec9..57e0348ea637c56325a4d89278bcd277d248a319 100644 (file)
@@ -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);
         }
     }
index 0f0b7e9fbf058bef80c7a1d5206853da5dc41246..f3d6a54e296072f03863c06d4a12115e39ea93fc 100644 (file)
@@ -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);
                     }
                 }