Wiki: some changes to improve error messages and (slightly) behaviour when in group mode

This commit is contained in:
sam_marshall 2006-10-09 14:29:14 +00:00
parent 29f1cae1b0
commit 745c19685c
2 changed files with 25 additions and 20 deletions

View 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.

View File

@ -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) {