Skip to content

Commit cb221b5

Browse files
committed
feature is almost completed, topic can be moved to another forum.
1 parent f76ecb2 commit cb221b5

File tree

5 files changed

+114
-17
lines changed

5 files changed

+114
-17
lines changed

Diff for: lang/en/moodleoverflow.php

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341
$string['downvotenotchangeable'] = 'Downvote (not changeable)';
342342
$string['nodownvote'] = 'No downvote';
343343
$string['movetopicicon'] = 'The icon to move a topic';
344+
$string['movetopictoforum'] = 'The icon to move a selected topic to another forum';
344345

345346
// Privacy.
346347
$string['privacy:metadata:core_files'] = 'Moodleoverflow stores files which have been uploaded by the user to form part of a forum post.';

Diff for: locallib.php

+41-1
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
355355
// build linktopopup to move a topic
356356
$linktopopup = $CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id . '&movetopopup=' . $discussion->discussion;
357357
$preparedarray[$i]['linktopopup'] = $linktopopup;
358+
358359
// Add all created data to an array.
359-
360360
$preparedarray[$i]['statusstarter'] = $statusstarter;
361361
$preparedarray[$i]['statusteacher'] = $statusteacher;
362362
$preparedarray[$i]['statusboth'] = $statusboth;
@@ -390,6 +390,46 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
390390
}
391391
}
392392

393+
/**
394+
* Prints a popup with a menu of other moodleoverflow in the course.
395+
* Menu to move a topic to another moodleoverflow forum.
396+
*/
397+
function moodleoverflow_print_forum_list($course, $cm, $movetopopup) {
398+
global $CFG, $DB, $PAGE;
399+
$forumarray = array(array());
400+
$currentforum = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup), 'moodleoverflow');
401+
$currentdiscussion = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup), 'name');
402+
$forums = $DB->get_records('moodleoverflow', array('course' => $course->id));
403+
$amountforums = count($forums);
404+
405+
if($amountforums > 1) {
406+
// write the moodleoverflow-names in an array.
407+
$i = 0;
408+
foreach ($forums as $forum) {
409+
if ($forum->id == $currentforum->moodleoverflow) {
410+
continue;
411+
} else {
412+
$forumarray[$i]['name'] = $forum->name;
413+
$movetoforum = $CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id . '&movetopopup=' . $movetopopup . '&movetoforum=' . $forum->id;
414+
$forumarray[$i]['movetoforum'] = $movetoforum;
415+
}
416+
$i++;
417+
}
418+
$amountforums = true;
419+
} else {
420+
$amountforums = false;
421+
}
422+
423+
424+
// build popup
425+
$renderer = $PAGE->get_renderer('mod_moodleoverflow');
426+
$mustachedata = new stdClass();
427+
$mustachedata->hasforums = $amountforums;
428+
$mustachedata->forums = $forumarray;
429+
$mustachedata->currentdiscussion = $currentdiscussion->name;
430+
echo $renderer->render_forum_list($mustachedata);
431+
}
432+
393433
/**
394434
* Returns an array of counts of replies for each discussion.
395435
*

Diff for: renderer.php

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class mod_moodleoverflow_renderer extends plugin_renderer_base {
4646
public function render_discussion_list($data) {
4747
return $this->render_from_template('mod_moodleoverflow/discussion_list', $data);
4848
}
49+
50+
/**
51+
* Display the forum list in the view.php if a discussion needs to be moved to another forum.
52+
*/
53+
public function render_forum_list($data) {
54+
return $this->render_from_template('mod_moodleoverflow/forum_list', $data);
55+
}
4956

5057
/**
5158
* Renders a dummy post for users that cannot see the post.

Diff for: templates/forum_list.mustache

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{{!
2+
This file is part of Moodle - http://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template mod_moodleoverflow/discussion_list
19+
20+
Moodleoverflow discussion_list template.
21+
The purpose of this template is to render a list of discussions for the view.php.
22+
23+
Example context (json):
24+
{
25+
}
26+
}}
27+
{{#hasforums}}
28+
<table cellspacing="0" class="moodleoverflowheaderlist generaltable">
29+
<thead>
30+
<th class ="header topic" scope="col">
31+
{{#currentdiscussion}}
32+
Where do you want to move the topic "{{currentdiscussion}}" ?
33+
{{/currentdiscussion}}
34+
</th>
35+
</thead>
36+
<tbody>
37+
{{#forums}}
38+
<tr class="discussion">
39+
<td class="topic starter">
40+
{{name}}
41+
<a href='{{ movetoforum }}'>{{#pix}} i/arrow-right, core, {{#str}}movetopictoforum, moodleoverflow{{/str}} {{/pix}}</a>
42+
</td>
43+
</tr>
44+
{{/forums}}
45+
<tbody>
46+
</table>
47+
{{/hasforums}}
48+
{{^hasforums}}
49+
<div class="alert alert-info">
50+
Unfortunately, there is no other Moodleoverflow where you can move it.
51+
</div>
52+
{{/hasforums}}
53+
<br>

Diff for: view.php

+12-16
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
3535
$m = optional_param('m', 0, PARAM_INT); // MoodleOverflow ID.
3636
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
37-
$movetopopup = optional_param('movetopopup', 0, PARAM_INT);
37+
$movetopopup = optional_param('movetopopup', 0, PARAM_INT); // Which Topic to move.
38+
$linktoforum = optional_param('movetoforum', 0, PARAM_INT); // Forum to which it is moved.
3839
// Set the parameters.
3940
$params = array();
4041
if ($id) {
@@ -114,23 +115,18 @@
114115
}
115116
}
116117

117-
if ($movetopopup) {
118-
// make a list of all moodleoverflows in the course.
119-
$forumarray = array();
120-
$currentforum = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup), 'moodleoverflow');
121-
$forums = $DB->get_records('moodleoverflow', array('course' => $course->id));
122-
// write the moodleoverflow-names in an array.
123-
foreach ($forums as $forum) {
124-
if ($forum->id == $currentforum->moodleoverflow) {
125-
continue;
126-
} else {
127-
array_push($forumarray, $forum->name);
128-
}
129-
}
130-
// build popup
131-
118+
if ($movetopopup && has_capability('mod/moodleoverflow:movetopic', $context)) {
119+
moodleoverflow_print_forum_list($course, $cm, $movetopopup);
120+
}
132121

122+
if($linktoforum && $movetopopup && has_capability('mod/moodleoverflow:movetopic', $context)) {
123+
// Take the $movetopopup-id and the $linktoforum-id and move the discussion to the forum
124+
$topic = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup));
125+
$topic->moodleoverflow = $linktoforum;
126+
$DB->update_record('moodleoverflow_discussions', $topic);
127+
redirect($CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id);
133128
}
129+
134130
// Return here after posting, etc.
135131
$SESSION->fromdiscussion = qualified_me();
136132

0 commit comments

Comments
 (0)