Skip to content

Commit

Permalink
MDL-71642 qbank_comment: Add question comment plugin to core
Browse files Browse the repository at this point in the history
This implementation will introduce a qbank plugin
"comment" which will allow users with the capability
to comment in a question. It also implements a
callback for the question preview page to view
and add comments from the preview page. Comment
plugin is implemented using the existing comments
API from the core.

Co-Authored-By: Guillermo Gomez Arias <guillermogomez@catalyst-au.net>
Co-Authored-By: Safat Shahin <safatshahin@catalyst-au.net>
Co-Authored-By: Matt Porritt <mattp@catalyst-au.net>
  • Loading branch information
3 people committed Oct 8, 2021
1 parent 70073fd commit 3be2b12
Show file tree
Hide file tree
Showing 35 changed files with 2,165 additions and 18 deletions.
1 change: 1 addition & 0 deletions backup/moodle2/backup_plan_builder.class.php
Expand Up @@ -36,6 +36,7 @@
require_once($CFG->dirroot . '/backup/moodle2/backup_default_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qbank_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_extrafields_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php');
Expand Down
38 changes: 38 additions & 0 deletions backup/moodle2/backup_qbank_plugin.class.php
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Defines backup_qbank_plugin class.
*
* @package core_backup
* @subpackage moodle2
* @category backup
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Base class for qbank backup plugins.
*
* @package core_backup
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class backup_qbank_plugin extends backup_plugin {
// Use default parent behaviour.
}
23 changes: 10 additions & 13 deletions backup/moodle2/backup_stepslib.php
Expand Up @@ -787,34 +787,28 @@ protected function define_structure() {
}

/**
* structure step in charge of constructing the comments.xml file for all the comments found
* in a given context
* Structure step in charge of constructing the comments.xml file for all the comments found in a given context.
*/
class backup_comments_structure_step extends backup_structure_step {

protected function define_structure() {

// Define each element separated

// Define each element separated.
$comments = new backup_nested_element('comments');

$comment = new backup_nested_element('comment', array('id'), array(
'commentarea', 'itemid', 'content', 'format',
'component', 'commentarea', 'itemid', 'content', 'format',
'userid', 'timecreated'));

// Build the tree

// Build the tree.
$comments->add_child($comment);

// Define sources

// Define sources.
$comment->set_source_table('comments', array('contextid' => backup::VAR_CONTEXTID));

// Define id annotations

// Define id annotations.
$comment->annotate_ids('user', 'userid');

// Return the root element (comments)
// Return the root element (comments).
return $comments;
}
}
Expand Down Expand Up @@ -2356,6 +2350,9 @@ protected function define_structure() {
// attach qtype plugin structure to $question element, only one allowed
$this->add_plugin_structure('qtype', $question, false);

// Attach qbank plugin stucture to $question element, multiple allowed.
$this->add_plugin_structure('qbank', $question, true);

// attach local plugin stucture to $question element, multiple allowed
$this->add_plugin_structure('local', $question, true);

Expand Down
2 changes: 2 additions & 0 deletions backup/moodle2/restore_plan_builder.class.php
Expand Up @@ -35,6 +35,7 @@
require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_qbank_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_extrafields_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php');
Expand All @@ -46,6 +47,7 @@
require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_enrol_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qbank_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_extrafields_plugin.class.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
Expand Down
39 changes: 39 additions & 0 deletions backup/moodle2/restore_qbank_plugin.class.php
@@ -0,0 +1,39 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Defines restore_qbank_plugin class.
*
* @package core_backup
* @subpackage moodle2
* @category backup
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


/**
* Base class for qbank backup plugins.
*
* @package core_backup
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class restore_qbank_plugin extends restore_plugin {
// Use default parent behaviour.
}
5 changes: 4 additions & 1 deletion backup/moodle2/restore_stepslib.php
Expand Up @@ -4750,10 +4750,13 @@ protected function define_structure() {
// Apply for 'qtype' plugins optional paths at question level
$this->add_plugin_structure('qtype', $question);

// Apply for 'qbank' plugins optional paths at question level.
$this->add_plugin_structure('qbank', $question);

// Apply for 'local' plugins optional paths at question level
$this->add_plugin_structure('local', $question);

return array($category, $question, $hint, $tag);
return [$category, $question, $hint, $tag];
}

protected function process_question_category($data) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en/role.php
Expand Up @@ -365,6 +365,8 @@
$string['question:viewmine'] = 'View your own questions';
$string['question:tagall'] = 'Tag all questions';
$string['question:tagmine'] = 'Tag your own questions';
$string['question:commentall'] = 'Comment all questions';
$string['question:commentmine'] = 'Comment your own questions';
$string['rating:rate'] = 'Add ratings to items';
$string['rating:view'] = 'View the total rating you received';
$string['rating:viewany'] = 'View total ratings that anyone received';
Expand Down
1 change: 1 addition & 0 deletions lib/classes/plugin_manager.php
Expand Up @@ -1944,6 +1944,7 @@ public static function standard_plugins_list($type) {
),

'qbank' => [
'comment',
'deletequestion',
'editquestion',
'exporttoxml',
Expand Down
7 changes: 6 additions & 1 deletion lib/questionlib.php
Expand Up @@ -387,6 +387,9 @@ function question_delete_question($questionid) {
}
}

// Delete question comments.
$DB->delete_records('comments', ['itemid' => $questionid, 'component' => 'qbank_comment',
'commentarea' => 'question']);
// Finally delete the question record itself
$DB->delete_records('question', array('id' => $questionid));
question_bank::notify_question_edited($questionid);
Expand Down Expand Up @@ -1569,7 +1572,7 @@ function question_has_capability_on($questionorid, $cap, $notused = -1) {

// These are existing questions capabilities that are set per category.
// Each of these has a 'mine' and 'all' version that is appended to the capability name.
$capabilitieswithallandmine = ['edit' => 1, 'view' => 1, 'use' => 1, 'move' => 1, 'tag' => 1];
$capabilitieswithallandmine = ['edit' => 1, 'view' => 1, 'use' => 1, 'move' => 1, 'tag' => 1, 'comment' => 1];

if (!isset($capabilitieswithallandmine[$cap])) {
return has_capability('moodle/question:' . $cap, $context);
Expand Down Expand Up @@ -1742,6 +1745,8 @@ function question_get_question_capabilities() {
'moodle/question:moveall',
'moodle/question:tagmine',
'moodle/question:tagall',
'moodle/question:commentmine',
'moodle/question:commentall',
);
}

Expand Down
2 changes: 2 additions & 0 deletions question/bank/comment/amd/build/comment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions question/bank/comment/amd/build/comment.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3be2b12

Please sign in to comment.