Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 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: 1611 lines (60 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

view:: (68 methods):
  __construct()
  init_plugins()
  init_column_manager()
  init_bulk_actions()
  init_search_conditions()
  init_question_actions()
  get_question_bank_plugins()
  wanted_columns()
  get_column_type()
  heading_column()
  init_columns()
  has_column()
  get_column_count()
  get_courseid()
  init_sort()
  parse_subsort()
  sort_to_params()
  default_sort()
  get_primary_sort_order()
  new_sort_url()
  get_required_joins()
  get_required_fields()
  get_component_requirements()
  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()
  get_pagevars()
  set_pagevars()
  display()
  wanted_filters()
  print_choose_category_message()
  get_current_category()
  display_options_form()
  display_advanced_search_form()
  display_showtext_checkbox()
  display_question_bank_header()
  allow_add_questions()
  get_plugin_controls()
  display_question_list()
  determine_required_statistics()
  load_required_statistics()
  get_aggregate_statistic()
  display_top_pagnation()
  display_bottom_pagination()
  display_bottom_controls()
  display_questions()
  load_questions()
  print_table()
  start_table()
  end_table()
  print_table_headers()
  get_row_classes()
  print_table_row()
  process_actions()
  process_actions_needing_ui()
  add_searchcondition()
  add_standard_search_conditions()
  get_visiblecolumns()
  is_listing_specific_versions()
  get_question_actions()
  display_questions_table()


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, $params = [], $extraparams = [])   X-Ref
Constructor for view.

param: \core_question\local\bank\question_edit_contexts $contexts
param: \moodle_url $pageurl
param: object $course course settings
param: null $cm (optional) activity settings.
param: array $params the parameters required to initialize the api.
param: array $extraparams any extra parameters required by a particular view class.

init_plugins()   X-Ref
Get an array of plugin features objects for all enabled qbank plugins.

return: void

init_column_manager()   X-Ref
Allow qbank plugins to override the column manager.

If multiple qbank plugins define a column manager, this will pick the first one sorted alphabetically.

return: void

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.


init_question_actions()   X-Ref
Initialise list of menu actions for enabled question bank plugins.

Menu action objects are stored in $this->menuactions, keyed by class name.

return: void

get_question_bank_plugins()   X-Ref
Get class for each question bank columns.

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].

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($sortname)   X-Ref
Gets the primary sort order according to the default sort.

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

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

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

get_required_joins()   X-Ref
Return an array 'table_alias' => 'JOIN clause' to bring in any data that
the core view requires.

return: string[] 'table_alias' => 'JOIN clause'

get_required_fields()   X-Ref
Return an array of fields for any data that the core view requires.

Use table alias 'q' for the question table, or one of the ones from get_required_joins.
Every field requested must specify a table prefix.

return: string[] fields required.

get_component_requirements(array $viewcomponents)   X-Ref
Gather query requirements from view component objects.

This will take the required fields and joins for this view, and combine them with those for all active view components.
Fields will be de-duplicated in multiple components require the same field.
Joins will be de-duplicated if the alias and join clause match exactly.

param: view_component[] $viewcomponents List of component objects included in the current view
return: array [$fields, $joins] SQL fields and joins to add to the query.

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()   X-Ref
Load the questions we need to display.

return: \moodle_recordset questionid => data about each question.

base_url()   X-Ref
Returns the base url.

return: \moodle_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.

get_pagevars(?string $field = null)   X-Ref
Get fields from the pagevars array.

If a field is specified, that particlar pagevars field will be returned. Otherwise the entire array will be returned.

If a field is specified but it does not exist, null will be returned.

param: ?string $field
return: mixed

set_pagevars(array $pagevars)   X-Ref
Set the pagevars property with the provided array.

param: array $pagevars

display()   X-Ref
Shows the question bank interface.


wanted_filters()   X-Ref
The filters for the question bank.


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.


allow_add_questions()   X-Ref
Does the current view allow adding new questions?

return: bool True if the view supports adding new questions.

get_plugin_controls(\core\context $context, int $categoryid)   X-Ref
Output the question bank controls for each plugin.

Controls will be output in the order defined by the array keys returned from
{@see plugin_features_base::get_question_bank_controls}. If more than one plugin defines a control in the same position,
they will placed after one another based on the alphabetical order of the plugins.

param: \core\context $context The current context, for permissions checks.
param: int $categoryid The current question category.

display_question_list()   X-Ref
Prints the table of questions in a category with interactions


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, $page = 0, $perpage = DEFAULT_QUESTIONS_PER_PAGE)   X-Ref
Display the questions.

param: array $questions

load_questions()   X-Ref
Load the questions according to the search conditions.

return: array

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(condition $searchcondition, ?string $fieldname = null)   X-Ref
Add another search control to this view.

param: condition $searchcondition the condition to add.
param: string|null $fieldname

add_standard_search_conditions()   X-Ref
Add standard search conditions.
Params must be set into this object before calling this function.


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

get_question_actions()   X-Ref
Return array of menu actions.

return: question_action_base[]

display_questions_table()   X-Ref
Display the questions table for the fragment/ajax.

return: string HTML for the question table