idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
34,000
public function finish_table_export ( xmldb_table $ table ) { $ this -> feedback -> output ( get_string ( 'done' , 'core_dbtransfer' , $ table -> getName ( ) ) , 2 ) ; $ this -> importer -> finish_table_import ( $ table -> getName ( ) ) ; }
Callback function . Calls importer s finish_table_import callback method .
34,001
public function recode_legacy_state_answer ( $ state ) { global $ DB ; $ answer = $ state -> answer ; $ resultarr = array ( ) ; $ sequence = $ DB -> get_field ( 'question_multianswer' , 'sequence' , array ( 'question' => $ state -> question ) ) ; $ sequencearr = explode ( ',' , $ sequence ) ; foreach ( explode ( ',' , ...
Given one question_states record return the answer recoded pointing to all the restored stuff for multianswer questions
34,002
public static function can_use_tls12 ( array $ curlinfo , $ uname ) { if ( ! defined ( 'CURL_SSLVERSION_TLSv1_2' ) ) { return false ; } $ sslversion = explode ( '/' , $ curlinfo [ 'ssl_version' ] ) ; $ flavour = explode ( ' ' , $ sslversion [ 0 ] ) [ 0 ] ; $ version = count ( $ sslversion ) == 2 ? $ sslversion [ 1 ] : ...
Tests if the system is capable of using TLS 1 . 2 for requests .
34,003
public function getCacheKey ( ) { if ( ! $ this -> useCache ) { return false ; } $ h = $ this -> sub ; $ h .= $ this -> assertionType ; $ h .= $ this -> privateKey ; $ h .= $ this -> scopes ; $ h .= $ this -> serviceAccountName ; return md5 ( $ h ) ; }
Generate a unique key to represent this credential .
34,004
function _tag_cdata ( & $ parser , $ cdata ) { switch ( $ this -> currentElement ) { case 'CONSTRAINT' : if ( isset ( $ this -> current_field ) ) { $ this -> addFieldOpt ( $ this -> current_field , $ this -> currentElement , $ cdata ) ; } else { $ this -> addTableOpt ( $ cdata ) ; } break ; case 'OPT' : $ this -> addTa...
XML Callback to process CDATA elements
34,005
public static function get_async_backup_progress ( $ backupids , $ contextid ) { global $ CFG ; require_once ( $ CFG -> dirroot . '/backup/util/includes/backup_includes.php' ) ; require_once ( $ CFG -> dirroot . '/backup/util/includes/restore_includes.php' ) ; self :: validate_parameters ( self :: get_async_backup_prog...
Get asynchronous backup progress .
34,006
public static function get_async_backup_links_backup ( $ filename , $ contextid ) { self :: validate_parameters ( self :: get_async_backup_links_backup_parameters ( ) , array ( 'filename' => $ filename , 'contextid' => $ contextid ) ) ; list ( $ context , $ course , $ cm ) = get_context_info_array ( $ contextid ) ; sel...
Get the data to be used when generating the table row for an asynchronous backup the table row updates via ajax when backup is complete .
34,007
public static function get_async_backup_links_restore ( $ backupid , $ contextid ) { self :: validate_parameters ( self :: get_async_backup_links_restore_parameters ( ) , array ( 'backupid' => $ backupid , 'contextid' => $ contextid ) ) ; $ context = context :: instance_by_id ( $ contextid ) ; self :: validate_context ...
Get the data to be used when generating the table row for an asynchronous restore the table row updates via ajax when restore is complete .
34,008
public static function course_updated ( \ core \ event \ course_updated $ event ) { if ( class_exists ( 'format_weeks' , false ) ) { format_weeks :: update_end_date ( $ event -> courseid ) ; } }
Triggered via \ core \ event \ course_updated event .
34,009
public static function course_section_created ( \ core \ event \ course_section_created $ event ) { if ( class_exists ( 'format_weeks' , false ) ) { format_weeks :: update_end_date ( $ event -> courseid ) ; } }
Triggered via \ core \ event \ course_section_created event .
34,010
public static function course_section_deleted ( \ core \ event \ course_section_deleted $ event ) { if ( class_exists ( 'format_weeks' , false ) ) { format_weeks :: update_end_date ( $ event -> courseid ) ; } }
Triggered via \ core \ event \ course_section_deleted event .
34,011
public function execute ( ) { $ this -> result = ( $ this -> validate_files_layout ( ) and $ this -> validate_version_php ( ) and $ this -> validate_language_pack ( ) and $ this -> validate_target_location ( ) ) ; return $ this -> result ; }
Execute the validation process against all explicit and implicit requirements
34,012
public function message_code_name ( $ msgcode ) { $ stringman = get_string_manager ( ) ; if ( $ stringman -> string_exists ( 'validationmsg_' . $ msgcode , 'core_plugin' ) ) { return get_string ( 'validationmsg_' . $ msgcode , 'core_plugin' ) ; } return $ msgcode ; }
If defined returns human readable validation code .
34,013
public function message_help_icon ( $ msgcode ) { $ stringman = get_string_manager ( ) ; if ( $ stringman -> string_exists ( 'validationmsg_' . $ msgcode . '_help' , 'core_plugin' ) ) { return new help_icon ( 'validationmsg_' . $ msgcode , 'core_plugin' ) ; } return false ; }
Returns help icon for the message code if defined .
34,014
public function message_code_info ( $ msgcode , $ addinfo ) { $ stringman = get_string_manager ( ) ; if ( $ addinfo !== null and $ stringman -> string_exists ( 'validationmsg_' . $ msgcode . '_info' , 'core_plugin' ) ) { return get_string ( 'validationmsg_' . $ msgcode . '_info' , 'core_plugin' , $ addinfo ) ; } return...
Localizes the message additional info if it exists .
34,015
protected function validate_files_layout ( ) { if ( ! is_array ( $ this -> extractfiles ) or count ( $ this -> extractfiles ) < 4 ) { $ this -> add_message ( self :: ERROR , 'filesnumber' ) ; return false ; } foreach ( $ this -> extractfiles as $ filerelname => $ filestatus ) { if ( $ filestatus !== true ) { $ this -> ...
Returns false if files in the ZIP do not have required layout .
34,016
protected function validate_language_pack ( ) { if ( ! isset ( $ this -> assertions [ 'plugintype' ] ) ) { throw new coding_exception ( 'Required plugin type must be set before calling this' ) ; } if ( ! isset ( $ this -> extractfiles [ $ this -> rootdir . '/lang/en/' ] ) or $ this -> extractfiles [ $ this -> rootdir ....
Returns false if the English language pack is not provided correctly .
34,017
public function validate_target_location ( ) { if ( ! isset ( $ this -> assertions [ 'plugintype' ] ) ) { throw new coding_exception ( 'Required plugin type must be set before calling this' ) ; } $ plugintypepath = $ this -> get_plugintype_location ( $ this -> assertions [ 'plugintype' ] ) ; if ( is_null ( $ plugintype...
Returns false of the given add - on can t be installed into its location .
34,018
protected function parse_version_php ( $ fullpath ) { $ content = $ this -> get_stripped_file_contents ( $ fullpath ) ; preg_match_all ( '#\$((plugin|module)\->(version|maturity|release|requires))=()(\d+(\.\d+)?);#m' , $ content , $ matches1 ) ; preg_match_all ( '#\$((plugin|module)\->(maturity))=()(MATURITY_\w+);#m' ,...
Get as much information from existing version . php as possible
34,019
protected function add_message ( $ level , $ msgcode , $ a = null ) { $ msg = ( object ) array ( 'level' => $ level , 'msgcode' => $ msgcode , 'addinfo' => $ a , ) ; $ this -> messages [ ] = $ msg ; }
Append the given message to the messages log
34,020
protected function get_stripped_file_contents ( $ fullpath ) { $ source = file_get_contents ( $ fullpath ) ; $ tokens = token_get_all ( $ source ) ; $ output = '' ; $ doprocess = false ; foreach ( $ tokens as $ token ) { if ( is_string ( $ token ) ) { $ id = - 1 ; $ text = $ token ; } else { list ( $ id , $ text ) = $ ...
Returns bare PHP code from the given file
34,021
public function edit_field_add ( $ mform ) { $ checkbox = $ mform -> addElement ( 'advcheckbox' , $ this -> inputname , format_string ( $ this -> field -> name ) ) ; if ( $ this -> data == '1' ) { $ checkbox -> setChecked ( true ) ; } $ mform -> setType ( $ this -> inputname , PARAM_BOOL ) ; if ( $ this -> is_required ...
Add elements for editing the profile field value .
34,022
public function edit_field ( $ mform ) { if ( ! $ this -> is_editable ( ) ) { return false ; } $ this -> edit_field_add ( $ mform ) ; $ this -> edit_field_set_default ( $ mform ) ; $ this -> edit_field_set_required ( $ mform ) ; return true ; }
Print out the form field in the edit profile page
34,023
public function edit_validate_field ( $ usernew ) { global $ DB ; $ errors = array ( ) ; if ( isset ( $ usernew -> { $ this -> inputname } ) ) { if ( is_array ( $ usernew -> { $ this -> inputname } ) && isset ( $ usernew -> { $ this -> inputname } [ 'text' ] ) ) { $ value = $ usernew -> { $ this -> inputname } [ 'text'...
Validate the form field from profile page
34,024
public function edit_field_set_default ( $ mform ) { if ( ! empty ( $ this -> field -> defaultdata ) ) { $ mform -> setDefault ( $ this -> inputname , $ this -> field -> defaultdata ) ; } }
Sets the default data for the field in the form object
34,025
public function edit_field_set_required ( $ mform ) { global $ USER ; if ( $ this -> is_required ( ) && ( $ this -> userid == $ USER -> id || isguestuser ( ) ) ) { $ mform -> addRule ( $ this -> inputname , get_string ( 'required' ) , 'required' , null , 'client' ) ; } }
Sets the required flag for the field in the form object
34,026
public function edit_load_user_data ( $ user ) { if ( $ this -> data !== null ) { $ user -> { $ this -> inputname } = $ this -> data ; } }
Loads a user object with data for this field ready for the edit profile form
34,027
public function get_category_name ( ) { global $ DB ; if ( $ this -> categoryname === null ) { $ this -> categoryname = $ DB -> get_field ( 'user_info_category' , 'name' , [ 'id' => $ this -> field -> categoryid ] ) ; } return $ this -> categoryname ; }
Returns the name of the profile category where this field is
34,028
public function is_visible ( ) { global $ USER ; $ context = ( $ this -> userid > 0 ) ? context_user :: instance ( $ this -> userid ) : context_system :: instance ( ) ; switch ( $ this -> field -> visible ) { case PROFILE_VISIBLE_ALL : return true ; case PROFILE_VISIBLE_PRIVATE : if ( $ this -> is_signup_field ( ) && (...
Check if the field data is visible to the current user
34,029
public function is_editable ( ) { global $ USER ; if ( ! $ this -> is_visible ( ) ) { return false ; } if ( $ this -> is_signup_field ( ) && ( empty ( $ this -> userid ) || isguestuser ( $ this -> userid ) ) ) { return true ; } $ systemcontext = context_system :: instance ( ) ; if ( $ this -> userid == $ USER -> id && ...
Check if the field data is editable for the current user This method should not generally be overwritten by child classes .
34,030
public function get_contextvisibility ( $ context ) { global $ USER ; if ( $ context -> contextlevel == CONTEXT_COURSE ) { return $ this -> _options [ 'enablecourseinstances' ] ; } if ( $ context -> contextlevel == CONTEXT_USER ) { return $ this -> _options [ 'enableuserinstances' ] ; } return true ; }
Return if the instance is visible in a context
34,031
public function update_options ( $ options = null ) { global $ DB ; $ classname = 'repository_' . $ this -> _typename ; $ instanceoptions = repository :: static_function ( $ this -> _typename , 'get_instance_option_names' ) ; if ( empty ( $ instanceoptions ) ) { $ params = array ( ) ; $ params [ 'type' ] = $ this -> _t...
Update plugin options into the config_plugin table
34,032
public function update_visibility ( $ visible = null ) { if ( is_bool ( $ visible ) ) { $ this -> _visible = $ visible ; } else { $ this -> _visible = ! $ this -> _visible ; } return $ this -> update_visible ( ) ; }
1 . Change visibility to the value chosen 2 . Update the type
34,033
public static function get_repository_by_id ( $ repositoryid , $ context , $ options = array ( ) ) { global $ CFG , $ DB ; $ cache = cache :: make ( 'core' , 'repositories' ) ; if ( ! is_object ( $ context ) ) { $ context = context :: instance_by_id ( $ context ) ; } $ cachekey = 'rep:' . $ repositoryid . ':' . $ conte...
Get repository instance using repository id
34,034
public function get_typename ( ) { if ( empty ( $ this -> typename ) ) { $ matches = array ( ) ; if ( ! preg_match ( "/^repository_(.*)$/" , get_class ( $ this ) , $ matches ) ) { throw new coding_exception ( 'The class name of a repository should be repository_<typeofrepository>, ' . 'e.g. repository_dropbox' ) ; } $ ...
Returns the type name of the repository .
34,035
public static function get_type_by_typename ( $ typename ) { global $ DB ; $ cache = cache :: make ( 'core' , 'repositories' ) ; if ( ( $ repositorytype = $ cache -> get ( 'typename:' . $ typename ) ) === false ) { $ repositorytype = null ; if ( $ record = $ DB -> get_record ( 'repository' , array ( 'type' => $ typenam...
Get a repository type object by a given type name .
34,036
public final function check_capability ( ) { global $ USER ; $ currentcontext = $ this -> context ; $ can = has_capability ( 'repository/' . $ this -> get_typename ( ) . ':view' , $ currentcontext ) ; $ repocontext = context :: instance_by_id ( $ this -> instance -> contextid ) ; if ( $ can && \ core \ session \ manage...
Checks if user has a capability to view the current repository .
34,037
public static function draftfile_exists ( $ itemid , $ filepath , $ filename ) { global $ USER ; $ fs = get_file_storage ( ) ; $ usercontext = context_user :: instance ( $ USER -> id ) ; return $ fs -> file_exists ( $ usercontext -> id , 'user' , 'draft' , $ itemid , $ filepath , $ filename ) ; }
Check if file already exists in draft area .
34,038
public static function get_moodle_file ( $ reference ) { $ params = file_storage :: unpack_reference ( $ reference , true ) ; $ fs = get_file_storage ( ) ; return $ fs -> get_file ( $ params [ 'contextid' ] , $ params [ 'component' ] , $ params [ 'filearea' ] , $ params [ 'itemid' ] , $ params [ 'filepath' ] , $ params...
Parses the moodle file reference and returns an instance of stored_file
34,039
public static function get_unused_filename ( $ itemid , $ filepath , $ filename ) { global $ USER ; $ contextid = context_user :: instance ( $ USER -> id ) -> id ; $ fs = get_file_storage ( ) ; return $ fs -> get_unused_filename ( $ contextid , 'user' , 'draft' , $ itemid , $ filepath , $ filename ) ; }
Get an unused filename from the current draft area .
34,040
public static function append_suffix ( $ filename ) { debugging ( 'The function repository::append_suffix() has been deprecated. Use repository::get_unused_filename() instead.' , DEBUG_DEVELOPER ) ; $ pathinfo = pathinfo ( $ filename ) ; if ( empty ( $ pathinfo [ 'extension' ] ) ) { return $ filename . RENAME_SUFFIX ; ...
Append a suffix to filename .
34,041
public static function static_function ( $ plugin , $ function ) { global $ CFG ; $ typedirectory = $ CFG -> dirroot . '/repository/' . $ plugin . '/lib.php' ; if ( ! file_exists ( $ typedirectory ) ) { return false ; } $ args = func_get_args ( ) ; if ( count ( $ args ) <= 2 ) { $ args = array ( ) ; } else { array_shif...
Call a static function . Any additional arguments than plugin and function will be passed through .
34,042
public static function antivir_scan_file ( $ thefile , $ filename , $ deleteinfected ) { debugging ( 'Please upgrade your code to use \core\antivirus\manager::scan_file instead' , DEBUG_DEVELOPER ) ; \ core \ antivirus \ manager :: scan_file ( $ thefile , $ filename , $ deleteinfected ) ; }
Scan file throws exception in case of infected file .
34,043
public static function move_to_filepool ( $ thefile , $ record ) { global $ DB , $ CFG , $ USER , $ OUTPUT ; \ core \ antivirus \ manager :: scan_file ( $ thefile , $ record -> filename , empty ( $ CFG -> repository_no_delete ) ) ; $ fs = get_file_storage ( ) ; if ( repository :: draftfile_exists ( $ record -> itemid ,...
Move file from download folder to file pool using FILE API
34,044
public function get_file ( $ url , $ filename = '' ) { global $ CFG ; $ path = $ this -> prepare_file ( $ filename ) ; $ c = new curl ; $ result = $ c -> download_one ( $ url , null , array ( 'filepath' => $ path , 'timeout' => $ CFG -> repositorygetfiletimeout ) ) ; if ( $ result !== true ) { throw new moodle_exceptio...
Downloads a file from external repository and saves it in temp dir
34,045
public function get_file_size ( $ source ) { $ browser = get_file_browser ( ) ; $ params = unserialize ( base64_decode ( $ source ) ) ; $ contextid = clean_param ( $ params [ 'contextid' ] , PARAM_INT ) ; $ fileitemid = clean_param ( $ params [ 'itemid' ] , PARAM_INT ) ; $ filename = clean_param ( $ params [ 'filename'...
Return size of a file in bytes .
34,046
public final function can_be_edited_by_user ( ) { global $ USER ; try { $ this -> check_capability ( ) ; } catch ( repository_exception $ e ) { return false ; } $ repocontext = context :: instance_by_id ( $ this -> instance -> contextid ) ; if ( $ repocontext -> contextlevel == CONTEXT_USER && $ repocontext -> instance...
Can the instance be edited by the current user?
34,047
final public function get_meta ( ) { global $ CFG , $ OUTPUT ; $ meta = new stdClass ( ) ; $ meta -> id = $ this -> id ; $ meta -> name = format_string ( $ this -> get_name ( ) ) ; $ meta -> type = $ this -> get_typename ( ) ; $ meta -> icon = $ OUTPUT -> image_url ( 'icon' , 'repository_' . $ meta -> type ) -> out ( f...
Provide repository instance information for Ajax
34,048
final public function delete ( $ downloadcontents = false ) { global $ DB ; if ( $ downloadcontents ) { $ this -> convert_references_to_local ( ) ; } else { $ this -> remove_files ( ) ; } cache :: make ( 'core' , 'repositories' ) -> purge ( ) ; try { $ DB -> delete_records ( 'repository_instances' , array ( 'id' => $ t...
delete a repository instance
34,049
final public static function delete_all_for_context ( $ contextid , $ downloadcontents = true ) { global $ DB ; $ repoids = $ DB -> get_fieldset_select ( 'repository_instances' , 'id' , 'contextid = :contextid' , array ( 'contextid' => $ contextid ) ) ; if ( $ downloadcontents ) { foreach ( $ repoids as $ repoid ) { $ ...
Delete all the instances associated to a context .
34,050
public function get_option ( $ config = '' ) { global $ DB ; $ cache = cache :: make ( 'core' , 'repositories' ) ; if ( ( $ entries = $ cache -> get ( 'ops:' . $ this -> id ) ) === false ) { $ entries = $ DB -> get_records ( 'repository_instance_config' , array ( 'instanceid' => $ this -> id ) ) ; $ cache -> set ( 'ops...
Get settings for repository instance .
34,051
public function filter ( & $ value ) { $ accepted_types = optional_param_array ( 'accepted_types' , '' , PARAM_RAW ) ; if ( isset ( $ value [ 'children' ] ) ) { if ( ! empty ( $ value [ 'children' ] ) ) { $ value [ 'children' ] = array_filter ( $ value [ 'children' ] , array ( $ this , 'filter' ) ) ; } return true ; } ...
Filter file listing to display specific types
34,052
protected static function prepare_breadcrumb ( $ breadcrumb ) { global $ OUTPUT ; $ foldericon = $ OUTPUT -> image_url ( file_folder_icon ( 24 ) ) -> out ( false ) ; $ len = count ( $ breadcrumb ) ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { if ( is_array ( $ breadcrumb [ $ i ] ) && ! isset ( $ breadcrumb [ $ i ] [ 'icon...
Prepare the breadcrumb .
34,053
public static function prepare_listing ( $ listing ) { $ wasobject = false ; if ( is_object ( $ listing ) ) { $ listing = ( array ) $ listing ; $ wasobject = true ; } if ( isset ( $ listing [ 'path' ] ) && is_array ( $ listing [ 'path' ] ) ) { $ listing [ 'path' ] = self :: prepare_breadcrumb ( $ listing [ 'path' ] ) ;...
Prepares list of files before passing it to AJAX makes sure data is in the correct format and stores formatted values .
34,054
public function get_short_filename ( $ str , $ maxlength ) { if ( core_text :: strlen ( $ str ) >= $ maxlength ) { return trim ( core_text :: substr ( $ str , 0 , $ maxlength ) ) . '...' ; } else { return $ str ; } }
Create a shorten filename
34,055
public static function overwrite_existing_draftfile ( $ itemid , $ filepath , $ filename , $ newfilepath , $ newfilename ) { global $ USER ; $ fs = get_file_storage ( ) ; $ user_context = context_user :: instance ( $ USER -> id ) ; if ( $ file = $ fs -> get_file ( $ user_context -> id , 'user' , 'draft' , $ itemid , $ ...
Overwrite an existing file
34,056
public static function delete_tempfile_from_draft ( $ draftitemid , $ filepath , $ filename ) { global $ USER ; $ fs = get_file_storage ( ) ; $ user_context = context_user :: instance ( $ USER -> id ) ; if ( $ file = $ fs -> get_file ( $ user_context -> id , 'user' , 'draft' , $ draftitemid , $ filepath , $ filename ) ...
Delete a temp file from draft area
34,057
public function convert_references_to_local ( ) { $ fs = get_file_storage ( ) ; $ files = $ fs -> get_external_files ( $ this -> id ) ; foreach ( $ files as $ storedfile ) { $ fs -> import_external_file ( $ storedfile ) ; } }
Find all external files in this repo and import them
34,058
public function remove_files ( ) { $ fs = get_file_storage ( ) ; $ files = $ fs -> get_external_files ( $ this -> id ) ; foreach ( $ files as $ storedfile ) { $ storedfile -> delete ( ) ; } }
Find all external files linked to this repository and delete them .
34,059
public function prepare_to_cache ( ) { return array ( 'class' => get_class ( $ this ) , 'id' => $ this -> id , 'ctxid' => $ this -> context -> id , 'options' => $ this -> options , 'readonly' => $ this -> readonly ) ; }
Prepares the repository to be cached . Implements method from cacheable_object interface .
34,060
final static public function get_secret_key ( ) { global $ CFG ; if ( ! isset ( $ CFG -> reposecretkey ) ) { set_config ( 'reposecretkey' , time ( ) . random_string ( 32 ) ) ; } return $ CFG -> reposecretkey ; }
Generate a secret key to be used for passing sensitive information around .
34,061
protected function add_defaults ( ) { $ mform = & $ this -> _form ; $ strrequired = get_string ( 'required' ) ; $ mform -> addElement ( 'hidden' , 'edit' , ( $ this -> instance ) ? $ this -> instance -> id : 0 ) ; $ mform -> setType ( 'edit' , PARAM_INT ) ; $ mform -> addElement ( 'hidden' , 'new' , $ this -> plugin ) ...
Added defaults to moodle form
34,062
public function definition ( ) { global $ CFG ; $ this -> plugin = $ this -> _customdata [ 'plugin' ] ; $ this -> typeid = $ this -> _customdata [ 'typeid' ] ; $ this -> contextid = $ this -> _customdata [ 'contextid' ] ; $ this -> instance = ( isset ( $ this -> _customdata [ 'instance' ] ) && is_subclass_of ( $ this -...
Define moodle form elements
34,063
public function definition_after_data ( ) { $ mform = $ this -> _form ; $ filterstartdate = $ mform -> getElement ( 'filterstartdate' ) -> getValue ( ) ; $ filterenddate = $ mform -> getElement ( 'filterenddate' ) -> getValue ( ) ; if ( ! empty ( $ filterstartdate [ 'enabled' ] ) || ! empty ( $ filterenddate [ 'enabled...
Expand the form contents if the filter is in use .
34,064
function toHtml ( ) { $ this -> _generateId ( ) ; if ( 0 == strlen ( $ this -> _text ) ) { $ label = '' ; } elseif ( $ this -> _flagFrozen ) { $ label = $ this -> _text ; } else { $ label = '<label for="' . $ this -> getAttribute ( 'id' ) . '">' . $ this -> _text . '</label>' ; } return HTML_QuickForm_input :: toHtml (...
Returns the checkbox element in HTML
34,065
protected function explode_path ( $ path ) { $ parts = explode ( '/' , $ path , 2 ) ; if ( isset ( $ parts [ 1 ] ) && $ parts [ 1 ] !== '' ) { list ( $ bucket , $ uri ) = $ parts ; } else { $ bucket = $ parts [ 0 ] ; $ uri = '' ; } return array ( $ bucket , $ uri ) ; }
Extracts the Bucket and URI from the path
34,066
public function get_file ( $ filepath , $ file = '' ) { list ( $ bucket , $ uri ) = $ this -> explode_path ( $ filepath ) ; $ path = $ this -> prepare_file ( $ file ) ; try { $ this -> s -> getObject ( $ bucket , $ uri , $ path ) ; } catch ( S3Exception $ e ) { throw new moodle_exception ( 'errorwhilecommunicatingwith'...
Download S3 files to moodle
34,067
private function get_access_token ( ) { global $ SESSION ; if ( isset ( $ SESSION -> { self :: SESSIONKEY } ) && $ SESSION -> { self :: SESSIONKEY } ) { $ this -> client -> setAccessToken ( $ SESSION -> { self :: SESSIONKEY } ) ; return $ SESSION -> { self :: SESSIONKEY } ; } return null ; }
Gets the access token from session and sets it to client .
34,068
protected static function export_autosaves ( \ stdClass $ user , \ moodle_recordset $ autosaves ) { foreach ( $ autosaves as $ autosave ) { $ context = \ context :: instance_by_id ( $ autosave -> contextid ) ; $ subcontext = [ get_string ( 'autosaves' , 'editor_atto' ) , $ autosave -> id , ] ; $ html = writer :: with_c...
Export all autosave records in the recordset and close the recordset when finished .
34,069
protected static function get_queued_adhoc_task_record ( $ task ) { global $ DB ; $ record = self :: record_from_adhoc_task ( $ task ) ; $ params = [ $ record -> classname , $ record -> component , $ record -> customdata ] ; $ sql = 'classname = ? AND component = ? AND ' . $ DB -> sql_compare_text ( 'customdata' , \ co...
Checks if the task with the same classname component and customdata is already scheduled
34,070
public static function reschedule_or_queue_adhoc_task ( adhoc_task $ task ) : void { global $ DB ; if ( $ existingrecord = self :: get_queued_adhoc_task_record ( $ task ) ) { $ nextruntime = $ task -> get_next_run_time ( ) ; if ( $ nextruntime && ( $ existingrecord -> nextruntime != $ nextruntime ) ) { $ DB -> set_fiel...
Schedule a new task or reschedule an existing adhoc task which has matching data .
34,071
public static function queue_adhoc_task ( adhoc_task $ task , $ checkforexisting = false ) { global $ DB ; if ( $ userid = $ task -> get_userid ( ) ) { \ core_user :: require_active_user ( \ core_user :: get_user ( $ userid , '*' , MUST_EXIST ) , true , true ) ; } $ record = self :: record_from_adhoc_task ( $ task ) ; ...
Queue an adhoc task to run in the background .
34,072
public static function record_from_scheduled_task ( $ task ) { $ record = new \ stdClass ( ) ; $ record -> classname = self :: get_canonical_class_name ( $ task ) ; $ record -> component = $ task -> get_component ( ) ; $ record -> blocking = $ task -> is_blocking ( ) ; $ record -> customised = $ task -> is_customised (...
Utility method to create a DB record from a scheduled task .
34,073
public static function record_from_adhoc_task ( $ task ) { $ record = new \ stdClass ( ) ; $ record -> classname = self :: get_canonical_class_name ( $ task ) ; $ record -> id = $ task -> get_id ( ) ; $ record -> component = $ task -> get_component ( ) ; $ record -> blocking = $ task -> is_blocking ( ) ; $ record -> ne...
Utility method to create a DB record from an adhoc task .
34,074
public static function adhoc_task_from_record ( $ record ) { $ classname = self :: get_canonical_class_name ( $ record -> classname ) ; if ( ! class_exists ( $ classname ) ) { debugging ( "Failed to load task: " . $ classname , DEBUG_DEVELOPER ) ; return false ; } $ task = new $ classname ; if ( isset ( $ record -> nex...
Utility method to create an adhoc task from a DB record .
34,075
public static function scheduled_task_from_record ( $ record ) { $ classname = self :: get_canonical_class_name ( $ record -> classname ) ; if ( ! class_exists ( $ classname ) ) { debugging ( "Failed to load task: " . $ classname , DEBUG_DEVELOPER ) ; return false ; } $ task = new $ classname ; if ( isset ( $ record ->...
Utility method to create a task from a DB record .
34,076
public static function load_scheduled_tasks_for_component ( $ componentname ) { global $ DB ; $ tasks = array ( ) ; $ records = $ DB -> get_records ( 'task_scheduled' , array ( 'component' => $ componentname ) , 'classname' , '*' , IGNORE_MISSING ) ; foreach ( $ records as $ record ) { $ task = self :: scheduled_task_f...
Given a component name will load the list of tasks from the scheduled_tasks table for that component . Do not execute tasks loaded from this function - they have not been locked .
34,077
public static function get_scheduled_task ( $ classname ) { global $ DB ; $ classname = self :: get_canonical_class_name ( $ classname ) ; $ record = $ DB -> get_record ( 'task_scheduled' , array ( 'classname' => $ classname ) , '*' , IGNORE_MISSING ) ; if ( ! $ record ) { return false ; } return self :: scheduled_task...
This function load the scheduled task details for a given classname .
34,078
public static function get_adhoc_tasks ( $ classname ) { global $ DB ; $ classname = self :: get_canonical_class_name ( $ classname ) ; $ records = $ DB -> get_records ( 'task_adhoc' , array ( 'classname' => $ classname ) ) ; return array_map ( function ( $ record ) { return self :: adhoc_task_from_record ( $ record ) ...
This function load the adhoc tasks for a given classname .
34,079
public static function get_default_scheduled_task ( $ classname ) { $ task = self :: get_scheduled_task ( $ classname ) ; $ componenttasks = array ( ) ; if ( $ task ) { $ componenttasks = self :: load_default_scheduled_tasks_for_component ( $ task -> get_component ( ) ) ; } foreach ( $ componenttasks as $ componenttask...
This function load the default scheduled task details for a given classname .
34,080
public static function get_all_scheduled_tasks ( ) { global $ DB ; $ records = $ DB -> get_records ( 'task_scheduled' , null , 'component, classname' , '*' , IGNORE_MISSING ) ; $ tasks = array ( ) ; foreach ( $ records as $ record ) { $ task = self :: scheduled_task_from_record ( $ record ) ; if ( $ task ) { $ tasks [ ...
This function will return a list of all the scheduled tasks that exist in the database .
34,081
public static function adhoc_task_failed ( adhoc_task $ task ) { global $ DB ; $ delay = $ task -> get_fail_delay ( ) ; if ( empty ( $ delay ) ) { $ delay = 60 ; } else { $ delay *= 2 ; } if ( $ delay > 86400 ) { $ delay = 86400 ; } $ classname = self :: get_canonical_class_name ( $ task ) ; $ task -> set_next_run_time...
This function indicates that an adhoc task was not completed successfully and should be retried .
34,082
public static function adhoc_task_complete ( adhoc_task $ task ) { global $ DB ; logmanager :: finalise_log ( ) ; $ DB -> delete_records ( 'task_adhoc' , array ( 'id' => $ task -> get_id ( ) ) ) ; if ( $ task -> is_blocking ( ) ) { $ task -> get_cron_lock ( ) -> release ( ) ; } $ task -> get_lock ( ) -> release ( ) ; }
This function indicates that an adhoc task was completed successfully .
34,083
public static function scheduled_task_failed ( scheduled_task $ task ) { global $ DB ; $ delay = $ task -> get_fail_delay ( ) ; if ( empty ( $ delay ) ) { $ delay = 60 ; } else { $ delay *= 2 ; } if ( $ delay > 86400 ) { $ delay = 86400 ; } $ classname = self :: get_canonical_class_name ( $ task ) ; $ record = $ DB -> ...
This function indicates that a scheduled task was not completed successfully and should be retried .
34,084
public static function clear_fail_delay ( scheduled_task $ task ) { global $ DB ; $ record = new \ stdClass ( ) ; $ record -> id = $ DB -> get_field ( 'task_scheduled' , 'id' , [ 'classname' => self :: get_canonical_class_name ( $ task ) ] ) ; $ record -> nextruntime = $ task -> get_next_scheduled_time ( ) ; $ record -...
Clears the fail delay for the given task and updates its next run time based on the schedule .
34,085
public static function scheduled_task_complete ( scheduled_task $ task ) { global $ DB ; logmanager :: finalise_log ( ) ; $ classname = self :: get_canonical_class_name ( $ task ) ; $ record = $ DB -> get_record ( 'task_scheduled' , array ( 'classname' => $ classname ) ) ; if ( $ record ) { $ record -> lastruntime = ti...
This function indicates that a scheduled task was completed successfully and should be rescheduled .
34,086
protected static function get_canonical_class_name ( $ taskorstring ) { if ( is_string ( $ taskorstring ) ) { $ classname = $ taskorstring ; } else { $ classname = get_class ( $ taskorstring ) ; } if ( strpos ( $ classname , '\\' ) !== 0 ) { $ classname = '\\' . $ classname ; } return $ classname ; }
Gets class name for use in database table . Always begins with a \ .
34,087
public static function fetch_all_helper ( $ table , $ classname , $ params ) { global $ DB ; $ instance = new $ classname ( ) ; $ classvars = ( array ) $ instance ; $ params = ( array ) $ params ; $ wheresql = array ( ) ; $ newparams = array ( ) ; $ columns = $ DB -> get_columns ( $ table ) ; foreach ( $ params as $ va...
Factory method which uses the parameters to retrieve all matching instances from the database
34,088
public static function fetch_and_start_tour ( $ tourid , $ context , $ pageurl ) { global $ PAGE ; $ params = self :: validate_parameters ( self :: fetch_and_start_tour_parameters ( ) , [ 'tourid' => $ tourid , 'context' => $ context , 'pageurl' => $ pageurl , ] ) ; $ context = \ context_helper :: instance_by_id ( $ pa...
Fetch the tour configuration for the specified tour .
34,089
public static function reset_tour ( $ tourid , $ context , $ pageurl ) { $ params = self :: validate_parameters ( self :: reset_tour_parameters ( ) , [ 'tourid' => $ tourid , 'context' => $ context , 'pageurl' => $ pageurl , ] ) ; $ context = \ context_helper :: instance_by_id ( $ params [ 'context' ] ) ; self :: valid...
Reset the specified tour for the current user .
34,090
public static function complete_tour ( $ tourid , $ context , $ pageurl , $ stepid , $ stepindex ) { $ params = self :: validate_parameters ( self :: complete_tour_parameters ( ) , [ 'tourid' => $ tourid , 'context' => $ context , 'pageurl' => $ pageurl , 'stepid' => $ stepid , 'stepindex' => $ stepindex , ] ) ; $ cont...
Mark the specified tour as completed for the current user .
34,091
public static function complete_tour_parameters ( ) { return new external_function_parameters ( [ 'tourid' => new external_value ( PARAM_INT , 'Tour ID' ) , 'context' => new external_value ( PARAM_INT , 'Context ID' ) , 'pageurl' => new external_value ( PARAM_LOCALURL , 'Page URL' ) , 'stepid' => new external_value ( P...
The parameters for complete_tour .
34,092
public static function step_shown ( $ tourid , $ context , $ pageurl , $ stepid , $ stepindex ) { $ params = self :: validate_parameters ( self :: step_shown_parameters ( ) , [ 'tourid' => $ tourid , 'context' => $ context , 'pageurl' => $ pageurl , 'stepid' => $ stepid , 'stepindex' => $ stepindex , ] ) ; $ context = ...
Mark the specified toru step as shown for the current user .
34,093
public static function step_shown_parameters ( ) { return new external_function_parameters ( [ 'tourid' => new external_value ( PARAM_INT , 'Tour ID' ) , 'context' => new external_value ( PARAM_INT , 'Context ID' ) , 'pageurl' => new external_value ( PARAM_URL , 'Page URL' ) , 'stepid' => new external_value ( PARAM_INT...
The parameters for step_shown .
34,094
public static function step_structure_returns ( ) { return new external_single_structure ( [ 'title' => new external_value ( PARAM_RAW , 'Step Title' ) , 'content' => new external_value ( PARAM_RAW , 'Step Content' ) , 'element' => new external_value ( PARAM_TEXT , 'Step Target' ) , 'placement' => new external_value ( ...
The standard return structure for a step .
34,095
public function definition ( ) { $ mform = $ this -> _form ; $ contexts = $ this -> _customdata [ 'contexts' ] ; $ usablecontexts = $ contexts -> having_cap ( 'moodle/question:useall' ) ; $ mform -> addElement ( 'header' , 'generalheader' , get_string ( "general" , 'form' ) ) ; $ mform -> addElement ( 'questioncategory...
Form definiton .
34,096
protected static function get_registration ( $ confirmed = true ) { global $ DB ; if ( self :: $ registration === null ) { self :: $ registration = $ DB -> get_record ( 'registration_hubs' , [ 'huburl' => HUB_MOODLEORGHUBURL ] ) ; } if ( self :: $ registration && ( bool ) self :: $ registration -> confirmed == ( bool )...
Get site registration
34,097
public static function require_registration ( ) { if ( $ registration = self :: get_registration ( ) ) { return $ registration ; } if ( has_capability ( 'moodle/site:config' , context_system :: instance ( ) ) ) { throw new moodle_exception ( 'registrationwarning' , 'admin' , new moodle_url ( '/admin/registration/index....
Same as get_registration except it throws exception if site not registered
34,098
public static function get_token ( $ strictness = IGNORE_MISSING ) { if ( $ strictness == MUST_EXIST ) { $ registration = self :: require_registration ( ) ; } else if ( ! $ registration = self :: get_registration ( ) ) { return null ; } return $ registration -> token ; }
Returns registration token
34,099
public static function get_site_info ( $ defaults = [ ] ) { global $ CFG , $ DB ; require_once ( $ CFG -> libdir . '/badgeslib.php' ) ; require_once ( $ CFG -> dirroot . "/course/lib.php" ) ; $ siteinfo = array ( ) ; $ cleanhuburl = clean_param ( HUB_MOODLEORGHUBURL , PARAM_ALPHANUMEXT ) ; foreach ( self :: FORM_FIELDS...
Calculates and prepares site information to send to moodle . net as part of registration or update