Skip to content

Commit

Permalink
Merge branch 'wip-MDL-30478-MOODLE_21_STABLE' of git://github.com/abg…
Browse files Browse the repository at this point in the history
…reeve/moodle into MOODLE_21_STABLE
  • Loading branch information
stronk7 committed Apr 24, 2012
2 parents a52b49b + 4174535 commit 4790c88
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 19 deletions.
27 changes: 24 additions & 3 deletions mod/wiki/create.php
Expand Up @@ -31,7 +31,7 @@
$title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT); $title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT);
$wid = optional_param('wid', 0, PARAM_INT); $wid = optional_param('wid', 0, PARAM_INT);
$swid = optional_param('swid', 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); $uid = optional_param('uid', 0, PARAM_INT);


// 'create' action must be submitted by moodle form // 'create' action must be submitted by moodle form
Expand All @@ -50,7 +50,7 @@
} }


} else { } 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)) { if (!$wiki = wiki_get_wiki($wid)) {
print_error('invalidwikiid', 'wiki'); print_error('invalidwikiid', 'wiki');
Expand All @@ -62,6 +62,26 @@
print_error('invalidcoursemoduleid', 'wiki'); 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); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);


require_login($course->id, true, $cm); require_login($course->id, true, $cm);
Expand All @@ -74,10 +94,11 @@
$wikipage->set_swid($swid); $wikipage->set_swid($swid);
} else { } else {
$wikipage->set_wid($wid); $wikipage->set_wid($wid);
$wikipage->set_gid($gid); $wikipage->set_gid($group);
$wikipage->set_uid($uid); $wikipage->set_uid($uid);
} }


$wikipage->set_availablegroups($groups);
$wikipage->set_title($title); $wikipage->set_title($title);


// set page action, and initialise moodle form // set page action, and initialise moodle form
Expand Down
15 changes: 15 additions & 0 deletions mod/wiki/create_form.php
Expand Up @@ -64,6 +64,21 @@ protected function definition() {
$mform->setType('pageformat', PARAM_ALPHANUMEXT); $mform->setType('pageformat', PARAM_ALPHANUMEXT);
$mform->addRule('pageformat', get_string('required'), 'required', null, 'client'); $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 //hiddens
$mform->addElement('hidden', 'action', 'create'); $mform->addElement('hidden', 'action', 'create');
$mform->setType('action', PARAM_ALPHA); $mform->setType('action', PARAM_ALPHA);
Expand Down
25 changes: 18 additions & 7 deletions mod/wiki/pagelib.php
Expand Up @@ -862,6 +862,7 @@ class page_wiki_create extends page_wiki {
private $wid; private $wid;
private $action; private $action;
private $mform; private $mform;
private $groups;


function print_header() { function print_header() {
$this->set_url(); $this->set_url();
Expand Down Expand Up @@ -897,14 +898,18 @@ function set_swid($swid) {
$this->swid = $swid; $this->swid = $swid;
} }


function set_availablegroups($group) {
$this->groups = $group;
}

function set_action($action) { function set_action($action) {
global $PAGE; global $PAGE;
$this->action = $action; $this->action = $action;


require_once(dirname(__FILE__) . '/create_form.php'); 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(); $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')) { if ($this->title != get_string('newpage', 'wiki')) {
$options['disable_pagetitle'] = true; $options['disable_pagetitle'] = true;
} }
Expand Down Expand Up @@ -933,10 +938,16 @@ function print_content($pagetitle = '') {
} }


function create_page($pagetitle) { function create_page($pagetitle) {
global $USER, $CFG, $PAGE; global $USER, $PAGE;

$data = $this->mform->get_data(); $data = $this->mform->get_data();
if (empty($this->subwiki)) { if (isset($data->groupinfo)) {
$swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid); $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); $this->subwiki = wiki_get_subwiki($swid);
} }
if ($data) { if ($data) {
Expand Down Expand Up @@ -2054,8 +2065,8 @@ protected function print_save() {


//deleting old locks //deleting old locks
wiki_delete_locks($this->page->id, $USER->id, $this->section); wiki_delete_locks($this->page->id, $USER->id, $this->section);

$url = new moodle_url('view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid));
redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id); redirect($url);
} else { } else {
print_error('savingerror', 'wiki'); print_error('savingerror', 'wiki');
} }
Expand Down
21 changes: 12 additions & 9 deletions mod/wiki/view.php
Expand Up @@ -81,7 +81,7 @@


// Getting current group id // Getting current group id
$currentgroup = groups_get_activity_group($cm); $currentgroup = groups_get_activity_group($cm);
$currentgroup = !empty($currentgroup) ? $currentgroup : 0;
// Getting current user id // Getting current user id
if ($wiki->wikimode == 'individual') { if ($wiki->wikimode == 'individual') {
$userid = $USER->id; $userid = $USER->id;
Expand All @@ -91,7 +91,7 @@


// Getting subwiki. If it does not exists, redirecting to create page // Getting subwiki. If it does not exists, redirecting to create page
if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) { 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); $url = new moodle_url('/mod/wiki/create.php', $params);
redirect($url); redirect($url);
} }
Expand Down Expand Up @@ -133,6 +133,8 @@
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }


$currentgroup = $subwiki->groupid;

// Checking course instance // Checking course instance
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);


Expand Down Expand Up @@ -169,10 +171,6 @@
} }


$groupmode = groups_get_activity_groupmode($cm); $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)) { if ($wiki->wikimode == 'individual' && ($groupmode == SEPARATEGROUPS || $groupmode == VISIBLEGROUPS)) {
list($gid, $uid) = explode('-', $groupanduser); list($gid, $uid) = explode('-', $groupanduser);
Expand Down Expand Up @@ -202,15 +200,20 @@
print_error('nocontent','wiki'); 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); $url = new moodle_url('/mod/wiki/create.php', $params);
redirect($url); redirect($url);
} }


// Checking is there is a page with this title. If it does not exists, redirect to first page // 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)) { if (!$page = wiki_get_page_by_title($subwiki->id, $title)) {
$params = array('wid' => $wiki->id, 'gid' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle); $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
$url = new moodle_url('/mod/wiki/view.php', $params); // 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); redirect($url);
} }


Expand Down

0 comments on commit 4790c88

Please sign in to comment.