Commit 891750bc authored by Frederic Massart's avatar Frederic Massart Committed by Dan Poltawski
Browse files

MDL-55797 core_question: Make static getter for chooser

Part of MDL-55071
parent 7f8b7b2b
......@@ -25,9 +25,11 @@
namespace core_question\output;
defined('MOODLE_INTERNAL') || die();
use context_course;
use core\output\chooser_section;
use lang_string;
use moodle_url;
use question_bank;
/**
......@@ -41,6 +43,12 @@ 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 = [];
......@@ -66,4 +74,30 @@ class qbank_chooser extends \core\output\chooser {
}
}
/**
* 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) {
$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));
}
}
......@@ -450,21 +450,10 @@ function require_login_in_context($contextorid = null){
function print_choose_qtype_to_add_form($hiddenparams, array $allowedqtypes = null, $enablejs = true) {
global $CFG, $PAGE, $OUTPUT;
$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;
}
}
$chooser = core_question\output\qbank_chooser::get($PAGE->course, $hiddenparams, $allowedqtypes);
$renderer = $PAGE->get_renderer('question', 'bank');
return $renderer->qbank_chooser($realqtypes, $fakeqtypes, $PAGE->course, $hiddenparams);
return $renderer->render($chooser);
}
/**
......
......@@ -68,9 +68,9 @@ class core_question_bank_renderer extends plugin_renderer_base {
* @return string The composed HTML for the questionbank chooser
*/
public function qbank_chooser($real, $fake, $course, $hiddenparams) {
$chooser = new \core_question\output\qbank_chooser($real, $fake, $course, $hiddenparams,
context_course::instance($course->id));
return $this->render($chooser);
debugging('Method core_question_bank_renderer::qbank_chooser() is deprecated, ' .
'see core_question_bank_renderer::render_qbank_chooser().', DEBUG_DEVELOPER);
return '';
}
/**
......
This files describes API changes for code that uses the question API.
=== 3.2 ===
1) The following renderers have been deprecated in favour of the renderable
core_question\output\qbank_chooser and associated render_* method.
* qbank_chooser
* qbank_chooser_types
* qbank_chooser_qtype
* qbank_chooser_title
=== 3.1 ===
1) The argument $requirecourseid was removed from question_edit_setup() and
......
......@@ -35,6 +35,12 @@ Removed themes:
- course_modchooser_module_types
- course_modchooser_module
- course_modchooser_title
* The question chooser now uses a renderable and a template, the following methods
have been deprecated in favour of core_question_bank_renderer::render_qbank_chooser().
- qbank_chooser
- qbank_chooser_types
- qbank_chooser_qtype
- qbank_chooser_title
=== 3.1 ===
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment