Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Class to print a view of the question bank.

Copyright: 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1103 lines (44 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

view:: (3 methods):
  __construct()
  init_search_conditions()
  wanted_columns()

exists:: (46 methods):
  get_column_type()
  heading_column()
  init_columns()
  has_column()
  get_column_count()
  get_courseid()
  init_sort()
  parse_subsort()
  init_sort_from_params()
  sort_to_params()
  default_sort()
  get_primary_sort_order()
  new_sort_url()
  build_query_sql()
  build_query()
  get_question_count()
  load_page_questions()
  base_url()
  edit_question_moodle_url()
  edit_question_url()
  copy_question_moodle_url()
  copy_question_url()
  get_most_specific_context()
  preview_question_url()
  display()
  print_choose_category_message()
  get_current_category()
  print_category_info()
  display_category_form()
  display_options()
  display_category_form_checkbox()
  display_options_form()
  display_advanced_search_form()
  display_showtext_checkbox()
  display_question_bank_header()
  create_new_question_form()
  display_question_list()
  display_bottom_controls()
  start_table()
  end_table()
  print_table_headers()
  get_row_classes()
  print_table_row()
  process_actions()
  process_actions_needing_ui()
  add_searchcondition()

exists:: (46 methods):
  get_column_type()
  heading_column()
  init_columns()
  has_column()
  get_column_count()
  get_courseid()
  init_sort()
  parse_subsort()
  init_sort_from_params()
  sort_to_params()
  default_sort()
  get_primary_sort_order()
  new_sort_url()
  build_query_sql()
  build_query()
  get_question_count()
  load_page_questions()
  base_url()
  edit_question_moodle_url()
  edit_question_url()
  copy_question_moodle_url()
  copy_question_url()
  get_most_specific_context()
  preview_question_url()
  display()
  print_choose_category_message()
  get_current_category()
  print_category_info()
  display_category_form()
  display_options()
  display_category_form_checkbox()
  display_options_form()
  display_advanced_search_form()
  display_showtext_checkbox()
  display_question_bank_header()
  create_new_question_form()
  display_question_list()
  display_bottom_controls()
  start_table()
  end_table()
  print_table_headers()
  get_row_classes()
  print_table_row()
  process_actions()
  process_actions_needing_ui()
  add_searchcondition()


Class: view  - X-Ref

This class prints a view of the question bank, including
+ Some controls to allow users to to select what is displayed.
+ A list of questions as a table.
+ Further controls to do things with the questions.

This class gives a basic view, and provides plenty of hooks where subclasses
can override parts of the display.

The list of questions presented as a table is generated by creating a list of
core_question\bank\column objects, one for each 'column' to be displayed. These
manage
+ outputting the contents of that column, given a $question object, but also
+ generating the right fragments of SQL to ensure the necessary data is present,
and sorted in the right order.
+ outputting table headers.

__construct($contexts, $pageurl, $course, $cm = null)   X-Ref
Constructor

param: \question_edit_contexts $contexts
param: \moodle_url $pageurl
param: object $course course settings
param: object $cm (optional) activity settings.

init_search_conditions()   X-Ref
Initialize search conditions from plugins
local_*_get_question_bank_search_conditions() must return an array of
\core_question\bank\search\condition objects.


wanted_columns()   X-Ref
No description

Class: exists  - X-Ref

get_column_type($columnname)   X-Ref
Get a column object from its name.

param: string $columnname.
return: \core_question\bank\column_base.

heading_column()   X-Ref
Specify the column heading

return: string Column name for the heading

init_columns($wanted, $heading = '')   X-Ref
Initializing table columns

param: array $wanted Collection of column names
param: string $heading The name of column that is set as heading

has_column($colname)   X-Ref

param: string $colname a column internal name.
return: bool is this column included in the output?

get_column_count()   X-Ref

return: int The number of columns in the table.

get_courseid()   X-Ref
No description

init_sort()   X-Ref
No description

parse_subsort($sort)   X-Ref
Deal with a sort name of the form columnname, or colname_subsort by
breaking it up, validating the bits that are present, and returning them.
If there is no subsort, then $subsort is returned as ''.

param: string $sort the sort parameter to process.
return: array array($colname, $subsort).

init_sort_from_params()   X-Ref
No description

sort_to_params($sorts)   X-Ref
No description

default_sort()   X-Ref
No description

get_primary_sort_order($sort)   X-Ref

param: string $sort a column or column_subsort name.
return: int the current sort order for this column -1, 0, 1

new_sort_url($sort, $newsortreverse)   X-Ref
Get a URL to redisplay the page with a new sort for the question bank.

param: string $sort the column, or column_subsort to sort on.
param: bool $newsortreverse whether to sort in reverse order.
return: string The new URL.

build_query_sql($category, $recurse, $showhidden)   X-Ref
Create the SQL query to retrieve the indicated questions

param: \stdClass $category no longer used.
param: bool $recurse no longer used.
param: bool $showhidden no longer used.

build_query()   X-Ref
Create the SQL query to retrieve the indicated questions, based on
\core_question\bank\search\condition filters.


get_question_count()   X-Ref
No description

load_page_questions($page, $perpage)   X-Ref
Load the questions we need to display.

param: int $page page to display.
param: int $perpage number of questions per page.
return: \moodle_recordset questionid => data about each question.

base_url()   X-Ref
No description

edit_question_moodle_url($questionid)   X-Ref
Get the URL for editing a question as a {@link \moodle_url}.

param: int $questionid the question id.
return: \moodle_url the URL, HTML-escaped.

edit_question_url($questionid)   X-Ref
Get the URL for editing a question as a HTML-escaped string.

param: int $questionid the question id.
return: string the URL, HTML-escaped.

copy_question_moodle_url($questionid)   X-Ref
Get the URL for duplicating a question as a {@link \moodle_url}.

param: int $questionid the question id.
return: \moodle_url the URL.

copy_question_url($questionid)   X-Ref
Get the URL for duplicating a given question.

param: int $questionid the question id.
return: string the URL, HTML-escaped.

get_most_specific_context()   X-Ref
Get the context we are displaying the question bank for.

return: \context context object.

preview_question_url($questiondata)   X-Ref
Get the URL to preview a question.

param: \stdClass $questiondata the data defining the question.
return: \moodle_url the URL.

display($tabname, $page, $perpage, $cat,$recurse, $showhidden, $showquestiontext, $tagids = [])   X-Ref
Shows the question bank editing interface.

The function also processes a number of actions:

Actions affecting the question pool:
move           Moves a question to a different category
deleteselected Deletes the selected questions from the category
Other actions:
category      Chooses the category

param: string $tabname question bank edit tab name, for permission checking.
param: int $page the page number to show.
param: int $perpage the number of questions per page to show.
param: string $cat 'categoryid,contextid'.
param: int $recurse     Whether to include subcategories.
param: bool $showhidden  whether deleted questions should be displayed.
param: bool $showquestiontext whether the text of each question should be shown in the list. Deprecated.
param: array $tagids current list of selected tags.

print_choose_category_message($categoryandcontext)   X-Ref
No description

get_current_category($categoryandcontext)   X-Ref
No description

print_category_info($category)   X-Ref
prints category information

param: \stdClass $category the category row from the database.

display_category_form($contexts, $pageurl, $current)   X-Ref
Prints a form to choose categories


display_options($recurse, $showhidden, $showquestiontext)   X-Ref
Display the options form.

param: bool $recurse no longer used.
param: bool $showhidden no longer used.
param: bool $showquestiontext whether to show the question text.

display_category_form_checkbox($name, $value, $label)   X-Ref
Print a single option checkbox.


display_options_form($showquestiontext, $scriptpath = '/question/edit.php',$showtextoption = true)   X-Ref
Display the form with options for which questions are displayed and how they are displayed.

param: bool $showquestiontext Display the text of the question within the list.
param: string $scriptpath path to the script displaying this page.
param: bool $showtextoption whether to include the 'Show question text' checkbox.

display_advanced_search_form()   X-Ref
Print the "advanced" UI elements for the form to select which questions. Hidden by default.


display_showtext_checkbox($showquestiontext)   X-Ref
Display the checkbox UI for toggling the display of the question text in the list.

param: bool $showquestiontext the current or default value for whether to display the text.

display_question_bank_header()   X-Ref
Display the header element for the question bank.


create_new_question_form($category, $canadd)   X-Ref
No description

display_question_list($contexts, $pageurl, $categoryandcontext,$cm = null, $recurse=1, $page=0, $perpage=100, $showhidden=false,$showquestiontext = false, $addcontexts = array()   X-Ref
Prints the table of questions in a category with interactions

param: array      $contexts    Not used!
param: \moodle_url $pageurl     The URL to reload this page.
param: string     $categoryandcontext 'categoryID,contextID'.
param: \stdClass  $cm          Not used!
param: int        $recurse     Whether to include subcategories.
param: int        $page        The number of the page to be displayed
param: int        $perpage     Number of questions to show per page
param: bool       $showhidden  Not used! This is now controlled in a different way.
param: bool       $showquestiontext Not used! This is now controlled in a different way.
param: array      $addcontexts contexts where the user is allowed to add new questions.

display_bottom_controls($totalnumber, $recurse, $category, \context $catcontext, array $addcontexts)   X-Ref
Display the controls at the bottom of the list of questions.

param: int      $totalnumber Total number of questions that might be shown (if it was not for paging).
param: bool     $recurse     Whether to include subcategories.
param: \stdClass $category    The question_category row from the database.
param: \context  $catcontext  The context of the category being displayed.
param: array    $addcontexts contexts where the user is allowed to add new questions.

start_table()   X-Ref
No description

end_table()   X-Ref
No description

print_table_headers()   X-Ref
No description

get_row_classes($question, $rowcount)   X-Ref
No description

print_table_row($question, $rowcount)   X-Ref
No description

process_actions()   X-Ref
No description

process_actions_needing_ui()   X-Ref
No description

add_searchcondition($searchcondition)   X-Ref
Add another search control to this view.

param: condition $searchcondition the condition to add.

Class: exists  - X-Ref

get_column_type($columnname)   X-Ref
Get a column object from its name.

param: string $columnname.
return: \core_question\bank\column_base.

heading_column()   X-Ref
Specify the column heading

return: string Column name for the heading

init_columns($wanted, $heading = '')   X-Ref
Initializing table columns

param: array $wanted Collection of column names
param: string $heading The name of column that is set as heading

has_column($colname)   X-Ref

param: string $colname a column internal name.
return: bool is this column included in the output?

get_column_count()   X-Ref

return: int The number of columns in the table.

get_courseid()   X-Ref
No description

init_sort()   X-Ref
No description

parse_subsort($sort)   X-Ref
Deal with a sort name of the form columnname, or colname_subsort by
breaking it up, validating the bits that are present, and returning them.
If there is no subsort, then $subsort is returned as ''.

param: string $sort the sort parameter to process.
return: array array($colname, $subsort).

init_sort_from_params()   X-Ref
No description

sort_to_params($sorts)   X-Ref
No description

default_sort()   X-Ref
No description

get_primary_sort_order($sort)   X-Ref

param: string $sort a column or column_subsort name.
return: int the current sort order for this column -1, 0, 1

new_sort_url($sort, $newsortreverse)   X-Ref
Get a URL to redisplay the page with a new sort for the question bank.

param: string $sort the column, or column_subsort to sort on.
param: bool $newsortreverse whether to sort in reverse order.
return: string The new URL.

build_query_sql($category, $recurse, $showhidden)   X-Ref
Create the SQL query to retrieve the indicated questions

param: \stdClass $category no longer used.
param: bool $recurse no longer used.
param: bool $showhidden no longer used.

build_query()   X-Ref
Create the SQL query to retrieve the indicated questions, based on
\core_question\bank\search\condition filters.


get_question_count()   X-Ref
No description

load_page_questions($page, $perpage)   X-Ref
Load the questions we need to display.

param: int $page page to display.
param: int $perpage number of questions per page.
return: \moodle_recordset questionid => data about each question.

base_url()   X-Ref
No description

edit_question_moodle_url($questionid)   X-Ref
Get the URL for editing a question as a {@link \moodle_url}.

param: int $questionid the question id.
return: \moodle_url the URL, HTML-escaped.

edit_question_url($questionid)   X-Ref
Get the URL for editing a question as a HTML-escaped string.

param: int $questionid the question id.
return: string the URL, HTML-escaped.

copy_question_moodle_url($questionid)   X-Ref
Get the URL for duplicating a question as a {@link \moodle_url}.

param: int $questionid the question id.
return: \moodle_url the URL.

copy_question_url($questionid)   X-Ref
Get the URL for duplicating a given question.

param: int $questionid the question id.
return: string the URL, HTML-escaped.

get_most_specific_context()   X-Ref
Get the context we are displaying the question bank for.

return: \context context object.

preview_question_url($questiondata)   X-Ref
Get the URL to preview a question.

param: \stdClass $questiondata the data defining the question.
return: \moodle_url the URL.

display($tabname, $page, $perpage, $cat,$recurse, $showhidden, $showquestiontext, $tagids = [])   X-Ref
Shows the question bank editing interface.

The function also processes a number of actions:

Actions affecting the question pool:
move           Moves a question to a different category
deleteselected Deletes the selected questions from the category
Other actions:
category      Chooses the category

param: string $tabname question bank edit tab name, for permission checking.
param: int $page the page number to show.
param: int $perpage the number of questions per page to show.
param: string $cat 'categoryid,contextid'.
param: int $recurse     Whether to include subcategories.
param: bool $showhidden  whether deleted questions should be displayed.
param: bool $showquestiontext whether the text of each question should be shown in the list. Deprecated.
param: array $tagids current list of selected tags.

print_choose_category_message($categoryandcontext)   X-Ref
No description

get_current_category($categoryandcontext)   X-Ref
No description

print_category_info($category)   X-Ref
prints category information

param: \stdClass $category the category row from the database.

display_category_form($contexts, $pageurl, $current)   X-Ref
Prints a form to choose categories


display_options($recurse, $showhidden, $showquestiontext)   X-Ref
Display the options form.

param: bool $recurse no longer used.
param: bool $showhidden no longer used.
param: bool $showquestiontext whether to show the question text.

display_category_form_checkbox($name, $value, $label)   X-Ref
Print a single option checkbox.


display_options_form($showquestiontext, $scriptpath = '/question/edit.php',$showtextoption = true)   X-Ref
Display the form with options for which questions are displayed and how they are displayed.

param: bool $showquestiontext Display the text of the question within the list.
param: string $scriptpath path to the script displaying this page.
param: bool $showtextoption whether to include the 'Show question text' checkbox.

display_advanced_search_form()   X-Ref
Print the "advanced" UI elements for the form to select which questions. Hidden by default.


display_showtext_checkbox($showquestiontext)   X-Ref
Display the checkbox UI for toggling the display of the question text in the list.

param: bool $showquestiontext the current or default value for whether to display the text.

display_question_bank_header()   X-Ref
Display the header element for the question bank.


create_new_question_form($category, $canadd)   X-Ref
No description

display_question_list($contexts, $pageurl, $categoryandcontext,$cm = null, $recurse=1, $page=0, $perpage=100, $showhidden=false,$showquestiontext = false, $addcontexts = array()   X-Ref
Prints the table of questions in a category with interactions

param: array      $contexts    Not used!
param: \moodle_url $pageurl     The URL to reload this page.
param: string     $categoryandcontext 'categoryID,contextID'.
param: \stdClass  $cm          Not used!
param: int        $recurse     Whether to include subcategories.
param: int        $page        The number of the page to be displayed
param: int        $perpage     Number of questions to show per page
param: bool       $showhidden  Not used! This is now controlled in a different way.
param: bool       $showquestiontext Not used! This is now controlled in a different way.
param: array      $addcontexts contexts where the user is allowed to add new questions.

display_bottom_controls($totalnumber, $recurse, $category, \context $catcontext, array $addcontexts)   X-Ref
Display the controls at the bottom of the list of questions.

param: int      $totalnumber Total number of questions that might be shown (if it was not for paging).
param: bool     $recurse     Whether to include subcategories.
param: \stdClass $category    The question_category row from the database.
param: \context  $catcontext  The context of the category being displayed.
param: array    $addcontexts contexts where the user is allowed to add new questions.

start_table()   X-Ref
No description

end_table()   X-Ref
No description

print_table_headers()   X-Ref
No description

get_row_classes($question, $rowcount)   X-Ref
No description

print_table_row($question, $rowcount)   X-Ref
No description

process_actions()   X-Ref
No description

process_actions_needing_ui()   X-Ref
No description

add_searchcondition($searchcondition)   X-Ref
Add another search control to this view.

param: condition $searchcondition the condition to add.