Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30478 - wiki - Fixing up group problems when viewing and creating…

… wiki pages.

Thanks to Matt Kolb for his contribution.
  • Loading branch information...
commit 5dedd64d585f2108a14b046d6b5e7900ad8f435c 1 parent ead4f18
@abgreeve abgreeve authored
View
27 mod/wiki/create.php
@@ -31,7 +31,7 @@
$title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT);
$wid = optional_param('wid', 0, PARAM_INT);
$swid = optional_param('swid', 0, PARAM_INT);
-$gid = optional_param('gid', 0, PARAM_INT);
+$group = optional_param('group', 0, PARAM_INT);
$uid = optional_param('uid', 0, PARAM_INT);
// 'create' action must be submitted by moodle form
@@ -50,7 +50,7 @@
}
} else {
- $subwiki = wiki_get_subwiki_by_group($wid, $gid, $uid);
+ $subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
if (!$wiki = wiki_get_wiki($wid)) {
print_error('invalidwikiid', 'wiki');
@@ -62,6 +62,26 @@
print_error('invalidcoursemoduleid', 'wiki');
}
+$groups = new stdClass();
+if (groups_get_activity_groupmode($cm)) {
+ $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
+ if ($canaccessgroups) {
+ $groups->availablegroups = groups_get_all_groups($cm->course);
+ $allpart = new stdClass();
+ $allpart->id = '0';
+ $allpart->name = get_string('allparticipants');
+ array_unshift($groups->availablegroups, $allpart);
+ } else {
+ $groups->availablegroups = groups_get_all_groups($cm->course, $USER->id);
+ }
+ if (!empty($group)) {
+ $groups->currentgroup = $group;
+ } else {
+ $groups->currentgroup = groups_get_activity_group($cm);
+ }
+}
+
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course->id, true, $cm);
@@ -74,10 +94,11 @@
$wikipage->set_swid($swid);
} else {
$wikipage->set_wid($wid);
- $wikipage->set_gid($gid);
+ $wikipage->set_gid($group);
$wikipage->set_uid($uid);
}
+$wikipage->set_availablegroups($groups);
$wikipage->set_title($title);
// set page action, and initialise moodle form
View
15 mod/wiki/create_form.php
@@ -64,6 +64,21 @@ protected function definition() {
$mform->setType('pageformat', PARAM_ALPHANUMEXT);
$mform->addRule('pageformat', get_string('required'), 'required', null, 'client');
+ if (!empty($this->_customdata['groups']->availablegroups)) {
+ foreach ($this->_customdata['groups']->availablegroups as $groupdata) {
+ $groupinfo[$groupdata->id] = $groupdata->name;
+ }
+ if (count($groupinfo) > 1) {
+ $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
+ $mform->setDefault('groupinfo', $this->_customdata['groups']->currentgroup);
+ } else {
+ $groupid = key($groupinfo);
+ $groupname = $groupinfo[$groupid];
+ $mform->addElement('static', 'groupdesciption', get_string('group'), $groupname);
+ $mform->addElement('hidden', 'groupinfo', $groupid);
+ }
+ }
+
//hiddens
$mform->addElement('hidden', 'action', 'create');
$mform->setType('action', PARAM_ALPHA);
View
25 mod/wiki/pagelib.php
@@ -862,6 +862,7 @@ class page_wiki_create extends page_wiki {
private $wid;
private $action;
private $mform;
+ private $groups;
function print_header() {
$this->set_url();
@@ -897,14 +898,18 @@ function set_swid($swid) {
$this->swid = $swid;
}
+ function set_availablegroups($group) {
+ $this->groups = $group;
+ }
+
function set_action($action) {
global $PAGE;
$this->action = $action;
require_once(dirname(__FILE__) . '/create_form.php');
- $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'gid' => $this->gid, 'uid' => $this->uid));
+ $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'group' => $this->gid, 'uid' => $this->uid));
$formats = wiki_get_formats();
- $options = array('formats' => $formats, 'defaultformat' => $PAGE->activityrecord->defaultformat, 'forceformat' => $PAGE->activityrecord->forceformat);
+ $options = array('formats' => $formats, 'defaultformat' => $PAGE->activityrecord->defaultformat, 'forceformat' => $PAGE->activityrecord->forceformat, 'groups' => $this->groups);
if ($this->title != get_string('newpage', 'wiki')) {
$options['disable_pagetitle'] = true;
}
@@ -933,10 +938,16 @@ function print_content($pagetitle = '') {
}
function create_page($pagetitle) {
- global $USER, $CFG, $PAGE;
+ global $USER, $PAGE;
+
$data = $this->mform->get_data();
- if (empty($this->subwiki)) {
- $swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
+ if (isset($data->groupinfo)) {
+ $groupid = $data->groupinfo;
+ } else {
+ $groupid = '0';
+ }
+ if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid)) {
+ $swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
$this->subwiki = wiki_get_subwiki($swid);
}
if ($data) {
@@ -2056,8 +2067,8 @@ protected function print_save() {
//deleting old locks
wiki_delete_locks($this->page->id, $USER->id, $this->section);
-
- redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id);
+ $url = new moodle_url('view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid));
+ redirect($url);
} else {
print_error('savingerror', 'wiki');
}
View
21 mod/wiki/view.php
@@ -81,7 +81,7 @@
// Getting current group id
$currentgroup = groups_get_activity_group($cm);
- $currentgroup = !empty($currentgroup) ? $currentgroup : 0;
+
// Getting current user id
if ($wiki->wikimode == 'individual') {
$userid = $USER->id;
@@ -91,7 +91,7 @@
// Getting subwiki. If it does not exists, redirecting to create page
if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) {
- $params = array('wid' => $wiki->id, 'gid' => $currentgroup, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
+ $params = array('wid' => $wiki->id, 'group' => $currentgroup, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
$url = new moodle_url('/mod/wiki/create.php', $params);
redirect($url);
}
@@ -133,6 +133,8 @@
print_error('invalidcoursemodule');
}
+ $currentgroup = $subwiki->groupid;
+
// Checking course instance
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
@@ -169,10 +171,6 @@
}
$groupmode = groups_get_activity_groupmode($cm);
- if (empty($currentgroup)) {
- $currentgroup = groups_get_activity_group($cm);
- $currentgroup = !empty($currentgroup) ? $currentgroup : 0;
- }
if ($wiki->wikimode == 'individual' && ($groupmode == SEPARATEGROUPS || $groupmode == VISIBLEGROUPS)) {
list($gid, $uid) = explode('-', $groupanduser);
@@ -202,15 +200,20 @@
print_error('nocontent','wiki');
}
- $params = array('wid' => $wiki->id, 'gid' => $gid, 'uid' => $uid, 'title' => $title);
+ $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $title);
$url = new moodle_url('/mod/wiki/create.php', $params);
redirect($url);
}
// Checking is there is a page with this title. If it does not exists, redirect to first page
if (!$page = wiki_get_page_by_title($subwiki->id, $title)) {
- $params = array('wid' => $wiki->id, 'gid' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
- $url = new moodle_url('/mod/wiki/view.php', $params);
+ $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
+ // Check to see if the first page has been created
+ if (!wiki_get_page_by_title($subwiki->id, $wiki->firstpagetitle)) {
+ $url = new moodle_url('/mod/wiki/create.php', $params);
+ } else {
+ $url = new moodle_url('/mod/wiki/view.php', $params);
+ }
redirect($url);
}

0 comments on commit 5dedd64

Please sign in to comment.
Something went wrong with that request. Please try again.