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,91 @@
<?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/>.
/**
* Question bank column for the duplicate action icon.
*
* @package qbank_editquestion
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core_question\local\bank\question_action_base;
use moodle_url;
/**
* Question bank column for the duplicate action icon.
*
* @copyright 2013 The Open University
* @author 2021 Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class copy_action extends question_action_base {
/** @var string avoids repeated calls to get_string('duplicate'). */
protected $strcopy;
/**
* Contains the url of the edit question page.
* @var moodle_url|string
*/
public $duplicatequestionurl;
public function init(): void {
parent::init();
$this->strcopy = get_string('duplicate');
$this->duplicatequestionurl = new \moodle_url('/question/bank/editquestion/question.php',
array('returnurl' => $this->qbank->returnurl));
if ($this->qbank->cm !== null) {
$this->duplicatequestionurl->param('cmid', $this->qbank->cm->id);
} else {
$this->duplicatequestionurl->param('courseid', $this->qbank->course->id);
}
}
public function get_menu_position(): int {
return 250;
}
/**
* Get the URL for duplicating a question as a moodle_url.
*
* @param int $questionid the question id.
* @return \moodle_url the URL.
*/
public function duplicate_question_moodle_url($questionid): moodle_url {
return new \moodle_url($this->duplicatequestionurl, ['id' => $questionid, 'makecopy' => 1]);
}
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];
}
// To copy a question, you need permission to add a question in the same
// category as the existing question, and ability to access the details of
// the question being copied.
if (question_has_capability_on($question, 'add') &&
(question_has_capability_on($question, 'edit') || question_has_capability_on($question, 'view'))) {
return [$this->duplicate_question_moodle_url($question->id), 't/copy', $this->strcopy];
}
return [null, null, null];
}
}
@@ -0,0 +1,100 @@
<?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/>.
/**
* Class for question bank edit question column.
*
* @package qbank_editquestion
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use core_question\local\bank\question_action_base;
use moodle_url;
/**
* Class for question bank edit question column.
*
* @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 edit_action extends question_action_base {
/**
* Contains the string.
* @var string
*/
protected $stredit;
/**
* Contains the string.
* @var string
*/
protected $strview;
/**
* Contains the url of the edit question page.
* @var moodle_url|string
*/
public $editquestionurl;
public function init(): void {
parent::init();
$this->stredit = get_string('editquestion', 'question');
$this->strview = get_string('view');
$this->editquestionurl = new \moodle_url('/question/bank/editquestion/question.php',
array('returnurl' => $this->qbank->returnurl));
if ($this->qbank->cm !== null) {
$this->editquestionurl->param('cmid', $this->qbank->cm->id);
} else {
$this->editquestionurl->param('courseid', $this->qbank->course->id);
}
}
public function get_menu_position(): int {
return 200;
}
/**
* Get the URL for editing a question as a link.
*
* @param int $questionid the question id.
* @return moodle_url the URL, HTML-escaped.
*/
public function edit_question_moodle_url($questionid): moodle_url {
return new moodle_url($this->editquestionurl, ['id' => $questionid]);
}
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, 'edit')) {
return [$this->edit_question_moodle_url($question->id), 't/edit', $this->stredit];
} else if (question_has_capability_on($question, 'view')) {
return [$this->edit_question_moodle_url($question->id), 'i/info', $this->strview];
} else {
return [null, null, null];
}
}
}
@@ -0,0 +1,104 @@
<?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/>.
/**
* Helper class for adding/editing a question.
*
* This code is based on question/editlib.php by Martin Dougiamas.
*
* @package qbank_editquestion
* @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_editquestion;
use core_question\local\bank\question_version_status;
use qbank_editquestion\output\add_new_question;
/**
* Class editquestion_helper for methods related to add/edit/copy
*
* @package qbank_editquestion
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
*/
class editquestion_helper {
/**
* Print a form to let the user choose which question type to add.
* When the form is submitted, it goes to the question.php script.
*
* @param array|null $hiddenparams hidden parameters to add to the form, in addition to
* the qtype radio buttons.
* @param array|null $allowedqtypes optional list of qtypes that are allowed. If given, only
* those qtypes will be shown. Example value array('description', 'multichoice').
* @param bool $enablejs
* @return bool|string
*/
public static function print_choose_qtype_to_add_form(array $hiddenparams, array $allowedqtypes = null, $enablejs = true) {
global $PAGE;
$chooser = \qbank_editquestion\qbank_chooser::get($PAGE->course, $hiddenparams, $allowedqtypes);
$renderer = $PAGE->get_renderer('qbank_editquestion');
return $renderer->render($chooser);
}
/**
* Print a button for creating a new question. This will open question/addquestion.php,
* which in turn goes to question/question.php before getting back to $params['returnurl']
* (by default the question bank screen).
*
* @param int $categoryid The id of the category that the new question should be added to.
* @param array $params Other paramters to add to the URL. You need either $params['cmid'] or
* $params['courseid'], and you should probably set $params['returnurl']
* @param bool $canadd the text to display on the button.
* @param string $tooltip a tooltip to add to the button (optional).
* @param bool $disabled if true, the button will be disabled.
* @deprecated since Moodle 4.3. Use {@see add_new_question} renderable instead
* @todo Final deprecation in Moodle 4.7
*/
public static function create_new_question_button($categoryid, $params, $canadd, $tooltip = '', $disabled = false) {
global $OUTPUT;
debugging('create_new_question_button() is deprecated. Use the add_new_question renderable instead.');
return $OUTPUT->render(new add_new_question($categoryid, $params, $canadd));
}
/**
* Get the string for the status of the question.
*
* @param string $status
* @return string
*/
public static function get_question_status_string($status): string {
return get_string('questionstatus' . $status, 'qbank_editquestion');
}
/**
* Get the array of status of the questions.
*
* @return array
*/
public static function get_question_status_list(): array {
$statuslist = [];
$statuslist[question_version_status::QUESTION_STATUS_READY] = get_string('questionstatusready', 'qbank_editquestion');
$statuslist[question_version_status::QUESTION_STATUS_DRAFT] = get_string('questionstatusdraft', 'qbank_editquestion');
return $statuslist;
}
}
@@ -0,0 +1,114 @@
<?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_editquestion\external;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/engine/bank.php');
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use qbank_editquestion\editquestion_helper;
use question_bank;
/**
* Update question status external api.
*
* @package qbank_editquestion
* @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 update_question_version_status extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters.
*/
public static function execute_parameters() {
return new external_function_parameters([
'questionid' => new external_value(PARAM_INT, 'The question id'),
'status' => new external_value(PARAM_TEXT, 'The updated question status')
]);
}
/**
* Handles the status form submission.
*
* @param int $questionid The question id.
* @param string $status The updated question status.
* @return array The created or modified question tag
*/
public static function execute($questionid, $status) {
global $DB;
$result = [
'status' => false,
'statusname' => '',
'error' => ''
];
// Parameter validation.
$params = self::validate_parameters(self::execute_parameters(), [
'questionid' => $questionid,
'status' => $status
]);
$statuslist = editquestion_helper::get_question_status_list();
$statusexists = array_key_exists($status, $statuslist);
if (!$statusexists) {
return [
'status' => false,
'statusname' => '',
'error' => get_string('unrecognizedstatus', 'qbank_editquestion')
];
}
$question = question_bank::load_question($params['questionid']);
$editingcontext = \context::instance_by_id($question->contextid);
self::validate_context($editingcontext);
$canedit = question_has_capability_on($question, 'edit');
if ($canedit) {
$versionrecord = $DB->get_record('question_versions', ['questionid' => $params['questionid']]);
$versionrecord->status = $params['status'];
$DB->update_record('question_versions', $versionrecord);
question_bank::notify_question_edited($question->id);
$result = [
'status' => true,
'statusname' => editquestion_helper::get_question_status_string($versionrecord->status),
'error' => ''
];
$event = \core\event\question_updated::create_from_question_instance($question, $editingcontext);
$event->trigger();
}
return $result;
}
/**
* Returns description of method result value.
*/
public static function execute_returns() {
return new external_single_structure([
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'statusname' => new external_value(PARAM_RAW, 'statusname: name of the status'),
'error' => new external_value(PARAM_TEXT, 'Error message if error exists')
]);
}
}
@@ -0,0 +1,69 @@
<?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_editquestion\output;
use qbank_editquestion\editquestion_helper;
use renderer_base;
/**
* Create new question button
*
* @package qbank_editquestion
* @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 add_new_question implements \renderable, \templatable {
/** @var int $categoryid The ID of the category the quesiton will be added to. */
protected int $categoryid;
/** @var array $params URL parameters to pass to the add question form. */
protected array $params;
/** @var bool $canadd True if the add question button should be displayed. If false, a placeholder will be shown.*/
protected bool $canadd;
/**
* Store data for building the template context.
*
* @param int $categoryid
* @param array $params
* @param bool $canadd
*/
public function __construct(int $categoryid, array $params, bool $canadd) {
$this->categoryid = $categoryid;
$this->params = $params;
$this->canadd = $canadd;
}
public function export_for_template(renderer_base $output): array {
$addquestiondisplay = [];
$addquestiondisplay['canadd'] = $this->canadd;
if ($this->canadd) {
$this->params['category'] = $this->categoryid;
$url = new \moodle_url('/question/bank/editquestion/addquestion.php', $this->params);
$addquestiondisplay['buttonhtml'] = $output->single_button(
$url,
get_string('createnewquestion', 'question'),
'get',
['disabled' => 'disabled'],
);
$addquestiondisplay['qtypeform'] = editquestion_helper::print_choose_qtype_to_add_form([]);
}
return $addquestiondisplay;
}
}
@@ -0,0 +1,83 @@
<?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/>.
/**
* Renderer for adding/editing a question.
*
* This code is based on question/renderer.php by The Open University.
*
* @package qbank_editquestion
* @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_editquestion\output;
/**
* Renderer for add/edit/copy
*
* @package qbank_editquestion
* @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 a qbank_chooser.
*
* @param \renderable $qbankchooser The chooser.
* @return string
*/
public function render_qbank_chooser(\renderable $qbankchooser) {
return $this->render_from_template('qbank_editquestion/qbank_chooser', $qbankchooser->export_for_template($this));
}
/**
* Render add question button.
*
* @param array $addquestiondata
* @return bool|string
* @deprecated since Moodle 4.3. Use {@see add_new_question} renderable instead
* @todo Final deprecation in Moodle 4.7
*/
public function render_create_new_question_button($addquestiondata) {
debugging('render_create_new_question_button() is deprecated. '
. 'Pass the add_new_question renderable to render() instead.');
return $this->render_from_template('qbank_editquestion/add_new_question', $addquestiondata);
}
/**
* Render question information for edit form.
*
* @param array $questiondata
* @return bool|string
*/
public function render_question_info($questiondata) {
return $this->render_from_template('qbank_editquestion/question_info', $questiondata);
}
/**
* Render status dropdown.
*
* @param array $dropdownoptions
* @return bool|string
*/
public function render_status_dropdown($dropdownoptions) {
return $this->render_from_template('qbank_editquestion/question_status_dropdown', $dropdownoptions);
}
}
@@ -0,0 +1,74 @@
<?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_editquestion
* @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_editquestion;
use core\context;
use core_question\local\bank\view;
use qbank_editquestion\output\add_new_question;
/**
* Class columns is the entrypoint for the columns.
*
* @package qbank_editquestion
* @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 {
public function get_question_columns($qbank): array {
return [
new question_status_column($qbank),
];
}
public function get_question_actions(view $qbank): array {
return [
new edit_action($qbank),
new copy_action($qbank),
];
}
/**
* Return "Add new question" control.
*
* @param view $qbank The question bank view.
* @param context $context The current context, for permission checks.
* @param int $categoryid The current question category ID.
* @return \renderable[]
*/
public function get_question_bank_controls(view $qbank, context $context, int $categoryid): array {
if (!$qbank->allow_add_questions()) {
return [];
}
$canadd = has_capability('moodle/question:add', $context);
$urlparams = (new edit_action($qbank))->editquestionurl->params();
return [
100 => new add_new_question($categoryid, $urlparams, $canadd),
];
}
}
@@ -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/>.
/**
* Version information for qbank_editquestion.
*
* @package qbank_editquestion
* @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_editquestion\privacy;
/**
* Privacy Subsystem for qbank_editquestion 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';
}
}
@@ -0,0 +1,105 @@
<?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/>.
/**
* The qbank_chooser renderable.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use context;
use context_course;
use core\output\chooser_section;
use lang_string;
use moodle_url;
use question_bank;
use stdClass;
/**
* The qbank_chooser renderable class.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbank_chooser extends \core\output\chooser {
/**
* Constructor.
*
* @param array $real The real question types.
* @param array $fake The fake question types.
* @param stdClass $course The course.
* @param array $hiddenparams Hidden parameters.
* @param context $context The relevant context.
*/
public function __construct($real, $fake, $course, $hiddenparams, $context) {
$sections = [];
$sections[] = new chooser_section('questions', new lang_string('questions', 'question'),
array_map(function($qtype) use ($context) {
return new qbank_chooser_item($qtype, $context);
}, $real));
if (!empty($fake)) {
$sections[] = new chooser_section('other', new lang_string('other'),
array_map(function ($qtype) use ($context) {
return new qbank_chooser_item($qtype, $context);
}, $fake));
}
parent::__construct(new moodle_url('/question/bank/editquestion/question.php'),
new lang_string('chooseqtypetoadd', 'question'), $sections, 'qtype');
$this->set_instructions(new lang_string('selectaqtypefordescription', 'question'));
$this->set_method('get');
$this->add_param('courseid', $course->id);
foreach ($hiddenparams as $k => $v) {
$this->add_param($k, $v);
}
}
/**
* Get an instance of the question bank chooser.
*
* @param stdClass $course The course.
* @param array $hiddenparams Hidden parameters.
* @param array|null $allowedqtypes Allowed question types.
* @return qbank_chooser
*/
public static function get($course, $hiddenparams, array $allowedqtypes = null): qbank_chooser {
$realqtypes = array();
$fakeqtypes = array();
foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) {
if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) {
continue;
}
if ($qtype->is_real_question_type()) {
$realqtypes[] = $qtype;
} else {
$fakeqtypes[] = $qtype;
}
}
return new static($realqtypes, $fakeqtypes, $course, $hiddenparams, context_course::instance($course->id));
}
}
@@ -0,0 +1,55 @@
<?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/>.
/**
* The qbank_chooser_item renderable.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qbank_editquestion;
use context;
use lang_string;
use pix_icon;
/**
* The qbank_chooser_item renderable class.
*
* @package qbank_editquestion
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbank_chooser_item extends \core\output\chooser_item {
/**
* Constructor.
*
* @param object $qtype The question type.
* @param context $context The relevant context.
*/
public function __construct($qtype, $context) {
$icon = new pix_icon('icon', $qtype->local_name(), $qtype->plugin_name(), [
'class' => 'icon',
'title' => $qtype->local_name()
]);
$help = new lang_string('pluginnamesummary', $qtype->plugin_name());
parent::__construct($qtype->plugin_name(), $qtype->menu_name(), $qtype->name(), $icon, $help, $context);
}
}
@@ -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_editquestion;
use core_question\local\bank\column_base;
use core_question\local\bank\question_version_status;
/**
* A column to show the status of the question.
*
* @package qbank_editquestion
* @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 question_status_column extends column_base {
public function get_name(): string {
return 'questionstatus';
}
public function get_title(): string {
return get_string('questionstatus', 'qbank_editquestion');
}
protected function display_content($question, $rowclasses): void {
global $PAGE;
$attributes = [];
if (question_has_capability_on($question, 'edit')
&& $question->status !== question_version_status::QUESTION_STATUS_HIDDEN) {
$options = [];
$options['questionid'] = $question->id;
$statuslist = editquestion_helper::get_question_status_list();
foreach ($statuslist as $value => $displaystatus) {
$options['options'][] = [
'name' => $displaystatus,
'value' => $value,
'selected' => ($question->status) === $value ? true : false
];
}
echo $PAGE->get_renderer('qbank_editquestion')->render_status_dropdown($options);
$PAGE->requires->js_call_amd('qbank_editquestion/question_status', 'init', [$question->id]);
}
}
public function get_extra_classes(): array {
return ['pr-3'];
}
}