Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'wip-MDL-30478-MOODLE_21_STABLE' of git://github.com/abg…

…reeve/moodle into MOODLE_21_STABLE
  • Loading branch information...
commit 4790c88e85e01ce608a2d86644d96c86a43e6cae 2 parents a52b49b + 4174535
Eloy Lafuente (stronk7) stronk7 authored
27 mod/wiki/create.php
@@ -31,7 +31,7 @@
31 31 $title = optional_param('title', get_string('newpage', 'wiki'), PARAM_TEXT);
32 32 $wid = optional_param('wid', 0, PARAM_INT);
33 33 $swid = optional_param('swid', 0, PARAM_INT);
34   -$gid = optional_param('gid', 0, PARAM_INT);
  34 +$group = optional_param('group', 0, PARAM_INT);
35 35 $uid = optional_param('uid', 0, PARAM_INT);
36 36
37 37 // 'create' action must be submitted by moodle form
@@ -50,7 +50,7 @@
50 50 }
51 51
52 52 } else {
53   - $subwiki = wiki_get_subwiki_by_group($wid, $gid, $uid);
  53 + $subwiki = wiki_get_subwiki_by_group($wid, $group, $uid);
54 54
55 55 if (!$wiki = wiki_get_wiki($wid)) {
56 56 print_error('invalidwikiid', 'wiki');
@@ -62,6 +62,26 @@
62 62 print_error('invalidcoursemoduleid', 'wiki');
63 63 }
64 64
  65 +$groups = new stdClass();
  66 +if (groups_get_activity_groupmode($cm)) {
  67 + $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
  68 + $canaccessgroups = has_capability('moodle/site:accessallgroups', $modulecontext);
  69 + if ($canaccessgroups) {
  70 + $groups->availablegroups = groups_get_all_groups($cm->course);
  71 + $allpart = new stdClass();
  72 + $allpart->id = '0';
  73 + $allpart->name = get_string('allparticipants');
  74 + array_unshift($groups->availablegroups, $allpart);
  75 + } else {
  76 + $groups->availablegroups = groups_get_all_groups($cm->course, $USER->id);
  77 + }
  78 + if (!empty($group)) {
  79 + $groups->currentgroup = $group;
  80 + } else {
  81 + $groups->currentgroup = groups_get_activity_group($cm);
  82 + }
  83 +}
  84 +
65 85 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
66 86
67 87 require_login($course->id, true, $cm);
@@ -74,10 +94,11 @@
74 94 $wikipage->set_swid($swid);
75 95 } else {
76 96 $wikipage->set_wid($wid);
77   - $wikipage->set_gid($gid);
  97 + $wikipage->set_gid($group);
78 98 $wikipage->set_uid($uid);
79 99 }
80 100
  101 +$wikipage->set_availablegroups($groups);
81 102 $wikipage->set_title($title);
82 103
83 104 // set page action, and initialise moodle form
15 mod/wiki/create_form.php
@@ -64,6 +64,21 @@ protected function definition() {
64 64 $mform->setType('pageformat', PARAM_ALPHANUMEXT);
65 65 $mform->addRule('pageformat', get_string('required'), 'required', null, 'client');
66 66
  67 + if (!empty($this->_customdata['groups']->availablegroups)) {
  68 + foreach ($this->_customdata['groups']->availablegroups as $groupdata) {
  69 + $groupinfo[$groupdata->id] = $groupdata->name;
  70 + }
  71 + if (count($groupinfo) > 1) {
  72 + $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
  73 + $mform->setDefault('groupinfo', $this->_customdata['groups']->currentgroup);
  74 + } else {
  75 + $groupid = key($groupinfo);
  76 + $groupname = $groupinfo[$groupid];
  77 + $mform->addElement('static', 'groupdesciption', get_string('group'), $groupname);
  78 + $mform->addElement('hidden', 'groupinfo', $groupid);
  79 + }
  80 + }
  81 +
67 82 //hiddens
68 83 $mform->addElement('hidden', 'action', 'create');
69 84 $mform->setType('action', PARAM_ALPHA);
25 mod/wiki/pagelib.php
@@ -862,6 +862,7 @@ class page_wiki_create extends page_wiki {
862 862 private $wid;
863 863 private $action;
864 864 private $mform;
  865 + private $groups;
865 866
866 867 function print_header() {
867 868 $this->set_url();
@@ -897,14 +898,18 @@ function set_swid($swid) {
897 898 $this->swid = $swid;
898 899 }
899 900
  901 + function set_availablegroups($group) {
  902 + $this->groups = $group;
  903 + }
  904 +
900 905 function set_action($action) {
901 906 global $PAGE;
902 907 $this->action = $action;
903 908
904 909 require_once(dirname(__FILE__) . '/create_form.php');
905   - $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'gid' => $this->gid, 'uid' => $this->uid));
  910 + $url = new moodle_url('/mod/wiki/create.php', array('action' => 'create', 'wid' => $PAGE->activityrecord->id, 'group' => $this->gid, 'uid' => $this->uid));
906 911 $formats = wiki_get_formats();
907   - $options = array('formats' => $formats, 'defaultformat' => $PAGE->activityrecord->defaultformat, 'forceformat' => $PAGE->activityrecord->forceformat);
  912 + $options = array('formats' => $formats, 'defaultformat' => $PAGE->activityrecord->defaultformat, 'forceformat' => $PAGE->activityrecord->forceformat, 'groups' => $this->groups);
908 913 if ($this->title != get_string('newpage', 'wiki')) {
909 914 $options['disable_pagetitle'] = true;
910 915 }
@@ -933,10 +938,16 @@ function print_content($pagetitle = '') {
933 938 }
934 939
935 940 function create_page($pagetitle) {
936   - global $USER, $CFG, $PAGE;
  941 + global $USER, $PAGE;
  942 +
937 943 $data = $this->mform->get_data();
938   - if (empty($this->subwiki)) {
939   - $swid = wiki_add_subwiki($PAGE->activityrecord->id, $this->gid, $this->uid);
  944 + if (isset($data->groupinfo)) {
  945 + $groupid = $data->groupinfo;
  946 + } else {
  947 + $groupid = '0';
  948 + }
  949 + if (!$this->subwiki = wiki_get_subwiki_by_group($this->wid, $groupid)) {
  950 + $swid = wiki_add_subwiki($PAGE->activityrecord->id, $groupid, $this->uid);
940 951 $this->subwiki = wiki_get_subwiki($swid);
941 952 }
942 953 if ($data) {
@@ -2054,8 +2065,8 @@ protected function print_save() {
2054 2065
2055 2066 //deleting old locks
2056 2067 wiki_delete_locks($this->page->id, $USER->id, $this->section);
2057   -
2058   - redirect($CFG->wwwroot . '/mod/wiki/view.php?pageid=' . $this->page->id);
  2068 + $url = new moodle_url('view.php', array('pageid' => $this->page->id, 'group' => $this->subwiki->groupid));
  2069 + redirect($url);
2059 2070 } else {
2060 2071 print_error('savingerror', 'wiki');
2061 2072 }
21 mod/wiki/view.php
@@ -81,7 +81,7 @@
81 81
82 82 // Getting current group id
83 83 $currentgroup = groups_get_activity_group($cm);
84   - $currentgroup = !empty($currentgroup) ? $currentgroup : 0;
  84 +
85 85 // Getting current user id
86 86 if ($wiki->wikimode == 'individual') {
87 87 $userid = $USER->id;
@@ -91,7 +91,7 @@
91 91
92 92 // Getting subwiki. If it does not exists, redirecting to create page
93 93 if (!$subwiki = wiki_get_subwiki_by_group($wiki->id, $currentgroup, $userid)) {
94   - $params = array('wid' => $wiki->id, 'gid' => $currentgroup, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
  94 + $params = array('wid' => $wiki->id, 'group' => $currentgroup, 'uid' => $userid, 'title' => $wiki->firstpagetitle);
95 95 $url = new moodle_url('/mod/wiki/create.php', $params);
96 96 redirect($url);
97 97 }
@@ -133,6 +133,8 @@
133 133 print_error('invalidcoursemodule');
134 134 }
135 135
  136 + $currentgroup = $subwiki->groupid;
  137 +
136 138 // Checking course instance
137 139 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
138 140
@@ -169,10 +171,6 @@
169 171 }
170 172
171 173 $groupmode = groups_get_activity_groupmode($cm);
172   - if (empty($currentgroup)) {
173   - $currentgroup = groups_get_activity_group($cm);
174   - $currentgroup = !empty($currentgroup) ? $currentgroup : 0;
175   - }
176 174
177 175 if ($wiki->wikimode == 'individual' && ($groupmode == SEPARATEGROUPS || $groupmode == VISIBLEGROUPS)) {
178 176 list($gid, $uid) = explode('-', $groupanduser);
@@ -202,15 +200,20 @@
202 200 print_error('nocontent','wiki');
203 201 }
204 202
205   - $params = array('wid' => $wiki->id, 'gid' => $gid, 'uid' => $uid, 'title' => $title);
  203 + $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $title);
206 204 $url = new moodle_url('/mod/wiki/create.php', $params);
207 205 redirect($url);
208 206 }
209 207
210 208 // Checking is there is a page with this title. If it does not exists, redirect to first page
211 209 if (!$page = wiki_get_page_by_title($subwiki->id, $title)) {
212   - $params = array('wid' => $wiki->id, 'gid' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
213   - $url = new moodle_url('/mod/wiki/view.php', $params);
  210 + $params = array('wid' => $wiki->id, 'group' => $gid, 'uid' => $uid, 'title' => $wiki->firstpagetitle);
  211 + // Check to see if the first page has been created
  212 + if (!wiki_get_page_by_title($subwiki->id, $wiki->firstpagetitle)) {
  213 + $url = new moodle_url('/mod/wiki/create.php', $params);
  214 + } else {
  215 + $url = new moodle_url('/mod/wiki/view.php', $params);
  216 + }
214 217 redirect($url);
215 218 }
216 219

0 comments on commit 4790c88

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