MDL-40313 question bank search classes should be namespaced.

This commit is contained in:
Tim Hunt 2014-01-09 12:43:56 +00:00
parent e22e749002
commit d62382d1f9
6 changed files with 54 additions and 49 deletions

View File

@ -1188,9 +1188,9 @@ class quiz_question_bank_view extends question_bank_view {
$editcontexts = $this->contexts->having_one_edit_tab_cap($tabname);
array_unshift($this->searchconditions,
new question_bank_search_condition_hide(!$showhidden));
new \core_question\bank\search\hidden_condition(!$showhidden));
array_unshift($this->searchconditions,
new question_bank_search_condition_category($cat, $recurse,
new \core_question\bank\search\category_condition($cat, $recurse,
$editcontexts, $this->baseurl, $this->course, self::MAX_TEXT_LENGTH));
echo $OUTPUT->box_start('generalbox questionbank');
@ -1209,13 +1209,13 @@ class quiz_question_bank_view extends question_bank_view {
* prints a form to choose categories
* @param string $categoryandcontext 'categoryID,contextID'.
* @deprecated since Moodle 2.6 MDL-40313.
* @see question_bank_search_condition_category
* @see \core_question\bank\search\category_condition
* @todo MDL-41978 This will be deleted in Moodle 2.8
*/
protected function print_choose_category_message($categoryandcontext) {
global $OUTPUT;
debugging('print_choose_category_message() is deprecated, ' .
'please use question_bank_search_condition_category instead.', DEBUG_DEVELOPER);
'please use \core_question\bank\search\category_condition instead.', DEBUG_DEVELOPER);
echo $OUTPUT->box_start('generalbox questionbank');
$this->display_category_form($this->contexts->having_one_edit_tab_cap('edit'),
$this->baseurl, $categoryandcontext);

View File

@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_question\bank\search;
defined('MOODLE_INTERNAL') || die();
/**
@ -31,11 +32,11 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Ray Morris
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_question_bank_search_condition_category extends core_question_bank_search_condition {
/** @var stdClass The course record. */
class category_condition extends condition {
/** @var \stdClass The course record. */
protected $course;
/** @var stdClass The category record. */
/** @var \stdClass The category record. */
protected $category;
/** @var array of contexts. */
@ -61,8 +62,8 @@ class core_question_bank_search_condition_category extends core_question_bank_se
* @param string $cat categoryID,contextID as used with question_bank_view->display()
* @param bool $recurse Whether to include questions from sub-categories
* @param array $contexts Context objects as used by question_category_options()
* @param moodle_url $baseurl The URL the form is submitted to
* @param stdClass $course Course record
* @param \moodle_url $baseurl The URL the form is submitted to
* @param \stdClass $course Course record
* @param integer $maxinfolength The maximum displayed length of the category info.
*/
public function __construct($cat = null, $recurse = false, $contexts, $baseurl, $course, $maxinfolength = null) {
@ -113,38 +114,36 @@ class core_question_bank_search_condition_category extends core_question_bank_se
* question_bank_view places this within the section that is hidden by default
*/
public function display_options_adv() {
echo '<div>';
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'recurse',
echo \html_writer::start_div();
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'recurse',
'value' => 0, 'id' => 'recurse_off'));
echo html_writer::checkbox('recurse', '1', $this->recurse, get_string('includesubcategories', 'question'),
echo \html_writer::checkbox('recurse', '1', $this->recurse, get_string('includesubcategories', 'question'),
array('id' => 'recurse_on', 'class' => 'searchoptions'));
echo "</div>\n";
echo \html_writer::end_div() . "\n";
}
/**
* Display the drop down to select the category.
*
* @param array $contexts of contexts that can be accessed from here.
* @param moodle_url $pageurl the URL of this page.
* @param \moodle_url $pageurl the URL of this page.
* @param string $current 'categoryID,contextID'.
*/
protected function display_category_form($contexts, $pageurl, $current) {
global $OUTPUT;
echo '<div class="choosecategory">';
echo \html_writer::start_div('choosecategory');
$catmenu = question_category_options($contexts, false, 0, true);
$select = new single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu');
$select = new \single_select($this->baseurl, 'category', $catmenu, $current, null, 'catmenu');
$select->set_label(get_string('selectacategory', 'question'));
echo $OUTPUT->render($select);
echo "</div>\n";
echo \html_writer::end_div() . "\n";
}
/**
* Look up the category record based on cateogry ID and context
* @param string $categoryandcontext categoryID,contextID as used with question_bank_view->display()
* @return stdClass The category record
* @return \stdClass The category record
*/
protected function get_current_category($categoryandcontext) {
global $DB, $OUTPUT;
@ -170,18 +169,16 @@ class core_question_bank_search_condition_category extends core_question_bank_se
* @param stdClass $category the category information form the database.
*/
protected function print_category_info($category) {
$formatoptions = new stdClass();
$formatoptions = new \stdClass();
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
echo '<div class="boxaligncenter categoryinfo">';
echo \html_writer::start_div('boxaligncenter categoryinfo');
if (isset($this->maxinfolength)) {
echo shorten_text(format_text($category->info, $category->infoformat, $formatoptions, $this->course->id),
$this->maxinfolength);
} else {
echo format_text($category->info, $category->infoformat, $formatoptions, $this->course->id);
}
echo "</div>\n";
echo \html_writer::end_div() . "\n";
}
}

View File

@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_question\bank\search;
defined('MOODLE_INTERNAL') || die();
/**
@ -32,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Ray Morris
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class core_question_bank_search_condition {
abstract class condition {
/**
* Return an SQL fragment to be ANDed into the WHERE clause to filter which questions are shown.
* @return string SQL fragment. Must use named parameters.

View File

@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_question\bank\search;
defined('MOODLE_INTERNAL') || die();
/**
@ -31,7 +32,7 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2013 Ray Morris
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_question_bank_search_condition_hide extends core_question_bank_search_condition {
class hidden_condition extends condition {
/** @var bool Whether to include old "deleted" questions. */
protected $hide;
@ -57,11 +58,11 @@ class core_question_bank_search_condition_hide extends core_question_bank_search
* Print HTML to display the "Also show old questions" checkbox
*/
public function display_options_adv() {
echo "<div>";
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showhidden',
echo \html_writer::start_div();
echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showhidden',
'value' => '0', 'id' => 'showhidden_off'));
echo html_writer::checkbox('showhidden', '1', (! $this->hide), get_string('showhidden', 'question'),
echo \html_writer::checkbox('showhidden', '1', (! $this->hide), get_string('showhidden', 'question'),
array('id' => 'showhidden_on', 'class' => 'searchoptions'));
echo "</div>\n";
echo \html_writer::end_div() . "\n";
}
}

View File

@ -24,6 +24,8 @@
*/
use core_question\bank\search\category_condition;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/questionlib.php');
@ -942,7 +944,8 @@ class question_bank_view {
/**
* Initialize search conditions from plugins
* local_*_get_question_bank_search_conditions() must return an array of core_question_bank_search_condition objects
* local_*_get_question_bank_search_conditions() must return an array of
* \core_question\bank\search\condition objects.
*/
protected function init_search_conditions() {
$searchplugins = get_plugin_list_with_function('local', 'get_question_bank_search_conditions');
@ -1164,17 +1167,18 @@ class question_bank_view {
* @param bool $showhidden no longer used.
* @deprecated since Moodle 2.7 MDL-40313.
* @see build_query()
* @see question_bank_search_condition
* @see \core_question\bank\search\condition
* @todo MDL-41978 This will be deleted in Moodle 2.8
*/
protected function build_query_sql($category, $recurse, $showhidden) {
debugging('build_query_sql() is deprecated, please use question_bank_view::build_query() and core_question_bank_search_condition" .
classes instead.', DEBUG_DEVELOPER);
debugging('build_query_sql() is deprecated, please use question_bank_view::build_query() and ' .
'\core_question\bank\search\condition classes instead.', DEBUG_DEVELOPER);
self::build_query();
}
/**
* Create the SQL query to retrieve the indicated questions, based on core_question_bank_search_condition filters
* Create the SQL query to retrieve the indicated questions, based on
* \core_question\bank\search\condition filters.
*/
protected function build_query() {
global $DB;
@ -1280,9 +1284,9 @@ class question_bank_view {
$editcontexts = $this->contexts->having_one_edit_tab_cap($tabname);
// Category selection form
echo $OUTPUT->heading(get_string('questionbank', 'question'), 2);
array_unshift($this->searchconditions, new core_question_bank_search_condition_hide(!$showhidden));
array_unshift($this->searchconditions, new core_question_bank_search_condition_category($cat, $recurse, $editcontexts,
$this->baseurl, $this->course));
array_unshift($this->searchconditions, new \core_question\bank\search\hidden_condition(!$showhidden));
array_unshift($this->searchconditions, new \core_question\bank\search\category_condition(
$cat, $recurse, $editcontexts, $this->baseurl, $this->course));
$this->display_options_form($showquestiontext);
// continues with list of questions
@ -1321,7 +1325,7 @@ class question_bank_view {
* prints category information
* @param stdClass $category the category row from the database.
* @deprecated since Moodle 2.7 MDL-40313.
* @see core_question_bank_search_condition_category
* @see \core_question\bank\search\condition
* @todo MDL-41978 This will be deleted in Moodle 2.8
*/
protected function print_category_info($category) {
@ -1336,13 +1340,14 @@ class question_bank_view {
/**
* Prints a form to choose categories
* @deprecated since Moodle 2.7 MDL-40313.
* @see core_question_bank_search_condition_category
* @see \core_question\bank\search\condition
* @todo MDL-41978 This will be deleted in Moodle 2.8
*/
protected function display_category_form($contexts, $pageurl, $current) {
global $OUTPUT;
debugging('display_category_form() is deprecated, please use core_question_bank_search_condition_category instead.', DEBUG_DEVELOPER);
debugging('display_category_form() is deprecated, please use ' .
'\core_question\bank\search\condition instead.', DEBUG_DEVELOPER);
/// Get all the existing categories now
echo '<div class="choosecategory">';
$catmenu = question_category_options($contexts, false, 0, true);
@ -1361,7 +1366,7 @@ class question_bank_view {
* @deprecated since Moodle 2.7 MDL-40313.
* @see display_options_form
* @todo MDL-41978 This will be deleted in Moodle 2.8
* @see core_question_bank_search_condition_category
* @see \core_question\bank\search\condition
*/
protected function display_options($recurse, $showhidden, $showquestiontext) {
debugging('display_options() is deprecated, please use display_options_form instead.', DEBUG_DEVELOPER);
@ -1371,13 +1376,13 @@ class question_bank_view {
/**
* Print a single option checkbox.
* @deprecated since Moodle 2.7 MDL-40313.
* @see core_question_bank_search_condition_category
* @see \core_question\bank\search\condition
* @see html_writer::checkbox
* @todo MDL-41978 This will be deleted in Moodle 2.8
*/
protected function display_category_form_checkbox($name, $value, $label) {
debugging('display_category_form_checkbox() is deprecated, ' .
'please use core_question_bank_search_condition_category instead.', DEBUG_DEVELOPER);
'please use \core_question\bank\search\condition instead.', DEBUG_DEVELOPER);
echo '<div><input type="hidden" id="' . $name . '_off" name="' . $name . '" value="0" />';
echo '<input type="checkbox" id="' . $name . '_on" name="' . $name . '" value="1"';
if ($value) {
@ -1721,7 +1726,7 @@ class question_bank_view {
/**
* Add another search control to this view.
* @param core_question_bank_search_condition $searchcondition the condition to add.
* @param \core_question\bank\search\condition $searchcondition the condition to add.
*/
public function add_searchcondition($searchcondition) {
$this->searchconditions[] = $searchcondition;

View File

@ -5,18 +5,19 @@ This files describes API changes for code that uses the question API.
1) Changes to class question_bank_view:
Filters, including $recurse and $showhidden, are now implemented as
pluggable question_bank_search_condition classes.
pluggable \core_question\bank\search\condition classes.
Therefore $recurse and $showhidden are no longer passed to the following functions:
protected function display_options [deprecated, use display_options_form()]
protected function build_query_sql [deprecated, use build_query()]
protected function display_category_form() is deprecated. Use question_bank_search_condition_category
protected function display_category_form() is deprecated. Use \core_question\bank\search\category_condition
protected function display_category_form_checkbox deprecated use html_writer::checkbox and separate Javascript
protected function display_category_form_checkbox deprecated use html_writer::checkbox and separate JavaScript
To add filters, local plugins can now implement the function local_[pluginname]_get_question_bank_search_conditions,
=== 2.6 ===
1) Modules using the question bank MUST now declare their use of it with the xxx_supports()