Skip to content

Commit

Permalink
ForumNG: Add discussion tags #11491
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanFez authored and sammarshallou committed Oct 28, 2014
1 parent b5511e8 commit d6df54c
Show file tree
Hide file tree
Showing 20 changed files with 712 additions and 32 deletions.
19 changes: 18 additions & 1 deletion backup/moodle2/backup_forumng_stepslib.php
Expand Up @@ -45,7 +45,7 @@ protected function define_structure() {
'reportingemail', 'subscription', 'feedtype', 'feeditems',
'maxpostsperiod', 'maxpostsblock', 'postingfrom', 'postinguntil',
'typedata', 'magicnumber', 'completiondiscussions', 'completionreplies',
'completionposts', 'removeafter', 'removeto', 'shared', 'originalcmid', 'gradingscale', 'canpostanon'));
'completionposts', 'removeafter', 'removeto', 'shared', 'originalcmid', 'gradingscale', 'canpostanon', 'tags'));

$discussions = new backup_nested_element('discussions');

Expand Down Expand Up @@ -90,6 +90,10 @@ protected function define_structure() {
$flagd = new backup_nested_element('flagd', array('id'), array(
'userid', 'flagged'));

$tags = new backup_nested_element('tags');

$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));

// Build the tree
$forumng->add_child($discussions);
$discussions->add_child($discussion);
Expand All @@ -115,6 +119,9 @@ protected function define_structure() {
$post->add_child($flags);
$flags->add_child($flag);

$discussion->add_child($tags);
$tags->add_child($tag);

// Define sources
$forumng->set_source_table('forumng', array('id' => backup::VAR_ACTIVITYID));

Expand All @@ -140,6 +147,16 @@ protected function define_structure() {
$flag->set_source_table('forumng_flags', array('postid' => backup::VAR_PARENTID));

$flagd->set_source_table('forumng_flags', array('discussionid' => backup::VAR_PARENTID));

$tag->set_source_sql('SELECT t.id, t.name, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.itemid = ?', array(
backup_helper::is_sqlparam('discussion'),
backup_helper::is_sqlparam('mod_forumng'),
backup::VAR_PARENTID));
}

// Define id annotations
Expand Down
19 changes: 19 additions & 0 deletions backup/moodle2/restore_forumng_stepslib.php
Expand Up @@ -55,6 +55,7 @@ protected function define_structure() {
'/activity/forumng/drafts/draft');
$paths[] = new restore_path_element('forumng_flagd',
'/activity/forumng/discussions/discussion/flagsd/flagd');
$paths[] = new restore_path_element('forumng_tag', '/activity/forumng/discussions/discussion/tags/tag');
}

// Return the paths wrapped into standard activity structure.
Expand Down Expand Up @@ -220,6 +221,24 @@ protected function process_forumng_read($data) {
$DB->insert_record('forumng_read', $data);
}

protected function process_forumng_tag($data) {
global $CFG, $DB;

$data = (object)$data;
$oldid = $data->id;

if (empty($CFG->usetags)) { // Tags disabled in server, nothing to process.
return;
}

$tag = $data->rawname;
$itemid = $this->get_new_parentid('forumng_discussion');
$forumid = $this->get_new_parentid('forumng');

$cm = get_coursemodule_from_instance('forumng', $forumid);
tag_set_add('discussion', $itemid, $tag, 'mod_forumng', context_module::instance($cm->id)->id);
}

protected function after_execute() {
global $DB, $CFG;

Expand Down
13 changes: 13 additions & 0 deletions db/access.php
Expand Up @@ -338,5 +338,18 @@
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),

'mod/forumng:addtag' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)

);
3 changes: 2 additions & 1 deletion db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/forumng/db" VERSION="20140728" COMMENT="ForumNG is a reimplemented variant of the original Moodle forum system. It provides asynchronous discussion facilities."
<XMLDB PATH="mod/forumng/db" VERSION="20140905" COMMENT="ForumNG is a reimplemented variant of the original Moodle forum system. It provides asynchronous discussion facilities."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -37,6 +37,7 @@
<FIELD NAME="originalcmid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="If this forum is a reference to (clone of) a shared forum, this field is non-null and points to the original forum. (When this is set, other settings in this table are ignored.)"/>
<FIELD NAME="gradingscale" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="grading scale"/>
<FIELD NAME="canpostanon" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="This flag is set to 1 if the user can post anonymously as a moderator , 0 if not."/>
<FIELD NAME="tags" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="field to indicate whether tags can be added to forumng discussions"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Expand Up @@ -180,5 +180,20 @@ function xmldb_forumng_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2014072800, 'forumng');
}

if ($oldversion < 2014102400) {

// Define field tags to be added to forumng.
$table = new xmldb_table('forumng');
$field = new xmldb_field('tags', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'canpostanon');

// Conditionally launch add field tags.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Forumng savepoint reached.
upgrade_mod_savepoint(true, 2014102400, 'forumng');
}

return true;
}
12 changes: 9 additions & 3 deletions editpost.php
Expand Up @@ -32,6 +32,7 @@
}
require_once('../../config.php');
require_once('mod_forumng.php');
require_once($CFG->dirroot . '/tag/lib.php');

$pageparams = array();

Expand Down Expand Up @@ -140,6 +141,7 @@ function send_edit_email($formdata, $post) {
$groupid = 0;
$forum = null;
$post = null;
$tags = null;
if ($draftid = optional_param('draft', 0, PARAM_INT)) {
$pageparams['draft'] = $draftid;
$draft = mod_forumng_draft::get_from_id($draftid);
Expand Down Expand Up @@ -246,6 +248,7 @@ function send_edit_email($formdata, $post) {
$params = array('d'=>$discussionid);
$pagename = get_string('editdiscussionoptions', 'forumng',
$post->get_effective_subject(false));
$tags = $discussion->get_tags();
} else {
// To edit existing posts, p (forum post id) is required
$postid = required_param('p', PARAM_INT);
Expand Down Expand Up @@ -299,7 +302,7 @@ function send_edit_email($formdata, $post) {
'iframe' => $iframe ? true : false,
'timelimit' => $ispost && $edit && !$post->can_ignore_edit_time_limit()
? $post->get_edit_time_limit() : 0,
'draft'=>$draft));
'draft'=>$draft, 'tags' => $tags));

if (is_object($post)) {
// Not a new discussion/post so we are editing a pre-existing post.
Expand Down Expand Up @@ -357,6 +360,9 @@ function send_edit_email($formdata, $post) {
if (!isset($fromform->sticky)) {
$fromform->sticky = false;
}
if (!isset($fromform->tags)) {
$fromform->tags = null;
}
// The form time is midnight, but because we want it to be
// inclusive, set it to 23:59:59 on that day.
if ($fromform->timeend) {
Expand Down Expand Up @@ -487,7 +493,7 @@ function send_edit_email($formdata, $post) {
$fromform->subject, $fromform->message['text'],
$fromform->message['format'], $hasattachments, !empty($fromform->mailnow),
$fromform->timestart, $fromform->timeend, false, $fromform->sticky,
0, true, $fromform->asmoderator);
0, true, $fromform->asmoderator, $fromform->tags);

// Save attachments
if (isset($fromform->attachments)) {
Expand Down Expand Up @@ -606,7 +612,7 @@ function send_edit_email($formdata, $post) {
: $discussion->get_group_id();
$discussion->edit_settings($groupid, $fromform->timestart,
$fromform->timeend, $discussion->is_locked(),
!empty($fromform->sticky), !empty($fromform->asmoderator));
!empty($fromform->sticky), $fromform->tags);
}

// Redirect to view discussion
Expand Down
35 changes: 25 additions & 10 deletions editpost_form.php
Expand Up @@ -40,7 +40,7 @@ public function definition() {
? $this->_customdata['timelimit'] : 0;
$draft = isset($this->_customdata['draft'])
? $this->_customdata['draft'] : null;

$tags = $this->_customdata['tags'];
// Keeps track of whether we add a group selector box.
$groupselector = false;

Expand Down Expand Up @@ -178,20 +178,35 @@ public function definition() {
$mform->addElement('date_selector', 'timeend',
get_string('timeend', 'forumng'), array('optional'=>true));
}
}

// Discussion options...
// Discussion options...
if ($isdiscussion && ($forum->can_manage_discussions() || $forum->can_tag_discussion())) {
$mform->addElement('header', 'id_stickyoptions',
get_string('discussionoptions', 'forumng'));

// Sticky discussion.
$options = array();
$options[0] = get_string('sticky_no', 'forumng');
$options[1] = get_string('sticky_yes', 'forumng');
$mform->addElement('select', 'sticky',
get_string('sticky', 'forumng'), $options);
$mform->addHelpButton('sticky', 'sticky', 'forumng');
if ($forum->can_manage_discussions()) {
$options = array();
$options[0] = get_string('sticky_no', 'forumng');
$options[1] = get_string('sticky_yes', 'forumng');
$mform->addElement('select', 'sticky',
get_string('sticky', 'forumng'), $options);
$mform->addHelpButton('sticky', 'sticky', 'forumng');
}

// Group.
// Tag discussion.
if ($forum->can_tag_discussion()) {
$mform->addElement('tags', 'tags', get_string('discussiontags', 'forumng'),
array('display' => 'noofficial'));
$mform->setType('tags', PARAM_TAGLIST);
$mform->setDefault('tags', $tags);
$mform->addHelpButton('tags', 'discussiontags', 'forumng');
}
}

// Group.
if ($isdiscussion && $forum->can_manage_discussions()) {
if ($forum->get_group_mode()) {
// Group ID comes from the post (if provided) or the params.
if ($post) {
Expand All @@ -200,7 +215,7 @@ public function definition() {
$groupid = $params['group'];
}

// Display as static or dropdown
// Display as static or dropdown.
if (has_capability('moodle/site:accessallgroups',
$forum->get_context())) {
// Users with 'access all groups' can move discussions, so
Expand Down
76 changes: 76 additions & 0 deletions internaldoc/testcase.tags.txt
@@ -0,0 +1,76 @@
This file contains a sequence of test cases for the ForumNG Tag feature.

Initial setup
=============

- two test student users U.S1 and U.S2.

CRE Creating ForumNG
====================

CRE01 / admin
In any course week, from the add activity dropdown, choose 'ForumNG'.
Enable discussion tagging (check box).

CRE02 / U.S1
Create discussion D1.
Set tags to 'adam, john, fred'.
Add post 'discussion post 1' and some text.
Create discussion 1A do not set/add tags.
Add post 'discussion post 1A' and some text.

CRE03 / U.S2 (change)
Create discussion 2
Set tags to 'adam, jim'
Add post 'discussion post 2' and some text
Create discussion 2A add tags 'adam, jim, john, ted'
Add post 'discussion post 2A' and some text

TTD Test discussions
====================

TTD01 / U.S2
Return to forum view page.
Check that 'Discussion 1' is shown as 'unread' in bold and the tags 'adam, john, fred' are shown in a smaller normal font.
Check that there is a drop down entitled 'View discussions with tag'
and the drop down shows a list of tags in alphabetical order with the correct number (sum) of tags for each tag.
If you have created the disccussions/tags as outlined above then the following should be in the dropdown list
adam (3)
fred (1)
jim (2)
john (2)
ted (1)

TTD02 /U.S2
Choose one of the above.
Check that the correct number (n) of discussions are shown and that each discussion is tagged
with the tag chosen from the dropdown.
Check that the dropdown has been replaced with the wording 'Viewing discussions with tag <tagname>'
followed by a link with the word 'Remove'
Click on the 'Remove' link
Check that the full list of (4) discussions are shown and the dropdown box is again shown

TTD03 / admin (change)
Goto discussion 1 and click on the button 'Discussion options'
In the 'discussion tags' text area remove the entry 'fred'
Save changes
Return to the forum
Check that 'discussion 1' no longer has the 'fred' tag
Check that the dropdown list no longer lists 'fred (1)'

TTD04 / admin
Goto discussion 2 and click on the button 'Discussion options'
In the 'discussion tags' text area remove the entry 'jim'
Save changes
Return to the forum
Check that 'discussion 2' no longer has the 'jim' tag
Check that the dropdown list lists 'jim (1)'
Choose 'jim (1)' from the dropdown.
Check that only 'discussion 2A' with the 'jim' tag is shown
Click on the 'Remove' link next to the 'Viewing discussions with tag <tagname>' label
Check that it returns you to the forum discussion list.
If you have followed the test as outlined above then the following should be in the dropdown list
adam (3)
jim (1)
john (2)
ted (1)
11 changes: 11 additions & 0 deletions lang/en/forumng.php
Expand Up @@ -172,6 +172,7 @@
$string['forumng:forwardposts'] = 'Forward posts';
$string['forumng:postasmoderator'] = 'Indentify self as moderator in post';
$string['forumng:postanon'] = 'Post as anonymous moderator';
$string['forumng:addtag'] = 'Allow user to set tags for a discussion';
$string['pluginadministration'] = 'ForumNG administration';
$string['modulename'] = 'ForumNG';
$string['pluginname'] = 'ForumNG';
Expand Down Expand Up @@ -899,3 +900,13 @@
$string['savefailnetwork'] = '<p>Unfortunately, your changes cannot be saved at this time. This is due to a
network error; the website is temporarily unavailable or you have been signed out. </p><p>Saving has been disabled
on this page. In order to retain any changes you must copy the post content, access this page again and then paste in your changes.</p>';
$string['tagging'] = 'Tagging';
$string['enabletagging'] = 'Enable discussion tagging';
$string['tagging_help'] = 'Enable tagging in discussions for this forum';
$string['discussiontags'] = 'Discussion tags';
$string['discussiontags_help'] = 'To add tags to a discussion enter the tags separated by commas';
$string['forumngdiscusstagfilter'] = 'View forum discussions by tag';
$string['forumngdiscusstagfilter_help'] = 'Select a tag option to view/filter forum discussions by';
$string['removefiltering'] = ' Viewing discussions with tag \'{$a}\'';
$string['filterdiscussions'] = 'View discussions with tag';
$string['remove'] = 'Remove';
11 changes: 11 additions & 0 deletions mod_form.php
Expand Up @@ -133,6 +133,13 @@ public function definition() {
}
}

// Add tagging to discussions.
if ($CFG->usetags) {
$mform->addElement('header', '', get_string('tagging', 'forumng'));
$mform->addElement('checkbox', 'tags', get_string('enabletagging', 'forumng'));
$mform->addHelpButton('tags', 'tagging', 'forumng');
}

// Ratings header
/*///////////////*/

Expand Down Expand Up @@ -465,6 +472,10 @@ public function get_data() {
if (empty($data->canpostanon)) {
$data->canpostanon = 0;
}
// Set the tags to 0 if empty so that they are consistency.
if (empty($data->tags)) {
$data->tags = 0;
}
// Set the removeto to null if the default option 'Delete permanently' was select
if (empty($data->removeto)) {
$data->removeto = null;
Expand Down

0 comments on commit d6df54c

Please sign in to comment.