Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_question\local\bank\view Class Reference

This class prints a view of the question bank. More...

Inheritance diagram for core_question\local\bank\view:
mod_quiz\question\bank\custom_view qbank_columnsortorder\local\bank\preview_view qbank_history\question_history_view mod_quiz\question\bank\random_question_view

Public Member Functions

 __construct ($contexts, $pageurl, $course, $cm=null, $params=[], $extraparams=[])
 Constructor for view.
 
 add_searchcondition (condition $searchcondition, ?string $fieldname=null)
 Add another search control to this view.
 
 add_standard_search_conditions ()
 Add standard search conditions.
 
 allow_add_questions ()
 Does the current view allow adding new questions?
 
 base_url ()
 Returns the base url.
 
 copy_question_moodle_url ($questionid)
 Get the URL for duplicating a question as a moodle url.
 
 copy_question_url ($questionid)
 Get the URL for duplicating a given question.
 
 display ()
 Shows the question bank interface.
 
 display_bottom_pagination ($pagination, $totalnumber, $perpage, $pageurl)
 Display bottom pagination bar.
 
 display_question_list ()
 Prints the table of questions in a category with interactions.
 
 display_questions ($questions, $page=0, $perpage=DEFAULT_QUESTIONS_PER_PAGE)
 Display the questions.
 
 display_questions_table ()
 Display the questions table for the fragment/ajax.
 
 display_top_pagnation ($pagination)
 Display the top pagination bar.
 
 edit_question_moodle_url ($questionid)
 Get the URL for editing a question as a moodle url.
 
 edit_question_url ($questionid)
 Get the URL for editing a question as a HTML-escaped string.
 
 get_aggregate_statistic (int $questionid, string $fieldname)
 Get the aggregated value of a particular statistic for a particular question.
 
 get_column_count ()
 Get the count of the columns.
 
 get_courseid ()
 Get course id.
 
 get_most_specific_context ()
 Get the context we are displaying the question bank for.
 
 get_pagevars (?string $field=null)
 Get fields from the pagevars array.
 
 get_primary_sort_order ($sortname)
 Gets the primary sort order according to the default sort.
 
 get_question_actions ()
 Return array of menu actions.
 
 get_question_count ()
 Get the number of questions.
 
 get_visiblecolumns ()
 Gets visible columns.
 
 has_column ($colname)
 Checks if the column included in the output.
 
 is_listing_specific_versions ()
 Is this view showing separate versions of a question?
 
 load_questions ()
 Load the questions according to the search conditions.
 
 new_sort_url ($sortname, $newsortreverse)
 Get a URL to redisplay the page with a new sort for the question bank.
 
 preview_question_url ()
 
 print_table_row ($question, $rowcount)
 Prints the table row from child classes.
 
 process_actions ()
 
 process_actions_needing_ui ()
 
 set_pagevars (array $pagevars)
 Set the pagevars property with the provided array.
 
 wanted_filters ()
 The filters for the question bank.
 

Public Attributes

array $bulkactions = []
 $bulkactions to identify the bulk actions for the api.
 
string $callback = 'question_data'
 $callback name of the callback for the api call via filter js.
 
object cm_info null $cm
 if we are in a module context, the cm.
 
string $component = 'core_question'
 $component the component the api is used from.
 
core_question local bank question_edit_contexts $contexts
 
object $course
 the course we are within.
 
array $extraparams = []
 $extraparams extra parameters for the extended apis.
 
string $returnurl
 url of the new question page.
 
const MAX_SORTS = 3
 Maximum number of sorts allowed.
 

Protected Member Functions

 build_query ()
 Create the SQL query to retrieve the indicated questions, based on core_question\bank\search\condition filters.
 
 default_sort ()
 Default sort for question data.
 
 determine_required_statistics ()
 Work out the list of all the required statistics fields for this question bank view.
 
 display_advanced_search_form ($advancedsearch)
 Print the "advanced" UI elements for the form to select which questions.
 
 display_bottom_controls (\context $catcontext)
 Display the controls at the bottom of the list of questions.
 
 display_options_form ($showquestiontext)
 Display the form with options for which questions are displayed and how they are displayed.
 
 display_question_bank_header ()
 Display the header element for the question bank.
 
 display_showtext_checkbox ($showquestiontext)
 Display the checkbox UI for toggling the display of the question text in the list.
 
 end_table ()
 End of the table html.
 
 get_column_type ($columnname)
 Check a column object from its name and get the object for sort.
 
 get_component_requirements (array $viewcomponents)
 Gather query requirements from view component objects.
 
 get_current_category ($categoryandcontext)
 Gets current selected category.
 
 get_plugin_controls (\core\context $context, int $categoryid)
 Output the question bank controls for each plugin.
 
 get_question_bank_plugins ()
 Get class for each question bank columns.
 
 get_required_fields ()
 Return an array of fields for any data that the core view requires.
 
 get_required_joins ()
 Return an array 'table_alias' => 'JOIN clause' to bring in any data that the core view requires.
 
 get_row_classes ($question, $rowcount)
 Gets the classes for the row.
 
 heading_column ()
 Specify the column heading.
 
 init_bulk_actions ()
 Initialize bulk actions.
 
 init_column_manager ()
 Allow qbank plugins to override the column manager.
 
 init_columns ($wanted, $heading='')
 Initializing table columns.
 
 init_plugins ()
 Get an array of plugin features objects for all enabled qbank plugins.
 
 init_question_actions ()
 Initialise list of menu actions for enabled question bank plugins.
 
 init_search_conditions ()
 Initialize search conditions from plugins local_*_get_question_bank_search_conditions() must return an array of core_question\bank\search\condition objects.
 
 init_sort ()
 Initialise sorting.
 
 load_page_questions ()
 Load the questions we need to display.
 
 load_required_statistics (array $questions)
 Load the aggregate statistics that all the columns require.
 
 parse_subsort ($sort)
 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.
 
 print_choose_category_message ()
 Print the text if category id not available.
 
 print_table ($questions)
 Prints the actual table with question.
 
 print_table_headers ()
 Print table headers from child classes.
 
 sort_to_params ($sorts)
 Sort to parameters.
 
 start_table ()
 Start of the table html.
 
 wanted_columns ()
 Loads all the available columns.
 

Protected Attributes

moodle_url $baseurl
 base URL for the current page.
 
column_manager_base $columnmanager
 $columnmanager The column manager, can be overridden by plugins.
 
column_base[] $corequestionbankcolumns
 these are the 'columns' that are common to the question bank.
 
string $countsql
 SQL to count the number of questions matching the current search conditions.
 
moodle_url $editquestionurl
 used as a basis for URLs that edit a question.
 
column_base[] $extrarows
 these are the 'columns' that are actually displayed as an additional row (e.g.
 
int null $lastchangedid
 id of the a question to highlight in the list (if present).
 
array $loadedstatistics = null
 Stores all the average statistics that this question bank view needs.
 
string $loadsql
 SQL to actually load the question data to display.
 
int $pagesize = DEFAULT_QUESTIONS_PER_PAGE
 page size to use (when we are not showing all questions).
 
array $pagevars = []
 Parameters for the page URL.
 
plugin_features_base[] $plugins = []
 $plugins Plugin feature objects for all enabled qbank plugins.
 
question_action_base[] $questionactions
 these are all the actions that can be displayed in a question's action menu.
 
column_base[] $requiredcolumns
 these are all the 'columns' that are part of the display.
 
condition[] $searchconditions = []
 search conditions.
 
array $sort
 list of column class names for which columns to sort on.
 
array $sqlparams
 params used by $countsql and $loadsql (which currently must be the same).
 
int null $totalcount = null
 Number of questions.
 
column_base[] $visiblecolumns
 these are the 'columns' that are actually displayed as a column, in order.
 

Detailed Description

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.
Author
2021 Safat Shahin safat.nosp@m.shah.nosp@m.in@ca.nosp@m.taly.nosp@m.st-au.nosp@m..net
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_question\local\bank\view::__construct ( $contexts,
$pageurl,
$course,
$cm = null,
$params = [],
$extraparams = [] )

Constructor for view.

Parameters
core_question\local\bank\question_edit_contexts$contexts
moodle_url$pageurl
object$coursecourse settings
null$cm(optional) activity settings.
array$paramsthe parameters required to initialize the api.
array$extraparamsany extra parameters required by a particular view class.

Reimplemented in mod_quiz\question\bank\custom_view.

Member Function Documentation

◆ add_searchcondition()

core_question\local\bank\view::add_searchcondition ( condition $searchcondition,
?string $fieldname = null )

Add another search control to this view.

Parameters
condition$searchconditionthe condition to add.
string | null$fieldname

◆ add_standard_search_conditions()

core_question\local\bank\view::add_standard_search_conditions ( )

Add standard search conditions.

Params must be set into this object before calling this function.

Reimplemented in mod_quiz\question\bank\custom_view.

◆ allow_add_questions()

core_question\local\bank\view::allow_add_questions ( )

Does the current view allow adding new questions?

Return values
boolTrue if the view supports adding new questions.

Reimplemented in qbank_history\question_history_view.

◆ base_url()

core_question\local\bank\view::base_url ( )

Returns the base url.

Return values
moodle_url

◆ build_query()

core_question\local\bank\view::build_query ( )
protected

Create the SQL query to retrieve the indicated questions, based on core_question\bank\search\condition filters.

Reimplemented in mod_quiz\question\bank\custom_view, and qbank_history\question_history_view.

◆ copy_question_moodle_url()

core_question\local\bank\view::copy_question_moodle_url ( $questionid)

Get the URL for duplicating a question as a moodle url.

Parameters
int$questionidthe question id.
Return values
moodle_urlthe URL.

◆ copy_question_url()

core_question\local\bank\view::copy_question_url ( $questionid)

Get the URL for duplicating a given question.

Parameters
int$questionidthe question id.
Return values
stringthe URL, HTML-escaped.

◆ default_sort()

core_question\local\bank\view::default_sort ( )
protected

Default sort for question data.

Return values
int[]

Reimplemented in mod_quiz\question\bank\custom_view, and qbank_history\question_history_view.

◆ determine_required_statistics()

core_question\local\bank\view::determine_required_statistics ( )
protected

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 values
string[]the names of all the required fields for this question bank view.

◆ display_advanced_search_form()

core_question\local\bank\view::display_advanced_search_form ( $advancedsearch)
protected

Print the "advanced" UI elements for the form to select which questions.

Hidden by default.

Parameters
array$advancedsearch
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

Reimplemented in qbank_history\question_history_view.

◆ display_bottom_controls()

core_question\local\bank\view::display_bottom_controls ( \context $catcontext)
protected

Display the controls at the bottom of the list of questions.

Parameters
context$catcontextThe context of the category being displayed.

◆ display_bottom_pagination()

core_question\local\bank\view::display_bottom_pagination ( $pagination,
$totalnumber,
$perpage,
$pageurl )

Display bottom pagination bar.

Parameters
string$pagination
int$totalnumber
int$perpage
moodle_url$pageurl
Deprecated
since Moodle 4.3
Todo
Final deprecation on Moodle 4.7 MDL-78091

◆ display_options_form()

core_question\local\bank\view::display_options_form ( $showquestiontext)
protected

Display the form with options for which questions are displayed and how they are displayed.

Parameters
bool$showquestiontextDisplay the text of the question within the list.
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ display_question_bank_header()

core_question\local\bank\view::display_question_bank_header ( )
protected

Display the header element for the question bank.

Reimplemented in mod_quiz\question\bank\custom_view, and qbank_history\question_history_view.

◆ display_questions()

core_question\local\bank\view::display_questions ( $questions,
$page = 0,
$perpage = DEFAULT_QUESTIONS_PER_PAGE )

Display the questions.

Parameters
array$questions

◆ display_questions_table()

core_question\local\bank\view::display_questions_table ( )

Display the questions table for the fragment/ajax.

Return values
stringHTML for the question table

◆ display_showtext_checkbox()

core_question\local\bank\view::display_showtext_checkbox ( $showquestiontext)
protected

Display the checkbox UI for toggling the display of the question text in the list.

Parameters
bool$showquestiontextthe current or default value for whether to display the text.
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ display_top_pagnation()

core_question\local\bank\view::display_top_pagnation ( $pagination)

Display the top pagination bar.

Parameters
object$pagination
Deprecated
since Moodle 4.3
Todo
Final deprecation on Moodle 4.7 MDL-78091

◆ edit_question_moodle_url()

core_question\local\bank\view::edit_question_moodle_url ( $questionid)

Get the URL for editing a question as a moodle url.

Parameters
int$questionidthe question id.
Return values
moodle_urlthe URL, HTML-escaped.

◆ edit_question_url()

core_question\local\bank\view::edit_question_url ( $questionid)

Get the URL for editing a question as a HTML-escaped string.

Parameters
int$questionidthe question id.
Return values
stringthe URL, HTML-escaped.

◆ end_table()

core_question\local\bank\view::end_table ( )
protected

End of the table html.

See also
print_table()
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ get_aggregate_statistic()

core_question\local\bank\view::get_aggregate_statistic ( int $questionid,
string $fieldname )

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.

Parameters
int$questionidthe id of a question
string$fieldnamethe name of a statistics field, e.g. 'facility'.
Return values
float|nullthe average (across all users) of this statistic for this question. Null if the value is not available right now.

◆ get_column_count()

core_question\local\bank\view::get_column_count ( )

Get the count of the columns.

Return values
intThe number of columns in the table.

◆ get_column_type()

core_question\local\bank\view::get_column_type ( $columnname)
protected

Check a column object from its name and get the object for sort.

Parameters
string$columnname

◆ get_component_requirements()

core_question\local\bank\view::get_component_requirements ( array $viewcomponents)
protected

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.

Exceptions
coding_exceptionIf two components attempt to use the same alias for different joins.
Parameters
view_component[]$viewcomponentsList of component objects included in the current view
Return values
array[$fields, $joins] SQL fields and joins to add to the query.

◆ get_courseid()

core_question\local\bank\view::get_courseid ( )

Get course id.

Return values
mixed

◆ get_current_category()

core_question\local\bank\view::get_current_category ( $categoryandcontext)
protected

Gets current selected category.

Parameters
string$categoryandcontext
Return values
false|mixed|stdClass
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ get_most_specific_context()

core_question\local\bank\view::get_most_specific_context ( )

Get the context we are displaying the question bank for.

Return values
contextcontext object.

◆ get_pagevars()

core_question\local\bank\view::get_pagevars ( ?string $field = null)

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.

Parameters
?string$field
Return values
mixed

◆ get_plugin_controls()

core_question\local\bank\view::get_plugin_controls ( \core\context $context,
int $categoryid )
protected

Output the question bank controls for each plugin.

Controls will be output in the order defined by the array keys returned from {

See also
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.
Parameters
core\context$contextThe current context, for permissions checks.
int$categoryidThe current question category.

◆ get_primary_sort_order()

core_question\local\bank\view::get_primary_sort_order ( $sortname)

Gets the primary sort order according to the default sort.

Parameters
string$sortnamea column or column_subsort name.
Return values
intthe current sort order for this column -1, 0, 1

◆ get_question_actions()

core_question\local\bank\view::get_question_actions ( )

Return array of menu actions.

Return values
question_action_base[]

◆ get_question_bank_plugins()

core_question\local\bank\view::get_question_bank_plugins ( )
protected

Get class for each question bank columns.

Return values
array

Reimplemented in mod_quiz\question\bank\custom_view, and mod_quiz\question\bank\random_question_view.

◆ get_question_count()

core_question\local\bank\view::get_question_count ( )

Get the number of questions.

Return values
int

◆ get_required_fields()

core_question\local\bank\view::get_required_fields ( )
protected

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 values
string[]fields required.

◆ get_required_joins()

core_question\local\bank\view::get_required_joins ( )
protected

Return an array 'table_alias' => 'JOIN clause' to bring in any data that the core view requires.

Return values
string[]'table_alias' => 'JOIN clause'

◆ get_row_classes()

core_question\local\bank\view::get_row_classes ( $question,
$rowcount )
protected

Gets the classes for the row.

Parameters
stdClass$question
int$rowcount
Return values
array

◆ get_visiblecolumns()

core_question\local\bank\view::get_visiblecolumns ( )

Gets visible columns.

Return values
arrayVisible columns.

◆ has_column()

core_question\local\bank\view::has_column ( $colname)

Checks if the column included in the output.

Parameters
string$colnamea column internal name.
Return values
boolis this column included in the output?

◆ heading_column()

core_question\local\bank\view::heading_column ( )
protected

Specify the column heading.

Return values
stringColumn name for the heading

Reimplemented in mod_quiz\question\bank\custom_view.

◆ init_column_manager()

core_question\local\bank\view::init_column_manager ( )
protected

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 values
void

Reimplemented in mod_quiz\question\bank\custom_view, and qbank_columnsortorder\local\bank\preview_view.

◆ init_columns()

core_question\local\bank\view::init_columns ( $wanted,
$heading = '' )
protected

Initializing table columns.

Parameters
array$wantedCollection of column names
string$headingThe name of column that is set as heading

◆ init_plugins()

core_question\local\bank\view::init_plugins ( )
protected

Get an array of plugin features objects for all enabled qbank plugins.

Return values
void

◆ init_question_actions()

core_question\local\bank\view::init_question_actions ( )
protected

Initialise list of menu actions for enabled question bank plugins.

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

Return values
void

Reimplemented in qbank_history\question_history_view.

◆ init_search_conditions()

core_question\local\bank\view::init_search_conditions ( )
protected

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

Deprecated
Since Moodle 4.3
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ is_listing_specific_versions()

core_question\local\bank\view::is_listing_specific_versions ( )

Is this view showing separate versions of a question?

Return values
bool

Reimplemented in qbank_history\question_history_view.

◆ load_page_questions()

core_question\local\bank\view::load_page_questions ( )
protected

Load the questions we need to display.

Return values
moodle_recordsetquestionid => data about each question.

◆ load_questions()

core_question\local\bank\view::load_questions ( )

Load the questions according to the search conditions.

Return values
array

◆ load_required_statistics()

core_question\local\bank\view::load_required_statistics ( array $questions)
protected

Load the aggregate statistics that all the columns require.

Parameters
stdClass[]$questionsthe questions that will be displayed indexed by question id.

◆ new_sort_url()

core_question\local\bank\view::new_sort_url ( $sortname,
$newsortreverse )

Get a URL to redisplay the page with a new sort for the question bank.

Parameters
string$sortnamethe column, or column_subsort to sort on.
bool$newsortreversewhether to sort in reverse order.
Return values
stringThe new URL.

◆ parse_subsort()

core_question\local\bank\view::parse_subsort ( $sort)
protected

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

Parameters
string$sortthe sort parameter to process.
Return values
array[$colname, $subsort].

◆ preview_question_url()

core_question\local\bank\view::preview_question_url ( )
Deprecated
since Moodle 4.0

◆ print_choose_category_message()

core_question\local\bank\view::print_choose_category_message ( )
protected

Print the text if category id not available.

Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ print_table()

core_question\local\bank\view::print_table ( $questions)
protected

Prints the actual table with question.

Parameters
array$questions

◆ print_table_row()

core_question\local\bank\view::print_table_row ( $question,
$rowcount )

Prints the table row from child classes.

Parameters
stdClass$question
int$rowcount

Reimplemented in qbank_columnsortorder\local\bank\preview_view.

◆ process_actions()

core_question\local\bank\view::process_actions ( )
Deprecated
since Moodle 4.0

◆ process_actions_needing_ui()

core_question\local\bank\view::process_actions_needing_ui ( )
Deprecated
since Moodle 4.0

◆ set_pagevars()

core_question\local\bank\view::set_pagevars ( array $pagevars)

Set the pagevars property with the provided array.

Parameters
array$pagevars

◆ sort_to_params()

core_question\local\bank\view::sort_to_params ( $sorts)
protected

Sort to parameters.

Parameters
array$sorts
Return values
array

◆ start_table()

core_question\local\bank\view::start_table ( )
protected

Start of the table html.

See also
print_table()
Deprecated
since Moodle 4.3 MDL-72321
Todo
Final deprecation on Moodle 4.7 MDL-78090

◆ wanted_columns()

core_question\local\bank\view::wanted_columns ( )
protected

Loads all the available columns.

Return values
array

Reimplemented in qbank_history\question_history_view.

◆ wanted_filters()

core_question\local\bank\view::wanted_filters ( )

The filters for the question bank.

Reimplemented in qbank_history\question_history_view.

Member Data Documentation

◆ $baseurl

moodle_url core_question\local\bank\view::$baseurl
protected

base URL for the current page.

Used as the basis for making URLs for actions that reload the page.

◆ $extrarows

column_base [] core_question\local\bank\view::$extrarows
protected

these are the 'columns' that are actually displayed as an additional row (e.g.

question text), in order. Array keys are the class name.

◆ $loadedstatistics

array core_question\local\bank\view::$loadedstatistics = null
protected

Stores all the average statistics that this question bank view needs.

This field gets initialised in {

See also
display_question_list()}. It is a two dimensional $this->loadedstatistics[$questionid][$fieldname] = $average value of that statistics for that question. Column classes in qbank plugins can access these values using {
get_aggregate_statistic()}.

◆ $questionactions

question_action_base [] core_question\local\bank\view::$questionactions
protected

these are all the actions that can be displayed in a question's action menu.

Array keys are the class name.

◆ $requiredcolumns

column_base [] core_question\local\bank\view::$requiredcolumns
protected

these are all the 'columns' that are part of the display.

Array keys are the class name.

◆ $visiblecolumns

column_base [] core_question\local\bank\view::$visiblecolumns
protected

these are the 'columns' that are actually displayed as a column, in order.

Array keys are the class name.


The documentation for this class was generated from the following file: