idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
27,100
protected function parse_template ( ) { if ( empty ( $ this -> params ) ) { $ this -> params = array ( ) ; if ( isset ( $ _SERVER [ 'PATH_INFO' ] ) && ! empty ( $ _SERVER [ 'PATH_INFO' ] ) ) { $ path = explode ( '/' , $ _SERVER [ 'PATH_INFO' ] ) ; $ parts = explode ( '/' , $ this -> get_template ( ) ) ; for ( $ i = 0 ;...
Parse the template for variables .
27,101
public function execute ( ) { $ areaid = $ this -> get_custom_data ( ) ; try { \ core_search \ manager :: clean_up_non_existing_area ( $ areaid ) ; } catch ( \ core_search \ engine_exception $ e ) { mtrace ( 'Search is not configured. Skip deleting index for search area ' . $ areaid ) ; } }
Run the task to clean up deleted search are data .
27,102
public function get_regions ( ) { if ( is_null ( $ this -> defaultregion ) ) { $ this -> page -> initialise_theme_and_output ( ) ; } return array_keys ( $ this -> regions ) ; }
Get an array of all region names on this page where a block may appear
27,103
public function get_addable_blocks ( ) { $ this -> check_is_loaded ( ) ; if ( ! is_null ( $ this -> addableblocks ) ) { return $ this -> addableblocks ; } $ this -> addableblocks = array ( ) ; $ allblocks = blocks_get_record ( ) ; if ( empty ( $ allblocks ) ) { return $ this -> addableblocks ; } $ unaddableblocks = sel...
The list of block types that may be added to this page .
27,104
public function is_block_present ( $ blockname ) { if ( empty ( $ this -> blockinstances ) ) { return false ; } $ requiredbythemeblocks = $ this -> get_required_by_theme_block_types ( ) ; foreach ( $ this -> blockinstances as $ region ) { foreach ( $ region as $ instance ) { if ( empty ( $ instance -> instance -> block...
Given a block name find out of any of them are currently present in the page
27,105
public function is_known_block_type ( $ blockname , $ includeinvisible = false ) { $ blocks = $ this -> get_installed_blocks ( ) ; foreach ( $ blocks as $ block ) { if ( $ block -> name == $ blockname && ( $ includeinvisible || $ block -> visible ) ) { return true ; } } return false ; }
Find out if a block type is known by the system
27,106
public function get_blocks_for_region ( $ region ) { $ this -> check_is_loaded ( ) ; $ this -> ensure_instances_exist ( $ region ) ; return $ this -> blockinstances [ $ region ] ; }
Get an array of all blocks within a given region
27,107
public function get_content_for_region ( $ region , $ output ) { $ this -> check_is_loaded ( ) ; $ this -> ensure_content_created ( $ region , $ output ) ; return $ this -> visibleblockcontent [ $ region ] ; }
Returns an array of block content objects that exist in a region
27,108
public function get_content_for_all_regions ( $ output ) { $ contents = array ( ) ; $ this -> check_is_loaded ( ) ; foreach ( $ this -> regions as $ region => $ val ) { $ this -> ensure_content_created ( $ region , $ output ) ; $ contents [ $ region ] = $ this -> visibleblockcontent [ $ region ] ; } return $ contents ;...
Returns an array of block content objects for all the existings regions
27,109
protected function get_move_target_url ( $ region , $ weight ) { return new moodle_url ( $ this -> page -> url , array ( 'bui_moveid' => $ this -> movingblock , 'bui_newregion' => $ region , 'bui_newweight' => $ weight , 'sesskey' => sesskey ( ) ) ) ; }
Helper method used by get_content_for_region .
27,110
public function get_installed_blocks ( ) { global $ DB ; if ( is_null ( $ this -> allblocks ) ) { $ this -> allblocks = $ DB -> get_records ( 'block' ) ; } return $ this -> allblocks ; }
Get an array of all of the installed blocks .
27,111
public static function protect_block ( $ blockidorname ) { global $ DB ; $ syscontext = context_system :: instance ( ) ; require_capability ( 'moodle/site:config' , $ syscontext ) ; $ block = false ; if ( is_int ( $ blockidorname ) ) { $ block = $ DB -> get_record ( 'block' , array ( 'id' => $ blockidorname ) , 'id, na...
Make this block type undeletable and unaddable .
27,112
public static function get_undeletable_block_types ( ) { global $ CFG ; $ undeletableblocks = false ; if ( isset ( $ CFG -> undeletableblocktypes ) ) { $ undeletableblocks = $ CFG -> undeletableblocktypes ; } if ( empty ( $ undeletableblocks ) ) { return array ( ) ; } else if ( is_string ( $ undeletableblocks ) ) { ret...
Get the list of protected blocks via admin block manager ui .
27,113
public function add_region ( $ region , $ custom = true ) { global $ SESSION ; $ this -> check_not_yet_loaded ( ) ; if ( $ custom ) { if ( array_key_exists ( $ region , $ this -> regions ) ) { debugging ( 'A custom region conflicts with a block region in the theme.' , DEBUG_DEVELOPER ) ; } $ type = $ this -> page -> pa...
Add a region to a page
27,114
public function add_custom_regions_for_pagetype ( $ pagetype ) { global $ SESSION ; if ( isset ( $ SESSION -> custom_block_regions [ $ pagetype ] ) ) { foreach ( $ SESSION -> custom_block_regions [ $ pagetype ] as $ customregion ) { $ this -> add_region ( $ customregion , false ) ; } } }
Finds custom block regions associated with a page type and registers them with this block manager .
27,115
public function set_default_region ( $ defaultregion ) { $ this -> check_not_yet_loaded ( ) ; if ( $ defaultregion ) { $ this -> check_region_is_known ( $ defaultregion ) ; } $ this -> defaultregion = $ defaultregion ; }
Set the default region for new blocks on the page
27,116
public function add_fake_block ( $ bc , $ region ) { $ this -> page -> initialise_theme_and_output ( ) ; if ( ! $ this -> is_known_region ( $ region ) ) { $ region = $ this -> get_default_region ( ) ; } if ( array_key_exists ( $ region , $ this -> visibleblockcontent ) ) { throw new coding_exception ( 'block_manager ha...
Add something that looks like a block but which isn t an actual block_instance to this page .
27,117
public function reposition_block ( $ blockinstanceid , $ newregion , $ newweight ) { global $ DB ; $ this -> check_region_is_known ( $ newregion ) ; $ inst = $ this -> find_instance ( $ blockinstanceid ) ; $ bi = $ inst -> instance ; if ( $ bi -> weight == $ bi -> defaultweight && $ bi -> region == $ bi -> defaultregio...
Move a block to a new position on this page .
27,118
public function find_instance ( $ instanceid ) { foreach ( $ this -> regions as $ region => $ notused ) { $ this -> ensure_instances_exist ( $ region ) ; foreach ( $ this -> blockinstances [ $ region ] as $ instance ) { if ( $ instance -> instance -> id == $ instanceid ) { return $ instance ; } } } throw new block_not_...
Find a given block by its instance id
27,119
protected function check_known_block_type ( $ blockname , $ includeinvisible = false ) { if ( ! $ this -> is_known_block_type ( $ blockname , $ includeinvisible ) ) { if ( $ this -> is_known_block_type ( $ blockname , true ) ) { throw new coding_exception ( 'Unknown block type ' . $ blockname ) ; } else { throw new cod...
Check if a block type is known and usable
27,120
protected function prepare_per_region_arrays ( ) { $ result = array ( ) ; foreach ( $ this -> regions as $ region => $ notused ) { $ result [ $ region ] = array ( ) ; } return $ result ; }
Returns an array of region names as keys and nested arrays for values
27,121
protected function create_block_instances ( $ birecords ) { $ results = array ( ) ; foreach ( $ birecords as $ record ) { if ( $ blockobject = block_instance ( $ record -> blockname , $ record , $ this -> page ) ) { $ results [ ] = $ blockobject ; } } return $ results ; }
Create a set of new block instance from a record array
27,122
protected function create_block_contents ( $ instances , $ output , $ region ) { $ results = array ( ) ; $ lastweight = 0 ; $ lastblock = 0 ; if ( $ this -> movingblock ) { $ first = reset ( $ instances ) ; if ( $ first ) { $ lastweight = $ first -> instance -> weight - 2 ; } } foreach ( $ instances as $ instance ) { $...
Return an array of content objects from a set of block instances
27,123
protected function ensure_instances_exist ( $ region ) { $ this -> check_region_is_known ( $ region ) ; if ( ! array_key_exists ( $ region , $ this -> blockinstances ) ) { $ this -> blockinstances [ $ region ] = $ this -> create_block_instances ( $ this -> birecordsbyregion [ $ region ] ) ; } }
Ensure block instances exist for a given region
27,124
public function ensure_content_created ( $ region , $ output ) { $ this -> ensure_instances_exist ( $ region ) ; if ( ! array_key_exists ( $ region , $ this -> visibleblockcontent ) ) { $ contents = array ( ) ; if ( array_key_exists ( $ region , $ this -> extracontent ) ) { $ contents = $ this -> extracontent [ $ regio...
Ensure that there is some content within the given region
27,125
public function process_url_actions ( ) { if ( ! $ this -> page -> user_is_editing ( ) ) { return false ; } return $ this -> process_url_add ( ) || $ this -> process_url_delete ( ) || $ this -> process_url_show_hide ( ) || $ this -> process_url_edit ( ) || $ this -> process_url_move ( ) ; }
Process any block actions that were specified in the URL .
27,126
public function process_url_show_hide ( ) { if ( $ blockid = optional_param ( 'bui_hideid' , null , PARAM_INT ) ) { $ newvisibility = 0 ; } else if ( $ blockid = optional_param ( 'bui_showid' , null , PARAM_INT ) ) { $ newvisibility = 1 ; } else { return false ; } require_sesskey ( ) ; $ block = $ this -> page -> block...
Handle showing or hiding a block .
27,127
protected function process_mapping ( ) { $ this -> mappings = $ this -> mapper -> get_mappings ( ) ; $ this -> fromids = $ this -> mapper -> get_all_from ( ) ; }
Process the mapping .
27,128
protected function find_coursescompetencies ( ) { global $ DB ; $ this -> progress -> start_progress ( get_string ( 'findingcoursecompetencies' , 'tool_lpmigrate' ) , 3 ) ; $ this -> progress -> increment_progress ( ) ; $ joins = array ( ) ; $ conditions = array ( ) ; $ params = array ( ) ; list ( $ insql , $ inparams ...
Identifies what courses and their competencies to work with .
27,129
protected function find_modulecompetencies ( ) { global $ DB ; if ( empty ( $ this -> coursescompetencies ) ) { return ; } $ this -> progress -> start_progress ( get_string ( 'findingmodulecompetencies' , 'tool_lpmigrate' ) , 3 ) ; $ this -> progress -> increment_progress ( ) ; list ( $ inidsql , $ inidparams ) = $ DB ...
Identifies what course modules and their competencies to work with .
27,130
protected function log_warning ( $ courseid , $ competencyid , $ cmid , $ message ) { $ this -> warnings [ ] = array ( 'courseid' => $ courseid , 'competencyid' => $ competencyid , 'cmid' => $ cmid , 'message' => $ message ) ; }
Log a warning .
27,131
public function proceed ( ) { if ( $ this -> has_run ( ) ) { throw new coding_exception ( 'The processor has already run.' ) ; } else if ( ! $ this -> mapper -> has_mappings ( ) ) { throw new coding_exception ( 'Mapping was not set.' ) ; } $ this -> proceeded = true ; $ this -> process_mapping ( ) ; $ this -> find_cour...
Execute the whole task .
27,132
public static function drop_site ( ) { if ( ! defined ( 'BEHAT_UTIL' ) ) { throw new coding_exception ( 'This method can be only used by Behat CLI tool' ) ; } self :: reset_dataroot ( ) ; self :: drop_database ( true ) ; self :: drop_dataroot ( ) ; }
Drops dataroot and remove test database tables
27,133
public static function drop_dataroot ( ) { global $ CFG ; if ( $ CFG -> behat_dataroot !== $ CFG -> behat_dataroot_parent ) { remove_dir ( $ CFG -> behat_dataroot , false ) ; } else { throw new moodle_exception ( "Behat dataroot should not be same as parent behat data root." ) ; } }
Delete files and directories under dataroot .
27,134
protected function get_roleid_options ( $ instance , $ context ) { if ( $ instance -> id ) { $ roles = get_default_enrol_roles ( $ context , $ instance -> roleid ) ; } else { $ roles = get_default_enrol_roles ( $ context , $ this -> get_config ( 'roleid' ) ) ; } return $ roles ; }
Return an array of valid options for the roleid .
27,135
public function set_analysable ( \ core_analytics \ analysable $ analysable ) { $ this -> analysable = $ analysable ; $ this -> ranges = $ this -> define_ranges ( ) ; $ this -> validate_ranges ( ) ; }
Assigns the analysable and updates the time ranges according to the analysable start and end dates .
27,136
public function ready_to_train ( $ range ) { $ now = time ( ) ; if ( $ range [ 'time' ] <= $ now && $ range [ 'end' ] <= $ now ) { return true ; } return false ; }
Should we use this time range for training?
27,137
public function get_most_recent_prediction_range ( ) { $ ranges = $ this -> get_all_ranges ( ) ; krsort ( $ ranges ) ; foreach ( $ ranges as $ rangeindex => $ range ) { if ( $ this -> ready_to_predict ( $ range ) ) { return array ( $ rangeindex => $ range ) ; } } return array ( ) ; }
Returns the most recent range that can be used to predict .
27,138
public function get_range_by_index ( $ rangeindex ) { if ( ! isset ( $ this -> ranges [ $ rangeindex ] ) ) { return false ; } return $ this -> ranges [ $ rangeindex ] ; }
Returns range data by its index .
27,139
protected function validate_ranges ( ) { foreach ( $ this -> ranges as $ key => $ range ) { if ( ! isset ( $ this -> ranges [ $ key ] [ 'start' ] ) || ! isset ( $ this -> ranges [ $ key ] [ 'end' ] ) || ! isset ( $ this -> ranges [ $ key ] [ 'time' ] ) ) { throw new \ coding_exception ( $ this -> get_id ( ) . ' time sp...
Validates the time splitting method ranges .
27,140
protected function validate_data ( ) { parent :: validate_data ( ) ; if ( $ this -> contextlevel != CONTEXT_COURSE ) { throw new \ coding_exception ( 'Context level must be CONTEXT_COURSE.' ) ; } if ( ! isset ( $ this -> relateduserid ) ) { throw new \ coding_exception ( 'The \'relateduserid\' must be set.' ) ; } }
custom validations .
27,141
public function set_status ( $ status , $ message = null ) { $ this -> status = $ status ; $ this -> message = is_null ( $ message ) ? $ this -> message : $ message ; $ this -> timeend = time ( ) ; }
Sets the result status of the allocation
27,142
public function log ( $ message , $ type = 'ok' , $ indent = 0 ) { $ log = new stdClass ( ) ; $ log -> message = $ message ; $ log -> type = $ type ; $ log -> indent = $ indent ; $ this -> logs [ ] = $ log ; }
Appends a new message to the log
27,143
function focus ( $ name = NULL ) { $ form = & $ this -> _form ; $ elkeys = array_keys ( $ form -> _elementIndex ) ; $ error = false ; if ( isset ( $ form -> _errors ) && 0 != count ( $ form -> _errors ) ) { $ errorkeys = array_keys ( $ form -> _errors ) ; $ elkeys = array_intersect ( $ elkeys , $ errorkeys ) ; $ error ...
To autofocus on first form element or first element with error .
27,144
function _process_submission ( $ method ) { $ submission = array ( ) ; if ( ! empty ( $ this -> _ajaxformdata ) ) { $ submission = $ this -> _ajaxformdata ; } else if ( $ method == 'post' ) { if ( ! empty ( $ _POST ) ) { $ submission = $ _POST ; } } else { $ submission = $ _GET ; merge_query_params ( $ submission , $ _...
Internal method . Alters submitted data to be suitable for quickforms processing . Must be called when the form is fully set up .
27,145
function _validate_files ( & $ files ) { global $ CFG , $ COURSE ; $ files = array ( ) ; if ( empty ( $ _FILES ) ) { return true ; } $ errors = array ( ) ; $ filenames = array ( ) ; foreach ( $ _FILES as $ elname => $ file ) { $ required = $ this -> _form -> isElementRequired ( $ elname ) ; if ( $ file [ 'error' ] == 4...
Internal method . Validates all old - style deprecated uploaded files . The new way is to upload files via repository api .
27,146
protected function validate_draft_files ( ) { global $ USER ; $ mform = & $ this -> _form ; $ errors = array ( ) ; foreach ( $ mform -> _rules as $ elementname => $ rules ) { $ elementtype = $ mform -> getElementType ( $ elementname ) ; if ( ( $ elementtype == 'filepicker' ) || ( $ elementtype == 'filemanager' ) ) { fo...
Internal method . Validates filepicker and filemanager files if they are set as required fields . Also sets the error message if encountered one .
27,147
function no_submit_button_pressed ( ) { static $ nosubmit = null ; if ( ! is_null ( $ nosubmit ) ) { return $ nosubmit ; } $ mform = & $ this -> _form ; $ nosubmit = false ; if ( ! $ this -> is_submitted ( ) ) { return false ; } foreach ( $ mform -> _noSubmitButtons as $ nosubmitbutton ) { if ( optional_param ( $ nosub...
Checks if button pressed is not for submitting the form
27,148
function is_cancelled ( ) { $ mform = & $ this -> _form ; if ( $ mform -> isSubmitted ( ) ) { foreach ( $ mform -> _cancelButtons as $ cancelbutton ) { if ( optional_param ( $ cancelbutton , 0 , PARAM_RAW ) ) { return true ; } } } return false ; }
Return true if a cancel button has been pressed resulting in the form being submitted .
27,149
function get_new_filename ( $ elname = null ) { global $ USER ; if ( ! $ this -> is_submitted ( ) or ! $ this -> is_validated ( ) ) { return false ; } if ( is_null ( $ elname ) ) { if ( empty ( $ _FILES ) ) { return false ; } reset ( $ _FILES ) ; $ elname = key ( $ _FILES ) ; } if ( empty ( $ elname ) ) { return false ...
Returns name of uploaded file .
27,150
function save_file ( $ elname , $ pathname , $ override = false ) { global $ USER ; if ( ! $ this -> is_submitted ( ) or ! $ this -> is_validated ( ) ) { return false ; } if ( file_exists ( $ pathname ) ) { if ( $ override ) { if ( ! @ unlink ( $ pathname ) ) { return false ; } } else { return false ; } } $ element = $...
Save file to standard filesystem
27,151
function save_temp_file ( $ elname ) { if ( ! $ this -> get_new_filename ( $ elname ) ) { return false ; } if ( ! $ dir = make_temp_directory ( 'forms' ) ) { return false ; } if ( ! $ tempfile = tempnam ( $ dir , 'tempup_' ) ) { return false ; } if ( ! $ this -> save_file ( $ elname , $ tempfile , true ) ) { @ unlink (...
Returns a temporary file do not forget to delete after not needed any more .
27,152
protected function get_draft_files ( $ elname ) { global $ USER ; if ( ! $ this -> is_submitted ( ) ) { return false ; } $ element = $ this -> _form -> getElement ( $ elname ) ; if ( $ element instanceof MoodleQuickForm_filepicker || $ element instanceof MoodleQuickForm_filemanager ) { $ values = $ this -> _form -> exp...
Get draft files of a form element This is a protected method which will be used only inside moodleforms
27,153
function save_stored_file ( $ elname , $ newcontextid , $ newcomponent , $ newfilearea , $ newitemid , $ newfilepath = '/' , $ newfilename = null , $ overwrite = false , $ newuserid = null ) { global $ USER ; if ( ! $ this -> is_submitted ( ) or ! $ this -> is_validated ( ) ) { return false ; } if ( empty ( $ newuserid...
Save file to local filesystem pool
27,154
function get_file_content ( $ elname ) { global $ USER ; if ( ! $ this -> is_submitted ( ) or ! $ this -> is_validated ( ) ) { return false ; } $ element = $ this -> _form -> getElement ( $ elname ) ; if ( $ element instanceof MoodleQuickForm_filepicker || $ element instanceof MoodleQuickForm_filemanager ) { $ values =...
Get content of uploaded file .
27,155
public static function mock_submit ( $ simulatedsubmitteddata , $ simulatedsubmittedfiles = array ( ) , $ method = 'post' , $ formidentifier = null ) { $ _FILES = $ simulatedsubmittedfiles ; if ( $ formidentifier === null ) { $ formidentifier = get_called_class ( ) ; $ formidentifier = str_replace ( '\\' , '_' , $ form...
Used by tests to simulate submitted form data submission from the user .
27,156
public static function mock_generate_submit_keys ( $ data = [ ] ) { if ( ! defined ( 'PHPUNIT_TEST' ) || ! PHPUNIT_TEST ) { throw new \ moodle_exception ( "This function can only be used for unit testing." ) ; } $ formidentifier = get_called_class ( ) ; $ formidentifier = str_replace ( '\\' , '_' , $ formidentifier ) ;...
Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data .
27,157
function setExpanded ( $ headername , $ expanded = true , $ ignoreuserstate = false ) { if ( empty ( $ headername ) ) { return ; } $ element = $ this -> getElement ( $ headername ) ; if ( $ element -> getType ( ) != 'header' ) { debugging ( 'Cannot use setExpanded on non-header elements' , DEBUG_DEVELOPER ) ; return ; ...
Use this method to indicate that the fieldset should be shown as expanded . The method is applicable to header elements only .
27,158
function setType ( $ elementname , $ paramtype ) { $ this -> _types [ $ elementname ] = $ paramtype ; if ( ! is_rtl_compatible ( $ paramtype ) && $ this -> elementExists ( $ elementname ) && ( $ element = & $ this -> getElement ( $ elementname ) ) && method_exists ( $ element , 'set_force_ltr' ) ) { $ element -> set_fo...
Should be used for all elements of a form except for select radio and checkboxes which clean their own data .
27,159
function setTypes ( $ paramtypes ) { foreach ( $ paramtypes as $ elementname => $ paramtype ) { $ this -> setType ( $ elementname , $ paramtype ) ; } }
This can be used to set several types at once .
27,160
function updateSubmission ( $ submission , $ files ) { $ this -> _flagSubmitted = false ; if ( empty ( $ submission ) ) { $ this -> _submitValues = array ( ) ; } else { foreach ( $ submission as $ key => $ s ) { $ type = $ this -> getCleanType ( $ key , $ s ) ; $ submission [ $ key ] = $ this -> getCleanedValue ( $ s ,...
Updates submitted values
27,161
function addHelpButton ( $ elementname , $ identifier , $ component = 'moodle' , $ linktext = '' , $ suppresscheck = false ) { global $ OUTPUT ; if ( array_key_exists ( $ elementname , $ this -> _elementIndex ) ) { $ element = $ this -> _elements [ $ this -> _elementIndex [ $ elementname ] ] ; $ element -> _helpbutton ...
Add a help button to element only one button per element is allowed .
27,162
function exportValues ( $ elementList = null ) { $ unfiltered = array ( ) ; if ( null === $ elementList ) { foreach ( array_keys ( $ this -> _elements ) as $ key ) { if ( $ this -> _elements [ $ key ] -> isFrozen ( ) && ! $ this -> _elements [ $ key ] -> _persistantFreeze ) { $ varname = $ this -> _elements [ $ key ] -...
export submitted values
27,163
function _setDefaultRuleMessages ( ) { foreach ( $ this -> _rules as $ field => $ rulesarr ) { foreach ( $ rulesarr as $ key => $ rule ) { if ( $ rule [ 'message' ] === null ) { $ a = new stdClass ( ) ; $ a -> format = $ rule [ 'format' ] ; $ str = get_string ( 'err_' . $ rule [ 'type' ] , 'form' , $ a ) ; if ( strpos ...
Sets default error message
27,164
function getLockOptionObject ( ) { $ result = array ( ) ; foreach ( $ this -> _dependencies as $ dependentOn => $ conditions ) { $ result [ $ dependentOn ] = array ( ) ; foreach ( $ conditions as $ condition => $ values ) { $ result [ $ dependentOn ] [ $ condition ] = array ( ) ; foreach ( $ values as $ value => $ depe...
Get list of attributes which have dependencies
27,165
function _getElNamesRecursive ( $ element ) { if ( is_string ( $ element ) ) { if ( ! $ this -> elementExists ( $ element ) ) { return array ( ) ; } $ element = $ this -> getElement ( $ element ) ; } if ( is_a ( $ element , 'HTML_QuickForm_group' ) ) { $ elsInGroup = $ element -> getElements ( ) ; $ elNames = array ( )...
Get names of element or elements in a group .
27,166
function startForm ( & $ form ) { global $ PAGE ; $ this -> _reqHTML = $ form -> getReqHTML ( ) ; $ this -> _elementTemplates = str_replace ( '{req}' , $ this -> _reqHTML , $ this -> _elementTemplates ) ; $ this -> _advancedHTML = $ form -> getAdvancedHTML ( ) ; $ this -> _collapseButtons = '' ; $ formid = $ form -> ge...
What to do when starting the form
27,167
function validate ( $ value , $ options = null ) { global $ CFG ; if ( is_array ( $ value ) && array_key_exists ( 'text' , $ value ) ) { $ value = $ value [ 'text' ] ; } if ( is_array ( $ value ) ) { $ value = implode ( '' , $ value ) ; } $ stripvalues = array ( '#</?(?!img|canvas|hr).*?>#im' , '#(\xc2\xa0|\s|&nbsp;)#'...
Checks if an element is not empty . This is a server - side validation it works for both text fields and editor fields
27,168
function getValidationScript ( $ format = null ) { global $ CFG ; if ( ! empty ( $ CFG -> strictformsrequired ) ) { if ( ! empty ( $ format ) && $ format == FORMAT_HTML ) { return array ( '' , "{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\s+/ig, '') == ''" ) ; } else { return array ( '' , "{jsVar}.replace(/^\s+$...
This function returns Javascript code used to build client - side validation . It checks if an element is not empty .
27,169
private function writeRows ( PHPExcel_Shared_XMLWriter $ objWriter , PHPExcel_Worksheet $ sheet ) { $ number_rows_repeated = self :: NUMBER_ROWS_REPEATED_MAX ; $ span_row = 0 ; $ rows = $ sheet -> getRowIterator ( ) ; while ( $ rows -> valid ( ) ) { $ number_rows_repeated -- ; $ row = $ rows -> current ( ) ; if ( $ row...
Write rows of the specified sheet
27,170
private function writeCells ( PHPExcel_Shared_XMLWriter $ objWriter , PHPExcel_Worksheet_Row $ row ) { $ number_cols_repeated = self :: NUMBER_COLS_REPEATED_MAX ; $ prev_column = - 1 ; $ cells = $ row -> getCellIterator ( ) ; while ( $ cells -> valid ( ) ) { $ cell = $ cells -> current ( ) ; $ column = PHPExcel_Cell ::...
Write cells of the specified row
27,171
public static function create ( $ content_model , $ content_model_type , $ attr ) { $ def = new HTMLPurifier_ElementDef ( ) ; $ def -> content_model = $ content_model ; $ def -> content_model_type = $ content_model_type ; $ def -> attr = $ attr ; return $ def ; }
Low - level factory constructor for creating new standalone element defs
27,172
public function mergeIn ( $ def ) { foreach ( $ def -> attr as $ k => $ v ) { if ( $ k === 0 ) { foreach ( $ v as $ v2 ) { $ this -> attr [ 0 ] [ ] = $ v2 ; } continue ; } if ( $ v === false ) { if ( isset ( $ this -> attr [ $ k ] ) ) { unset ( $ this -> attr [ $ k ] ) ; } continue ; } $ this -> attr [ $ k ] = $ v ; } ...
Merges the values of another element definition into this one . Values from the new element def take precedence if a value is not mergeable .
27,173
private function _mergeAssocArray ( & $ a1 , $ a2 ) { foreach ( $ a2 as $ k => $ v ) { if ( $ v === false ) { if ( isset ( $ a1 [ $ k ] ) ) { unset ( $ a1 [ $ k ] ) ; } continue ; } $ a1 [ $ k ] = $ v ; } }
Merges one array into another removes values which equal false
27,174
protected function define_lti_subplugin_structure ( ) { $ paths = array ( ) ; $ elename = $ this -> get_namefor ( 'lineitem' ) ; $ elepath = $ this -> get_pathfor ( '/lineitems/lineitem' ) ; $ paths [ ] = new restore_path_element ( $ elename , $ elepath ) ; return $ paths ; }
Returns the subplugin structure to attach to the XML element .
27,175
public function process_ltiservice_gradebookservices_lineitem ( $ data ) { global $ DB ; $ data = ( object ) $ data ; $ activitytask = $ this -> task ; $ courseid = $ activitytask -> get_courseid ( ) ; if ( $ data -> typeid != null ) { if ( $ ltitypeid = $ this -> get_mappingid ( 'ltitype' , $ data -> typeid ) ) { $ ne...
Processes one lineitem
27,176
protected function after_restore_lti ( ) { global $ DB ; $ activitytask = $ this -> task ; $ courseid = $ activitytask -> get_courseid ( ) ; $ gbstoupdate = $ DB -> get_records ( 'ltiservice_gradebookservices' , array ( 'gradeitemid' => 0 , 'courseid' => $ courseid ) ) ; foreach ( $ gbstoupdate as $ gbs ) { $ oldgradei...
We call the after_restore_lti to update the grade_items id s that we didn t know in the moment of creating the gradebookservices rows .
27,177
protected function get_writer_instance ( ) : content_writer { if ( null === $ this -> realwriter ) { if ( PHPUNIT_TEST ) { $ this -> realwriter = new \ core_privacy \ tests \ request \ content_writer ( static :: instance ( ) ) ; } else { $ this -> realwriter = new moodle_content_writer ( static :: instance ( ) ) ; } } ...
Singleton to return or create and return a copy of a content_writer .
27,178
public static function setup_real_writer_instance ( ) { if ( ! PHPUNIT_TEST ) { throw new coding_exception ( 'setup_real_writer_instance() is only for use with PHPUnit tests.' ) ; } $ instance = static :: instance ( ) ; if ( null === $ instance -> realwriter ) { $ instance -> realwriter = new moodle_content_writer ( st...
Create a real content_writer for use by PHPUnit tests where a mock writer will not suffice .
27,179
public function random_selector_string ( ) { if ( $ this -> question -> qtype == 'random' ) { return $ this -> question -> category . '/' . $ this -> question -> questiontext ; } else { return null ; } }
Used to determine which random questions pull sub questions from the same pools . Where pool means category and possibly all the sub categories of that category .
27,180
public function cache ( $ qubaids ) { global $ DB ; $ toinsert = new \ stdClass ( ) ; $ toinsert -> hashcode = $ qubaids -> get_hash_code ( ) ; $ toinsert -> timemodified = time ( ) ; foreach ( $ this -> fieldsindb as $ field ) { $ toinsert -> { $ field } = $ this -> { $ field } ; } $ DB -> insert_record ( 'question_st...
Cache calculated stats stored in this object in question_statistics table .
27,181
public function populate_from_record ( $ record ) { foreach ( $ this -> fieldsindb as $ field ) { $ this -> $ field = $ record -> $ field ; } $ this -> timemodified = $ record -> timemodified ; }
Load properties of this class from db record .
27,182
public function get_variants ( ) { $ variants = array_keys ( $ this -> variantstats ) ; if ( count ( $ variants ) > 1 || reset ( $ variants ) != 1 ) { return $ variants ; } else { return array ( ) ; } }
Array of variants that have appeared in the attempt data for this question . Or an empty array if there is only one variant .
27,183
public function break_down_by_variant ( ) { $ qtype = \ question_bank :: get_qtype ( $ this -> question -> qtype ) ; return $ qtype -> break_down_stats_and_response_analysis_by_variant ( $ this -> question ) ; }
Do we break down the stats for this question by variant or not?
27,184
public static function get ( $ classname ) { $ contexts = self :: $ environment -> getContexts ( ) ; foreach ( $ contexts as $ context ) { if ( is_a ( $ context , $ classname ) ) { return $ context ; } } $ suitename = self :: $ environment -> getSuite ( ) -> getName ( ) ; if ( $ suitename == 'default' ) { $ suitename =...
Gets the required context .
27,185
public static function escape ( $ label ) { if ( empty ( self :: $ escaper ) ) { self :: $ escaper = new \ Behat \ Mink \ Selector \ Xpath \ Escaper ( ) ; } return self :: $ escaper -> escapeLiteral ( $ label ) ; }
Translates string to XPath literal .
27,186
public function stripNamespace ( $ mbox ) { $ mbox = strval ( $ mbox ) ; $ name = $ this -> name ; return ( strlen ( $ name ) && ( strpos ( $ mbox , $ name ) === 0 ) ) ? substr ( $ mbox , strlen ( $ name ) ) : $ mbox ; }
Strips namespace information from the given mailbox name .
27,187
private function remove_button ( $ buttonname ) { $ el = $ this -> _form -> getElement ( 'buttonar' ) ; foreach ( $ el -> _elements as $ idx => $ button ) { if ( $ button instanceof MoodleQuickForm_submit && $ button -> getName ( ) === $ buttonname ) { unset ( $ el -> _elements [ $ idx ] ) ; return ; } } }
Removes the button that is not applicable for the current page
27,188
public function get_item_value ( $ item ) { if ( $ this -> structure instanceof mod_feedback_completion ) { return $ this -> structure -> get_item_value ( $ item ) ; } return null ; }
Returns value for this element that is already stored in temporary or permanent table usually only available when user clicked Previous page . Null means no value is stored .
27,189
protected function get_suggested_class ( $ item ) { $ class = "feedback_itemlist feedback-item-{$item->typ}" ; if ( $ item -> dependitem ) { $ class .= " feedback_is_dependent" ; } if ( $ item -> typ !== 'pagebreak' ) { $ itemobj = feedback_get_item_class ( $ item -> typ ) ; if ( $ itemobj -> get_hasvalue ( ) ) { $ cla...
CSS class for the item
27,190
protected function add_item_label ( $ item , $ element ) { if ( strlen ( $ item -> label ) && ( $ this -> mode == self :: MODE_EDIT || $ this -> mode == self :: MODE_VIEW_TEMPLATE ) ) { $ name = $ element -> getLabel ( ) ; $ name = '(' . format_string ( $ item -> label ) . ') ' . $ name ; $ element -> setLabel ( $ name...
Adds an item label to the question name
27,191
protected function add_item_dependencies ( $ item , $ element ) { $ allitems = $ this -> structure -> get_items ( ) ; if ( $ item -> dependitem && ( $ this -> mode == self :: MODE_EDIT || $ this -> mode == self :: MODE_VIEW_TEMPLATE ) ) { if ( isset ( $ allitems [ $ item -> dependitem ] ) ) { $ dependitem = $ allitems ...
Adds a dependency description to the question name
27,192
protected function guess_element_id ( $ item , $ element ) { if ( ! $ id = $ element -> getAttribute ( 'id' ) ) { $ attributes = $ element -> getAttributes ( ) ; $ id = $ attributes [ 'id' ] = 'feedback_item_' . $ item -> id ; $ element -> setAttributes ( $ attributes ) ; } if ( $ element -> getType ( ) === 'group' ) {...
Returns the CSS id attribute that will be assigned by moodleform later to this element
27,193
protected function enhance_name_for_edit ( $ item , $ element ) { global $ OUTPUT ; $ menu = new action_menu ( ) ; $ menu -> set_owner_selector ( '#' . $ this -> guess_element_id ( $ item , $ element ) ) ; $ menu -> set_constraint ( '.feedback_form' ) ; $ menu -> set_alignment ( action_menu :: TR , action_menu :: BR ) ...
Adds editing actions to the question name in the edit mode
27,194
public function add_validation_rule ( callable $ callback ) { if ( $ this -> mode == self :: MODE_COMPLETE ) { $ this -> _form -> addFormRule ( $ callback ) ; } }
Adds a validation rule to the form
27,195
protected function ldap_find_user_groups_recursively ( $ memberdn , & $ membergroups ) { $ result = @ ldap_read ( $ this -> ldapconnection , $ memberdn , '(objectClass=*)' , array ( $ this -> get_config ( 'group_memberofattribute' ) ) ) ; if ( ! $ result ) { return ; } if ( $ entry = ldap_first_entry ( $ this -> ldapco...
Recursively process the groups the given member distinguished name belongs to adding them to the already processed groups array .
27,196
protected function update_course ( $ course , $ externalcourse , progress_trace $ trace ) { global $ CFG , $ DB ; $ coursefields = array ( 'shortname' , 'fullname' , 'summary' ) ; static $ shouldupdate ; if ( ! isset ( $ shouldupdate ) ) { $ shouldupdate = false ; foreach ( $ coursefields as $ field ) { $ shouldupdate ...
Will update a moodle course with new values from LDAP A field will be updated only if it is marked to be updated on sync in plugin settings
27,197
function parse_charset ( $ charset ) { $ charset = trim ( strtolower ( $ charset ) ) ; if ( isset ( $ this -> synonyms [ $ charset ] ) ) { $ charset = $ this -> synonyms [ $ charset ] ; } return $ charset ; }
Normalize - changes input character set to lowercase letters .
27,198
function get_locale_charset ( $ locale ) { $ locale = strtolower ( $ locale ) ; if ( isset ( $ this -> locale_to_charset [ $ locale ] ) ) { return $ this -> locale_to_charset [ $ locale ] ; } list ( $ locale , $ modifier ) = explode ( '@' , $ locale ) ; list ( $ locale , $ charset ) = explode ( '.' , $ locale ) ; if ( ...
Get the charset of a locale .
27,199
function conv ( $ str , $ fromCS , $ toCS , $ useEntityForNoChar = 0 ) { if ( $ fromCS == $ toCS ) { return $ str ; } if ( $ toCS == 'utf-8' || ! $ useEntityForNoChar ) { switch ( $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'SYS' ] [ 't3lib_cs_convMethod' ] ) { case 'mbstring' : $ conv_str = mb_convert_encoding ( $ str , $ toCS ...
Convert from one charset to another charset .