]> git.mjollnir.org Git - moodle.git/commitdiff
Wiki: some changes to improve error messages and (slightly) behaviour when in group...
authorsam_marshall <sam_marshall>
Mon, 9 Oct 2006 14:29:14 +0000 (14:29 +0000)
committersam_marshall <sam_marshall>
Mon, 9 Oct 2006 14:29:14 +0000 (14:29 +0000)
mod/wiki/lib.php
mod/wiki/view.php

index 8e6188067d9aecf2943a9f3a7b350e8f98a37db8..44d751bfdbd46b92147068ea38c59495d09b6680 100644 (file)
@@ -448,23 +448,28 @@ function wiki_get_entry(&$wiki, &$course, $userid=0, $groupid=0) {
     case 'group':
         /// If there is a groupmode, get the user's group id.
         $groupmode = groupmode($course, $wiki);
-        //echo "groupid is in wiki_get_entry ".$groupid."<br />";
-        /// If a specific group was requested, return it, if allowed.
-        if ($groupid and wiki_user_can_access_group_wiki($wiki, $groupid, $course)) {
-            $wentry = wiki_get_group_entry($wiki, $groupid);
-        }
-        else if ($groupmode) {
-            $mygroupids = mygroupid($course->id);
-            /// If there is no entry for this user, check if this user is a teacher.
-            //this is broken for multiple groups /*mygroupid($course->id)*/
-            //while ($groupindex < size(mygroupids) AND !$wentry = wiki_get_group_entry($))
-            if (!$wentry = wiki_get_group_entry($wiki, $mygroupids[0])){//always default to first group it returns, can change later!
-    /*  if (wiki_is_teacher($wiki, $USER->id)) {
-                    /// If this user is a teacher, return the first entry.
-                    if ($wentries = wiki_get_entries($wiki)) {
-                        $wentry = current($wentries);
-                    }
-                } */
+        if($groupmode) {
+            if(!$groupid) {
+                if(($mygroupids=mygroupid($course->id)) && count($mygroupids)>0) {
+                    // Use first group. They ought to be able to change later
+                    $groupid=$mygroupids[0];
+                } else {
+                    // Whatever groups are in the course, pick one
+                    $coursegroups=get_records('groups','courseid',$course->id,'','id,name');
+                    if(!$coursegroups || count($coursegroups)==0) {
+                        error("Can't access wiki in group mode when no groups are configured for the course"); 
+                    } 
+                    $unkeyed=array_values($coursegroups); // Make sure first item is index 0
+                    $groupid=$unkeyed[0]->id;
+                }
+            }
+        
+            //echo "groupid is in wiki_get_entry ".$groupid."<br />";
+            /// If a specific group was requested, return it, if allowed.
+            if ($groupid and wiki_user_can_access_group_wiki($wiki, $groupid, $course)) {
+                $wentry = wiki_get_group_entry($wiki, $groupid);
+            } else {
+                error("Cannot access any groups for this wiki");
             }
         }
         /// If mode is 'nogroups', then groupid is zero.
index 5372bb7b606d7fa7d4ca3501beb931cf17abc47e..759273de6af5b98f452ebdfda98a2f2f92a3b2ce 100644 (file)
     echo '    <div id="wikiPageActions">
     ';
     /// The top row contains links to other wikis, if applicable.
-    if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) {
+    if ($wiki_entry && $wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) {
         //echo "wiki list ";print_r($wiki_list);
         $selected="";
         
     <div id="wiki-view" class="mwiki">
     ';
 
-    if($ewiki_title==$wiki_entry->pagename && !empty($wiki->summary)) {
+    if($wiki_entry && $ewiki_title==$wiki_entry->pagename && !empty($wiki->summary)) {
       if (trim(strip_tags($wiki->summary))) {
           print_simple_box(format_text($wiki->summary, FORMAT_MOODLE), 'center', '70%', '', 5, 'generalbox', 'intro');
       }
     /// actions will have the form [action]/[pagename]. If the action is 'view' or the  '/'
     /// isn't there (so the action defaults to 'view'), filter it.
     /// If the page does not yet exist, the display will default to 'edit'.
-    if((count($actions) < 2 || $actions[0] == "view") &&
+    if((count($actions) < 2 || $actions[0] == "view") && $wiki_entry && 
         record_exists('wiki_pages', 'pagename', addslashes($page), 'wiki', $wiki_entry->id)) {
         print(format_text($content, $moodle_format));
     } else if($actions[0]=='edit' && $reallyedit) {