Skip to content

Commit

Permalink
MDL-40313 question bank search classes should be namespaced.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jan 9, 2014
1 parent e22e749 commit d62382d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
8 changes: 4 additions & 4 deletions mod/quiz/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,9 @@ public function display($tabname, $page, $perpage, $cat,

$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');
Expand All @@ -1209,13 +1209,13 @@ public function display($tabname, $page, $perpage, $cat,
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand All @@ -31,11 +32,11 @@
* @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. */
Expand All @@ -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) {
Expand Down Expand Up @@ -113,38 +114,36 @@ public function display_options() {
* 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;
Expand All @@ -170,18 +169,16 @@ protected function get_current_category($categoryandcontext) {
* @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";
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand All @@ -32,7 +33,7 @@
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand All @@ -31,7 +32,7 @@
* @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;

Expand All @@ -57,11 +58,11 @@ public function where() {
* 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";
}
}
35 changes: 20 additions & 15 deletions question/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/


use core_question\bank\search\category_condition;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/questionlib.php');
Expand Down Expand Up @@ -942,7 +944,8 @@ public function __construct($contexts, $pageurl, $course, $cm = null) {

/**
* 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');
Expand Down Expand Up @@ -1164,17 +1167,18 @@ public function new_sort_url($sort, $newsortreverse) {
* @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;
Expand Down Expand Up @@ -1280,9 +1284,9 @@ public function display($tabname, $page, $perpage, $cat,
$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
Expand Down Expand Up @@ -1321,7 +1325,7 @@ protected function get_current_category($categoryandcontext) {
* 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) {
Expand All @@ -1336,13 +1340,14 @@ protected function print_category_info($category) {
/**
* 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);
Expand All @@ -1361,7 +1366,7 @@ protected function display_category_form($contexts, $pageurl, $current) {
* @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);
Expand All @@ -1371,13 +1376,13 @@ protected function display_options($recurse, $showhidden, $showquestiontext) {
/**
* 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) {
Expand Down Expand Up @@ -1721,7 +1726,7 @@ public function process_actions_needing_ui() {

/**
* 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;
Expand Down
7 changes: 4 additions & 3 deletions question/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d62382d

Please sign in to comment.