Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401] [Versions 401 and 403]

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: 1338 lines (49 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


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 for view.

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

init_bulk_actions()   X-Ref
Initialize bulk actions.


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.


get_question_bank_plugins()   X-Ref
Get the list of qbank plugins with available objects for features.

return: array

wanted_columns()   X-Ref
Loads all the available columns.

return: array

get_column_type($columnname)   X-Ref
Check a column object from its name and get the object for sort.

param: string $columnname

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
Checks if the column included in the output.

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

get_column_count()   X-Ref
Get the count of the columns.

return: int The number of columns in the table.

get_courseid()   X-Ref
Get course id.

return: mixed

init_sort()   X-Ref
Initialise sorting.


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 [$colname, $subsort].

init_sort_from_params()   X-Ref
Initialise sort from parameters.


sort_to_params($sorts)   X-Ref
Sort to parameters.

param: array $sorts
return: array

default_sort()   X-Ref
Default sort for question data.

return: int[]

get_primary_sort_order($sort)   X-Ref
Gets the primary sort order according to the default sort.

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()   X-Ref
Create the SQL query to retrieve the indicated questions, based on
\core_question\bank\search\condition filters.


get_question_count()   X-Ref
Get the number of questions.

return: int

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
Returns the base url.


edit_question_moodle_url($questionid)   X-Ref
Get the URL for editing a question as a 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 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($pagevars, $tabname)   X-Ref
Shows the question bank 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
params: $tabname question bank edit tab name, for permission checking
$pagevars current list of page variables

param: string $tabname
param: array $pagevars

wanted_filters($cat, $tagids, $showhidden, $recurse, $editcontexts, $showquestiontext)   X-Ref
The filters for the question bank.

param: string $cat 'categoryid,contextid'
param: array $tagids current list of selected tags
param: bool $showhidden whether deleted questions should be displayed
param: int $recurse Whether to include subcategories
param: array $editcontexts parent contexts
param: bool $showquestiontext whether the text of each question should be shown in the list

print_choose_category_message()   X-Ref
Print the text if category id not available.


get_current_category($categoryandcontext)   X-Ref
Gets current selected category.

param: string $categoryandcontext
return: false|mixed|\stdClass

display_options_form($showquestiontext)   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.

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

param: array $advancedsearch

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
Create a new question form.

param: false|mixed|\stdClass $category
param: bool $canadd

display_question_list($pageurl, $categoryandcontext, $recurse = 1, $page = 0,$perpage = null, $addcontexts = [])   X-Ref
Prints the table of questions in a category with interactions

param: \moodle_url $pageurl     The URL to reload this page.
param: string     $categoryandcontext 'categoryID,contextID'.
param: int        $recurse     Whether to include subcategories.
param: int        $page        The number of the page to be displayed
param: int|null   $perpage     Number of questions to show per page
param: array      $addcontexts contexts where the user is allowed to add new questions.

determine_required_statistics()   X-Ref
Work out the list of all the required statistics fields for this question bank view.

This gathers all the required fields from all columns, so they can all be loaded at once.

return: string[] the names of all the required fields for this question bank view.

load_required_statistics(array $questions)   X-Ref
Load the aggregate statistics that all the columns require.

param: \stdClass[] $questions the questions that will be displayed indexed by question id.

get_aggregate_statistic(int $questionid, string $fieldname)   X-Ref
Get the aggregated value of a particular statistic for a particular question.

You can only get values for the questions on the current page of the question bank view,
and only if you declared the need for this statistic in the get_required_statistics_fields()
method of your question bank column.

param: int $questionid the id of a question
param: string $fieldname the name of a statistics field, e.g. 'facility'.
return: float|null the average (across all users) of this statistic for this question.

display_top_pagnation($pagination)   X-Ref
Display the top pagination bar.

param: object $pagination

display_bottom_pagination($pagination, $totalnumber, $perpage, $pageurl)   X-Ref
Display bottom pagination bar.

param: string $pagination
param: int $totalnumber
param: int $perpage
param: \moodle_url $pageurl

display_bottom_controls(\context $catcontext)   X-Ref
Display the controls at the bottom of the list of questions.

param: \context $catcontext The context of the category being displayed.

display_questions($questions)   X-Ref
Display the questions.

param: array $questions

print_table($questions)   X-Ref
Prints the actual table with question.

param: array $questions

start_table()   X-Ref
Start of the table html.


end_table()   X-Ref
End of the table html.


print_table_headers()   X-Ref
Print table headers from child classes.


get_row_classes($question, $rowcount)   X-Ref
Gets the classes for the row.

param: \stdClass $question
param: int $rowcount
return: array

print_table_row($question, $rowcount)   X-Ref
Prints the table row from child classes.

param: \stdClass $question
param: int $rowcount

process_actions()   X-Ref
Process actions for the selected action.


process_actions_needing_ui()   X-Ref
Process actions with ui.

return: bool

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

param: condition $searchcondition the condition to add.

get_visiblecolumns()   X-Ref
Gets visible columns.

return: array Visible columns.

is_listing_specific_versions()   X-Ref
Is this view showing separate versions of a question?

return: bool