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,79 @@
<?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_viewquestiontext\external;
use context_system;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use qbank_viewquestiontext\output\question_text_format;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/editlib.php');
/**
* External function for setting the question text format.
*
* @package qbank_viewquestiontext
* @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 set_question_text_format extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'format' => new external_value(PARAM_INT, 'Format for the question text', VALUE_REQUIRED),
]);
}
/**
* Returns description of method result value.
*/
public static function execute_returns(): void {
}
/**
* Save the question text format preference for the current user.
*
* @param int $format Format for the question text.
*/
public static function execute(int $format): void {
[
'format' => $format,
] = self::validate_parameters(
self::execute_parameters(),
[
'format' => $format,
]
);
if (!in_array($format, [question_text_format::OFF, question_text_format::PLAIN, question_text_format::FULL])) {
throw new \invalid_parameter_exception('$format must be one of question_text_format::OFF, ::PLAIN or ::FULL.');
}
$context = context_system::instance();
self::validate_context($context);
\question_set_or_get_user_preference('qbshowtext', $format, 0, new \moodle_url('/'));
}
}
@@ -0,0 +1,92 @@
<?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_viewquestiontext\output;
use core_question\local\bank\view;
use qbank_viewquestiontext\question_text_row;
use renderer_base;
/**
* Question text format selector.
*
* @package qbank_viewquestiontext
* @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_text_format implements \renderable, \templatable {
/**
* @var int Question text is off.
*/
const OFF = 0;
/**
* @var int Question text is displayed in plain text mode.
*/
const PLAIN = 1;
/**
* @var int Question text is displayed fully rendered.
*/
const FULL = 2;
/** @var int|mixed The current display preference value. */
protected int $preference;
/**
* @var \moodle_url The return URL for redirecting back to the current question bank page.
*/
protected \moodle_url $returnurl;
/**
* Store the returnurl and the current preference value.
*
* @param view $qbank
* @throws \moodle_exception
*/
public function __construct(view $qbank) {
$row = new question_text_row($qbank);
$this->returnurl = new \moodle_url($qbank->returnurl);
$this->preference = question_get_display_preference($row->get_preference_key(), 0, PARAM_INT, new \moodle_url(''));
}
public function export_for_template(renderer_base $output): array {
return [
'formaction' => new \moodle_url('/question/bank/viewquestiontext/save.php'),
'sesskey' => sesskey(),
'returnurl' => $this->returnurl->out(false),
'options' => [
(object)[
'label' => get_string('showquestiontext_off', 'question'),
'value' => self::OFF,
'selected' => $this->preference === self::OFF,
],
(object)[
'label' => get_string('showquestiontext_plain', 'question'),
'value' => self::PLAIN,
'selected' => $this->preference === self::PLAIN,
],
(object)[
'label' => get_string('showquestiontext_full', 'question'),
'value' => self::FULL,
'selected' => $this->preference === self::FULL,
],
],
'label' => get_string('showquestiontext', 'core_question'),
];
}
}
@@ -0,0 +1,57 @@
<?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_viewquestiontext;
use core\context;
use core_question\local\bank\plugin_features_base;
use core_question\local\bank\view;
use qbank_viewquestiontext\output\question_text_format;
/**
* Class columns is the entrypoint for the columns.
*
* @package qbank_viewquestiontext
* @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 {
/**
* Return an additional row for displaying the question text, if user has a preference set to display it.
*
* @param view $qbank
* @return array
*/
public function get_question_columns(view $qbank): array {
$row = new question_text_row($qbank);
$preference = (int)question_get_display_preference($row->get_preference_key(), '0', PARAM_INT, new \moodle_url('/'));
if ($preference != question_text_format::OFF) {
return [
$row,
];
}
return [];
}
public function get_question_bank_controls(view $qbank, context $context, int $categoryid): array {
return [
400 => new question_text_format($qbank),
];
}
}
@@ -0,0 +1,32 @@
<?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_viewquestiontext\privacy;
/**
* Privacy Subsystem for qbank_viewquestiontext implementing null_provider.
*
* @package qbank_viewquestiontext
* @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';
}
}
@@ -0,0 +1,88 @@
<?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_viewquestiontext;
use core_question\local\bank\row_base;
use qbank_viewquestiontext\output\question_text_format;
use question_utils;
/**
* A column type for the name of the question name.
*
* @package qbank_viewquestiontext
* @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 question_text_row extends row_base {
/** @var int if true, we will show the question text reduced to plain text, else it is fully rendered. */
protected $preference;
/** @var \stdClass $formatoptions options used when displaying the question text as HTML. */
protected $formatoptions;
protected function init(): void {
// Cannot use $this->get_preference because of PHP type hints.
$this->preference = (int)question_get_display_preference($this->get_preference_key(), 0, PARAM_INT, new \moodle_url(''));
$this->formatoptions = new \stdClass();
$this->formatoptions->noclean = true;
$this->formatoptions->para = false;
}
public function get_name(): string {
return 'questiontext';
}
public function get_title(): string {
return get_string('questiontext', 'question');
}
protected function display_content($question, $rowclasses): void {
// Access 'showtext' filter from pagevars.
if ($this->preference !== question_text_format::OFF) {
$text = '';
if ($this->preference === question_text_format::PLAIN) {
$text = s(question_utils::to_plain_text($question->questiontext,
$question->questiontextformat, ['noclean' => true, 'para' => false, 'filter' => false]));
} else if ($this->preference === question_text_format::FULL) {
$text = question_rewrite_question_preview_urls($question->questiontext, $question->id,
$question->contextid, 'question', 'questiontext', $question->id,
$question->contextid, 'core_question');
$text = format_text($text, $question->questiontextformat,
$this->formatoptions);
}
if ($text == '') {
$text = '&#160;';
}
echo $text;
}
}
public function get_required_fields(): array {
return ['q.questiontext', 'q.questiontextformat'];
}
public function has_preference(): bool {
return false;
}
public function get_preference_key(): string {
return 'qbshowtext';
}
}