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
+51
View File
@@ -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_history;
/**
* Helper class for question history.
*
* @package qbank_history
* @copyright 2022 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 helper {
/**
* Get the question history url.
*
* @param int $entryid id of the question entry
* @param string $returnrul url of the page to return to
* @param int $courseid id of the course
* @param ?string $filter filter param to pass to the History view
* @return \moodle_url
*/
public static function question_history_url(int $entryid, string $returnrul, int $courseid, ?string $filter): \moodle_url {
$params = [
'entryid' => $entryid,
'returnurl' => $returnrul,
'courseid' => $courseid
];
if (!is_null($filter)) {
$params['filter'] = $filter;
}
return new \moodle_url('/question/bank/history/history.php', $params);
}
}
@@ -0,0 +1,64 @@
<?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_history;
use core_question\local\bank\question_action_base;
/**
* Question bank column for the history action icon.
*
* @package qbank_history
* @copyright 2022 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 history_action extends question_action_base {
// Store this lang string for performance.
protected $strpreview;
public function init(): void {
parent::init();
$this->strpreview = get_string('history_action', 'qbank_history');
}
public function get_menu_position(): int {
return 500;
}
protected function get_url_icon_and_label(\stdClass $question): array {
if (!\question_bank::is_qtype_installed($question->qtype)) {
// It sometimes happens that people end up with junk questions
// in their question bank of a type that is no longer installed.
// We cannot do most actions on them, because that leads to errors.
return [null, null, null];
}
if (question_has_capability_on($question, 'use')) {
$url = helper::question_history_url(
$question->questionbankentryid,
$this->qbank->returnurl,
$this->qbank->course->id,
$this->qbank->base_url()->param('filter'),
);
return [$url, 't/log', $this->strpreview];
}
return [null, null, null];
}
}
@@ -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/>.
namespace qbank_history\output;
/**
* Class renderer for rendering question history.
*
* @package qbank_history
* @copyright 2022 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 history header.
*
* @param array $historydata data to be passed in the mustache
* @return string
*/
public function render_history_header(array $historydata): string {
return $this->render_from_template('qbank_history/history_header', $historydata);
}
}
@@ -0,0 +1,43 @@
<?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_history;
use core_question\local\bank\view;
/**
* Class plugin_feature is the entrypoint for the columns.
*
* @package qbank_history
* @copyright 2022 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 {
public function get_question_columns($qbank): array {
return [
new version_number_column($qbank),
];
}
public function get_question_actions(view $qbank): array {
return [
new history_action($qbank),
];
}
}
@@ -0,0 +1,33 @@
<?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_history\privacy;
/**
* Privacy Subsystem for qbank_history implementing null_provider.
*
* @package qbank_history
* @copyright 2022 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 \core_privacy\local\metadata\null_provider {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
@@ -0,0 +1,191 @@
<?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_history;
use core_question\local\bank\question_edit_contexts;
use core_question\local\bank\view;
use moodle_url;
use stdClass;
/**
* Custom view class for the history page.
*
* @package qbank_history
* @copyright 2022 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 question_history_view extends view {
/**
* Entry id to get the versions
*
* @var int $entryid
*/
protected $entryid;
/**
* Base url for the return.
*
* @var \moodle_url $basereturnurl
*/
protected $basereturnurl;
/**
* Constructor for the history.
* @param question_edit_contexts $contexts the contexts of api call
* @param moodle_url $pageurl url of the page
* @param stdClass $course course settings
* @param stdClass|null $cm (optional) activity settings.
* @param array $params the parameters required to initialize the api.
* @param array $extraparams any extra parameters need to initialized if the api is extended, it will be passed to js.
* @throws \moodle_exception
*/
public function __construct(
question_edit_contexts $contexts,
moodle_url $pageurl,
stdClass $course,
stdClass $cm = null,
array $params = [],
array $extraparams = [],
) {
$this->entryid = $extraparams['entryid'];
$this->basereturnurl = new \moodle_url($extraparams['returnurl']);
parent::__construct($contexts, $pageurl, $course, $cm, $params, $extraparams);
}
protected function init_question_actions(): void {
parent::init_question_actions();
unset($this->questionactions['qbank_history\history_action']);
}
protected function wanted_columns(): array {
$this->requiredcolumns = [];
$questionbankcolumns = $this->get_question_bank_plugins();
foreach ($questionbankcolumns as $classobject) {
if (empty($classobject)) {
continue;
}
$this->requiredcolumns[$classobject->get_column_name()] = $classobject;
}
return $this->requiredcolumns;
}
protected function display_advanced_search_form($advancedsearch): void {
foreach ($advancedsearch as $searchcondition) {
echo $searchcondition->display_options_adv();
}
}
public function allow_add_questions(): bool {
// As we dont want to create questions in this page.
return false;
}
/**
* Default sort for question data.
* @return array
*/
protected function default_sort(): array {
$defaultsort = [];
if (class_exists('\\qbank_viewcreator\\creator_name_column')) {
$sort = 'qbank_viewcreator\creator_name_column-timecreated';
}
$defaultsort[$sort] = 1;
return $defaultsort;
}
protected function build_query(): void {
// Get the required tables and fields.
[$fields, $joins] = $this->get_component_requirements(array_merge($this->requiredcolumns, $this->questionactions));
// Build the order by clause.
$sorts = [];
foreach ($this->sort as $sortname => $sortorder) {
list($colname, $subsort) = $this->parse_subsort($sortname);
$sorts[] = $this->requiredcolumns[$colname]->sort_expression($sortorder == SORT_DESC, $subsort);
}
// Build the where clause.
$entryid = "qbe.id = $this->entryid";
// Changes done here to get the questions only for the passed entryid.
$tests = ['q.parent = 0', $entryid];
$this->sqlparams = [];
foreach ($this->searchconditions as $searchcondition) {
if ($searchcondition->where()) {
$tests[] = '((' . $searchcondition->where() .'))';
}
if ($searchcondition->params()) {
$this->sqlparams = array_merge($this->sqlparams, $searchcondition->params());
}
}
// Build the SQL.
$sql = ' FROM {question} q ' . implode(' ', $joins);
$sql .= ' WHERE ' . implode(' AND ', $tests);
$this->countsql = 'SELECT count(1)' . $sql;
$this->loadsql = 'SELECT ' . implode(', ', $fields) . $sql . ' ORDER BY ' . implode(', ', $sorts);
}
/**
* Display the header for the question bank in the history page to include question name and type.
*/
public function display_question_bank_header(): void {
global $PAGE, $DB, $OUTPUT;
$sql = 'SELECT q.*
FROM {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
WHERE qv.version = (SELECT MAX(v.version)
FROM {question_versions} v
JOIN {question_bank_entries} be
ON be.id = v.questionbankentryid
WHERE be.id = qbe.id)
AND qbe.id = ?';
$latestquestiondata = $DB->get_record_sql($sql, [$this->entryid]);
if ($latestquestiondata) {
$historydata = [
'questionname' => $latestquestiondata->name,
'returnurl' => $this->basereturnurl,
'questionicon' => print_question_icon($latestquestiondata)
];
// Header for the page before the actual form from the api.
echo $PAGE->get_renderer('qbank_history')->render_history_header($historydata);
} else {
// Continue when all the question versions are deleted.
echo $OUTPUT->notification(get_string('allquestionversionsdeleted', 'qbank_history'), 'notifysuccess');
echo $OUTPUT->continue_button($this->basereturnurl);
}
}
public function is_listing_specific_versions(): bool {
return true;
}
/**
* Override wanted_filters so that we apply the filters provided by the URL, but don't display the filter UI.
*
* @return void
*/
public function wanted_filters(): void {
$this->display_question_bank_header();
// Add search conditions.
$this->add_standard_search_conditions();
}
}
@@ -0,0 +1,47 @@
<?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_history;
use core_question\local\bank\column_base;
/**
* Question bank column for the question version number.
*
* @package qbank_history
* @copyright 2022 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 version_number_column extends column_base {
public function get_name(): string {
return 'questionversionnumber';
}
public function get_title(): string {
return get_string('questionversionnumber', 'qbank_history');
}
protected function display_content($question, $rowclasses): void {
print_string('questionversiondata', 'qbank_history', $question->version);
}
public function get_extra_classes(): array {
return ['pr-3'];
}
}