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,46 @@
<?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_deletequestion;
/**
* Class bulk_delete_action is the base class for delete bulk actions ui.
*
* @package qbank_deletequestion
* @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 bulk_delete_action extends \core_question\local\bank\bulk_action_base {
public function get_bulk_action_title(): string {
return get_string('delete');
}
public function get_key(): string {
return 'deleteselected';
}
public function get_bulk_action_url(): \moodle_url {
return new \moodle_url('/question/bank/deletequestion/delete.php');
}
public function get_bulk_action_capabilities(): ?array {
return [
'moodle/question:editall',
];
}
}
@@ -0,0 +1,106 @@
<?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/>.
/**
* Action to delete (or hide) a question, or restore a previously hidden question.
*
* @package qbank_deletequestion
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_deletequestion;
use core_question\local\bank\question_version_status;
use core_question\local\bank\question_action_base;
/**
* Action to delete (or hide) a question, or restore a previously hidden question.
*
* @package qbank_deletequestion
* @copyright 2009 Tim Hunt
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_action extends question_action_base {
/**
* @var string $strdelete
*/
protected $strdelete;
/**
* @var string $strrestore
*/
protected $strrestore;
/**
* Contains the url of the delete question page.
* @var \moodle_url|string
*/
public $deletequestionurl;
/**
* Array of the return parameters.
* @var array $returnparams
*/
protected $returnparams;
public function init(): void {
parent::init();
$this->strdelete = get_string('delete');
$this->strrestore = get_string('restore');
$this->deletequestionurl = new \moodle_url('/question/bank/deletequestion/delete.php');
if (!empty($this->qbank->cm->id)) {
$this->returnparams['cmid'] = $this->qbank->cm->id;
}
if (!empty($this->qbank->course->id)) {
$this->returnparams['courseid'] = $this->qbank->course->id;
}
if (!empty($this->qbank->returnurl)) {
$this->returnparams['returnurl'] = $this->qbank->returnurl;
}
}
public function get_menu_position(): int {
return 400;
}
protected function get_url_icon_and_label(\stdClass $question): array {
if (!question_has_capability_on($question, 'edit')) {
return [null, null, null];
}
if ($question->status === question_version_status::QUESTION_STATUS_HIDDEN) {
$hiddenparams = array(
'unhide' => $question->id,
'sesskey' => sesskey());
$hiddenparams = array_merge($hiddenparams, $this->returnparams);
$url = new \moodle_url($this->deletequestionurl, $hiddenparams);
return [$url, 't/restore', $this->strrestore];
} else {
$deleteparams = array(
'deleteselected' => $question->id,
'q' . $question->id => 1,
'sesskey' => sesskey());
$deleteparams = array_merge($deleteparams, $this->returnparams);
if ($this->qbank->base_url()->get_param('deleteall')) {
$deleteparams['deleteall'] = 1;
}
$url = new \moodle_url($this->deletequestionurl, $deleteparams);
return [$url, 't/delete', $this->strdelete];
}
}
}
@@ -0,0 +1,122 @@
<?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_deletequestion;
/**
* Class helper of qbank_deletequestion.
*
* @package qbank_deletequestion
* @copyright 2023 The Open University
* @since Moodle 4.2
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class helper {
/**
* Get the confirmation message of delete question.
*
* @param array $questionids List of id questions.
* @param bool $deleteallversions Delete all question version or not.
* @return array List confirmation message.
*/
public static function get_delete_confirmation_message(array $questionids, bool $deleteallversions): array {
global $DB;
$questionnames = '';
$inuse = false;
$questionversions = [];
$countselectedquestion = count($questionids);
if ($deleteallversions) {
$versionsofeachquestionbankentry = \question_bank::get_all_versions_of_questions($questionids);
foreach ($versionsofeachquestionbankentry as $entryid => $versions) {
// Re-order to oldest first.
$versionsofeachquestionbankentry[$entryid] = array_reverse($versions, true);
// Flip the array to list question by question id. [ qid => version ].
$questionversions += array_flip($versions);
}
// Flatten an array.
$questionids = array_merge(...$versionsofeachquestionbankentry);
}
// Get the names of all the questions.
$questions = $DB->get_records_list('question', 'id', $questionids, '', 'id, name');
// Build the message.
foreach ($questionids as $questionid) {
if (questions_in_use([$questionid])) {
$questionnames .= '* ';
$inuse = true;
}
$questionname = format_string($questions[$questionid]->name);
if (isset($questionversions[$questionid])) {
$a = new \stdClass();
$a->name = $questionname;
$a->version = $questionversions[$questionid];
$questionnames .= get_string('questionnameandquestionversion',
'question', $a) . '<br />';
} else {
$questionnames .= $questionname . '<br />';
}
}
// Add the in-use message if required.
if ($inuse) {
$questionnames .= '<br />'.get_string('questionsinuse', 'question');
}
// Add in the right tile and message text.
$confirmtitle = [
'confirmtitle' => $countselectedquestion > 1 ? get_string('deleteversiontitle_plural',
'question') : get_string('deleteversiontitle', 'question'),
];
$message = get_string('deleteselectedquestioncheck', 'question', $questionnames);
if ($deleteallversions) {
$confirmtitle = [
'confirmtitle' => get_string('deletequestiontitle', 'question'),
];
$message = get_string('deletequestioncheck', 'question', $questionnames);
if ($countselectedquestion > 1) {
$confirmtitle = [
'confirmtitle' => get_string('deletequestiontitle_plural', 'question'),
];
$message = get_string('deletequestionscheck', 'question', $questionnames);
}
}
return [$confirmtitle, $message];
}
/**
* Delete questions has (single/multiple) version.
*
* @param array $questionids List of questionid.
* @param bool $deleteallversions Delete all question version or not.
*/
public static function delete_questions(array $questionids, bool $deleteallversions): void {
if ($deleteallversions) {
// Get all the question id from multidimensional array.
$listofquestions = \question_bank::get_all_versions_of_questions($questionids);
// Flatten an array.
$questionids = array_merge(...$listofquestions);
}
foreach ($questionids as $questionid) {
$questionid = (int) $questionid;
question_require_capability_on($questionid, 'edit');
question_delete_question($questionid);
}
}
}
@@ -0,0 +1,72 @@
<?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_deletequestion;
use core\output\datafilter;
use core_question\local\bank\condition;
use core_question\local\bank\question_version_status;
/**
* This class controls whether hidden / deleted questions are hidden in the list.
*
* @package qbank_deletequestion
* @copyright 2013 Ray Morris
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hidden_condition extends condition {
public static function get_condition_key() {
return 'hidden';
}
/**
* Build query from filter value
*
* @param array $filter filter properties
* @return array where sql and params
*/
public static function build_query_from_filter(array $filter): array {
$showhidden = (bool)$filter['values'][0];
$where = "";
$params = [];
if (!$showhidden) {
$where = "qv.status <> :hidden_condition";
$params = ['hidden_condition' => question_version_status::QUESTION_STATUS_HIDDEN];
}
return [$where, $params];
}
public function get_title() {
return get_string('showhidden', 'core_question');
}
public function get_join_list(): array {
return [
datafilter::JOINTYPE_ANY,
];
}
public function get_filter_class() {
return 'qbank_deletequestion/datafilter/filtertypes/hidden';
}
public function is_required(): bool {
return true;
}
}
@@ -0,0 +1,58 @@
<?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/>.
/**
* Plugin entrypoint for columns.
*
* @package qbank_deletequestion
* @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
*/
namespace qbank_deletequestion;
use core_question\local\bank\bulk_action_base;
use core_question\local\bank\plugin_features_base;
use core_question\local\bank\view;
/**
* Class columns is the entrypoint for the columns.
*
* @package qbank_deletequestion
* @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 plugin_features_base {
public function get_question_actions($qbank): array {
return [
new delete_action($qbank),
];
}
public function get_bulk_actions(): array {
return [
new bulk_delete_action(),
];
}
public function get_question_filters(view $qbank = null): array {
return [
new hidden_condition($qbank),
];
}
}
@@ -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/>.
/**
* Version information for qbank_deletequestion.
*
* @package qbank_deletequestion
* @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
*/
namespace qbank_deletequestion\privacy;
/**
* Privacy Subsystem for qbank_deletequestion implementing null_provider.
*
* @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 \core_privacy\local\metadata\null_provider {
public static function get_reason(): string {
return 'privacy:metadata';
}
}