first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,116 @@
<?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/>.
namespace qbank_comment;
use core_question\local\bank\column_base;
use question_bank;
/**
* A column to show the number of comments.
*
* @package qbank_comment
* @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
*/
class comment_count_column extends column_base {
/**
* @var bool Comments enabled or not from config.
*/
protected $commentsenabled = true;
/**
* Load javascript module if enabled.
*
* @return void
*/
public function init(): void {
parent::init();
$this->check_comments_status();
if ($this->commentsenabled) {
global $PAGE;
$PAGE->requires->js_call_amd('qbank_comment/comment', 'init');
}
}
/**
* Check if comments is turned on in the system or not.
*/
protected function check_comments_status(): void {
global $CFG;
if (!$CFG->usecomments) {
$this->commentsenabled = false;
}
}
/**
* Get the name of the column, used internally.
*
* @return string
*/
public function get_name(): string {
return 'commentcount';
}
/**
* Get the title of the column that will be displayed.
*
* @return string
*/
public function get_title(): string {
return get_string('commentplural', 'qbank_comment');
}
/**
* Generate the content to be displayed.
*
* @param object $question The question object.
* @param string $rowclasses Classes that can be added.
*/
protected function display_content($question, $rowclasses): void {
global $DB;
$syscontext = \context_system::instance();
$args = [
'component' => 'qbank_comment',
'commentarea' => 'question',
'itemid' => $question->id,
'contextid' => $syscontext->id,
];
$commentcount = $DB->count_records('comments', $args);
$attributes = [];
if (question_has_capability_on($question, 'comment')) {
$target = 'questioncommentpreview_' . $question->id;
$attributes = [
'href' => '#',
'data-target' => $target,
'data-questionid' => $question->id,
'data-courseid' => $this->qbank->course->id,
'data-contextid' => $syscontext->id,
];
}
echo \html_writer::tag('a', $commentcount, $attributes);
}
public function get_extra_classes(): array {
return ['pr-3'];
}
public function get_default_width(): int {
return 150;
}
}
@@ -0,0 +1,51 @@
<?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/>.
namespace qbank_comment\event;
/**
* qbank_comment comment created event.
*
* @package qbank_comment
* @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
*/
class comment_created extends \core\event\comment_created {
/**
* Get URL related to the action, null in this case.
*
* @return null
*/
public function get_url() {
return null;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$a = new \stdClass();
$a->userid = $this->userid;
$a->objectid = $this->objectid;
$a->component = $this->component;
$a->itemid = $this->other['itemid'];
return get_string('comment_added', 'qbank_comment', $a);
}
}
@@ -0,0 +1,51 @@
<?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/>.
namespace qbank_comment\event;
/**
* qbank_comment comment deleted event.
*
* @package qbank_comment
* @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
*/
class comment_deleted extends \core\event\comment_deleted {
/**
* Get URL related to the action, null in this case.
*
* @return null
*/
public function get_url() {
return null;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
$a = new \stdClass();
$a->userid = $this->userid;
$a->objectid = $this->objectid;
$a->component = $this->component;
$a->itemid = $this->other['itemid'];
return get_string('comment_removed', 'qbank_comment', $a);
}
}
@@ -0,0 +1,49 @@
<?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/>.
namespace qbank_comment\event;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/comment/lib.php');
use core\event\question_deleted;
/**
* Event observer for question deletion
*
* @package qbank_comment
* @copyright 2023 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_deleted_observer {
/**
* Delete any comments for the deleted question.
*
* @param question_deleted $event
* @return void
*/
public static function delete_question_comments(question_deleted $event): void {
\comment::delete_comments([
'contextid' => \context_system::instance()->id,
'component' => 'qbank_comment',
'commentarea' => 'question',
'itemid' => $event->objectid,
]);
}
}
@@ -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/>.
namespace qbank_comment\output;
/**
* Class renderer for comment.
*
* @package qbank_comment
* @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
*/
class renderer extends \plugin_renderer_base {
/**
* Render the html fragment for comment modal.
*
* @param array $displaydata
* @return string
*/
public function render_comment_fragment($displaydata): string {
return $this->render_from_template('qbank_comment/comment_modal', $displaydata);
}
}
@@ -0,0 +1,40 @@
<?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/>.
namespace qbank_comment;
/**
* Class plugin_features is the entrypoint for the columns.
*
* @package qbank_comment
* @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
*/
class plugin_feature extends \core_question\local\bank\plugin_features_base {
/**
* Get the columns provided by this plugin.
*
* @param \core_question\local\bank\view $qbank
* @return comment_count_column[]
*/
public function get_question_columns(\core_question\local\bank\view $qbank): array {
return [
new comment_count_column($qbank)
];
}
}
@@ -0,0 +1,140 @@
<?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/>.
namespace qbank_comment\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\userlist;
use core_privacy\local\request\approved_userlist;
/**
* Privacy Subsystem for qbank_comment.
*
* @package qbank_comment
* @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
*/
class provider implements
// The qbank_comment stores user provided data.
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
// The qbank_comment provides data directly to core.
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
*
* @param collection $collection
* @return collection
*/
public static function get_metadata(collection $collection): collection {
return $collection->add_subsystem_link('core_comment', [], 'privacy:metadata:core_comment');
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid
* @return contextlist
*/
public static function get_contexts_for_userid(int $userid): contextlist {
$contextlist = new contextlist();
$sql = "SELECT contextid
FROM {comments}
WHERE component = :component
AND userid = :userid";
$params = [
'area' => 'question',
'component' => 'qbank_comment',
'userid' => $userid
];
$contextlist->add_from_sql($sql, $params);
return $contextlist;
}
/**
* Get the list of users within a specific context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
$params = [
'contextid' => $context->id,
'area' => 'question',
'component' => 'qbank_comment'
];
$sql = "SELECT userid as userid
FROM {comments}
WHERE component = :component
AND contextid = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist
*/
public static function export_user_data(approved_contextlist $contextlist) {
$contexts = $contextlist->get_contexts();
foreach ($contexts as $context) {
\core_comment\privacy\provider::export_comments(
$context,
'qbank_comment',
'question',
0,
[]
);
}
}
/**
* Delete all data for all users in the specified context.
*
* @param \context $context
*/
public static function delete_data_for_all_users_in_context(\context $context) {
\core_comment\privacy\provider::delete_comments_for_all_users($context, 'qbank_comment');
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
\core_comment\privacy\provider::delete_comments_for_users($userlist, 'qbank_comment');
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
\core_comment\privacy\provider::delete_comments_for_user($contextlist, 'qbank_comment');
}
}