Permalink
Browse files

Wiki: some changes to improve error messages and (slightly) behaviour…

… when in group mode
  • Loading branch information...
1 parent 29f1cae commit 745c19685c0da9e47272b5ed432a46ee040b0b36 sam_marshall committed Oct 9, 2006
Showing with 25 additions and 20 deletions.
  1. +22 −17 mod/wiki/lib.php
  2. +3 −3 mod/wiki/view.php
View
@@ -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.
View
@@ -283,7 +283,7 @@
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="";
@@ -347,7 +347,7 @@
<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');
}
@@ -400,7 +400,7 @@
/// 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) {

0 comments on commit 745c196

Please sign in to comment.