idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
33,400
static function table ( $ newtable = false ) { static $ _table ; if ( ! empty ( $ newtable ) ) $ _table = $ newtable ; if ( empty ( $ _table ) ) $ _table = 'adodb_logsql' ; return $ _table ; }
Sets the tablename to be used
33,401
function _CPULoad ( ) { if ( strncmp ( PHP_OS , 'WIN' , 3 ) == 0 ) { if ( PHP_VERSION == '5.0.0' ) return false ; if ( PHP_VERSION == '5.0.1' ) return false ; if ( PHP_VERSION == '5.0.2' ) return false ; if ( PHP_VERSION == '5.0.3' ) return false ; if ( PHP_VERSION == '4.3.10' ) return false ; static $ FAIL = false ; i...
returns array with info to calculate CPU Load
33,402
protected static function delete_all_user_data ( context_user $ usercontext ) { global $ DB ; $ userid = $ usercontext -> instanceid ; $ recordset = $ DB -> get_recordset_select ( 'post' , 'userid = :userid AND module IN (:blog, :blogext)' , [ 'userid' => $ userid , 'blog' => 'blog' , 'blogext' => 'blog_external' ] ) ;...
Helper method to delete all user data .
33,403
public static function get_instance_info ( $ instanceid ) { global $ DB ; $ params = self :: validate_parameters ( self :: get_instance_info_parameters ( ) , array ( 'instanceid' => $ instanceid ) ) ; $ warnings = array ( ) ; $ enrolplugin = enrol_get_plugin ( 'guest' ) ; if ( empty ( $ enrolplugin ) ) { throw new mood...
Return guest enrolment instance information .
33,404
public function is_connection_ready ( ) { if ( ! @ $ this -> connection -> set ( "ping" , 'ping' , 1 ) ) { return false ; } if ( $ this -> isshared ) { $ safecombination = false ; $ extension = new ReflectionExtension ( 'memcached' ) ; if ( ( version_compare ( $ extension -> getVersion ( ) , '3.0.1' ) >= 0 ) ) { $ safe...
Confirm whether the connection is ready and usable .
33,405
protected function delete_many_connection ( Memcached $ connection , array $ keys ) { $ count = 0 ; if ( $ this -> candeletemulti ) { $ result = $ connection -> deleteMulti ( $ keys ) ; foreach ( $ result as $ key => $ outcome ) { if ( $ outcome === true ) { $ count ++ ; } } return $ count ; } foreach ( $ keys as $ key...
Deletes several keys from the cache in a single action for a specific connection .
33,406
protected static function get_prefixed_keys ( Memcached $ connection , $ prefix ) { $ connkeys = $ connection -> getAllKeys ( ) ; if ( empty ( $ connkeys ) ) { return array ( ) ; } $ keys = array ( ) ; $ start = strlen ( $ prefix ) ; foreach ( $ connkeys as $ key ) { if ( strpos ( $ key , $ prefix ) === 0 ) { $ keys [ ...
Returns all of the keys in the given connection that belong to this cache store instance .
33,407
public static function config_get_hash_options ( ) { $ options = array ( Memcached :: HASH_DEFAULT => get_string ( 'hash_default' , 'cachestore_memcached' ) , Memcached :: HASH_MD5 => get_string ( 'hash_md5' , 'cachestore_memcached' ) , Memcached :: HASH_CRC => get_string ( 'hash_crc' , 'cachestore_memcached' ) , Memca...
Gets an array of hash options available during configuration .
33,408
public function get_warnings ( ) { global $ CFG ; $ warnings = array ( ) ; if ( isset ( $ CFG -> session_memcached_save_path ) && count ( $ this -> servers ) ) { $ bits = explode ( ':' , $ CFG -> session_memcached_save_path , 3 ) ; $ host = array_shift ( $ bits ) ; $ port = ( count ( $ bits ) ) ? array_shift ( $ bits )...
Used to notify of configuration conflicts .
33,409
public function resetopt ( ) { $ this -> options = array ( ) ; $ this -> options [ 'CURLOPT_USERAGENT' ] = 'MoodleBot/1.0' ; $ this -> options [ 'CURLOPT_HEADER' ] = 0 ; $ this -> options [ 'CURLOPT_NOBODY' ] = 0 ; $ this -> options [ 'CURLOPT_FOLLOWLOCATION' ] = 1 ; $ this -> options [ 'CURLOPT_MAXREDIRS' ] = 10 ; $ t...
Resets the CURL options that have already been set
33,410
public static function get_cacert ( ) { global $ CFG ; if ( is_readable ( "$CFG->dataroot/moodleorgca.crt" ) ) { return realpath ( "$CFG->dataroot/moodleorgca.crt" ) ; } $ cacert = ini_get ( 'curl.cainfo' ) ; if ( ! empty ( $ cacert ) and is_readable ( $ cacert ) ) { return realpath ( $ cacert ) ; } if ( $ CFG -> ostyp...
Get the location of ca certificates .
33,411
public function setHeader ( $ header ) { if ( is_array ( $ header ) ) { foreach ( $ header as $ v ) { $ this -> setHeader ( $ v ) ; } } else { $ newvalue = preg_replace ( '/[\r\n]/' , '' , $ header ) ; if ( ! in_array ( $ newvalue , $ this -> header ) ) { $ this -> header [ ] = $ newvalue ; } } }
Set HTTP Request Header
33,412
public function set_security ( $ securityobject ) { if ( $ securityobject instanceof \ core \ files \ curl_security_helper ) { $ this -> securityhelper = $ securityobject ; return true ; } return false ; }
Sets the curl security helper .
33,413
protected function multi ( $ requests , $ options = array ( ) ) { $ count = count ( $ requests ) ; $ handles = array ( ) ; $ results = array ( ) ; $ main = curl_multi_init ( ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( ! empty ( $ requests [ $ i ] [ 'filepath' ] ) and empty ( $ requests [ $ i ] [ 'file' ] ) ) { ...
Multi HTTP Requests This function could run multi - requests in parallel .
33,414
protected function reset_request_state_vars ( ) { $ this -> info = array ( ) ; $ this -> error = '' ; $ this -> errno = 0 ; $ this -> response = array ( ) ; $ this -> rawresponse = array ( ) ; $ this -> responsefinished = false ; }
Helper function to reset the request state vars .
33,415
public function download_one ( $ url , $ params , $ options = array ( ) ) { $ options [ 'CURLOPT_HTTPGET' ] = 1 ; if ( ! empty ( $ params ) ) { $ url .= ( stripos ( $ url , '?' ) !== false ) ? '&' : '?' ; $ url .= http_build_query ( $ params , '' , '&' ) ; } if ( ! empty ( $ options [ 'filepath' ] ) && empty ( $ option...
Downloads one file and writes it to the specified file handler
33,416
public function cleanup ( $ expire ) { if ( $ dir = opendir ( $ this -> dir ) ) { while ( false !== ( $ file = readdir ( $ dir ) ) ) { if ( ! is_dir ( $ file ) && $ file != '.' && $ file != '..' ) { $ lasttime = @ filemtime ( $ this -> dir . $ file ) ; if ( time ( ) - $ lasttime > $ expire ) { @ unlink ( $ this -> dir ...
Remove cache files
33,417
public function shouldFormatNumericValueAsDate ( $ styleId ) { $ stylesAttributes = $ this -> getStylesAttributes ( ) ; if ( $ styleId === self :: DEFAULT_STYLE_ID || ! isset ( $ stylesAttributes [ $ styleId ] ) ) { return false ; } $ styleAttributes = $ stylesAttributes [ $ styleId ] ; return $ this -> doesStyleIndica...
Returns whether the style with the given ID should consider numeric values as timestamps and format the cell as a date .
33,418
protected function extractRelevantInfo ( ) { $ this -> customNumberFormats = [ ] ; $ this -> stylesAttributes = [ ] ; $ xmlReader = new XMLReader ( ) ; if ( $ xmlReader -> openFileInZip ( $ this -> filePath , self :: STYLES_XML_FILE_PATH ) ) { while ( $ xmlReader -> read ( ) ) { if ( $ xmlReader -> isPositionedOnStarti...
Reads the styles . xml file and extract the relevant information from the file .
33,419
protected function extractNumberFormats ( $ xmlReader ) { while ( $ xmlReader -> read ( ) ) { if ( $ xmlReader -> isPositionedOnStartingNode ( self :: XML_NODE_NUM_FMT ) ) { $ numFmtId = intval ( $ xmlReader -> getAttribute ( self :: XML_ATTRIBUTE_NUM_FMT_ID ) ) ; $ formatCode = $ xmlReader -> getAttribute ( self :: XM...
Extracts number formats from the numFmt nodes . For simplicity the styles attributes are kept in memory . This is possible thanks to the reuse of formats . So 1 million cells should not use 1 million formats .
33,420
protected function extractStyleAttributes ( $ xmlReader ) { while ( $ xmlReader -> read ( ) ) { if ( $ xmlReader -> isPositionedOnStartingNode ( self :: XML_NODE_XF ) ) { $ numFmtId = $ xmlReader -> getAttribute ( self :: XML_ATTRIBUTE_NUM_FMT_ID ) ; $ normalizedNumFmtId = ( $ numFmtId !== null ) ? intval ( $ numFmtId ...
Extracts style attributes from the xf nodes inside the cellXfs section . For simplicity the styles attributes are kept in memory . This is possible thanks to the reuse of styles . So 1 million cells should not use 1 million styles .
33,421
protected function doesNumFmtIdIndicateDate ( $ numFmtId ) { if ( ! isset ( $ this -> numFmtIdToIsDateFormatCache [ $ numFmtId ] ) ) { $ formatCode = $ this -> getFormatCodeForNumFmtId ( $ numFmtId ) ; $ this -> numFmtIdToIsDateFormatCache [ $ numFmtId ] = ( $ this -> isNumFmtIdBuiltInDateFormat ( $ numFmtId ) || $ thi...
Returns whether the number format ID indicates that the number is a date . The result is cached to avoid recomputing the same thing over and over as numFmtId attributes can be shared between multiple styles .
33,422
public function col_random_response ( $ row ) { if ( $ this -> is_downloading ( ) ) { return $ row -> random_response ; } else { return html_writer :: link ( $ this -> get_link_single_entry ( $ row ) , get_string ( 'response_nr' , 'feedback' ) . ': ' . $ row -> random_response ) ; } }
Prepares column reponse for display
33,423
public function process_logstore_database_log ( $ data ) { if ( ! self :: $ extdb || ! self :: $ extdbtablename ) { return ; } $ data = $ this -> process_log ( $ data , get_config ( 'logstore_database' , 'jsonformat' ) ) ; if ( $ data ) { self :: $ extdb -> insert_record ( self :: $ extdbtablename , $ data ) ; } }
Process logstore_database_log entries .
33,424
public function is_used_in_context ( $ typeid , $ courseid ) { global $ DB ; $ ok = $ DB -> record_exists ( 'lti' , array ( 'course' => $ courseid , 'typeid' => $ typeid ) ) ; return $ ok || $ DB -> record_exists ( 'lti_types' , array ( 'course' => $ courseid , 'id' => $ typeid ) ) ; }
Default implementation will check for the existence of at least one mod_lti entry for that tool and context .
33,425
public function is_allowed_in_context ( $ typeid , $ courseid ) { global $ DB ; $ type = $ DB -> get_record ( 'lti_types' , array ( 'id' => $ typeid ) ) ; return $ type && ( $ type -> course == $ courseid || $ type -> course == SITEID ) ; }
Checks if there is a site tool or a course tool for this site .
33,426
public function parse_value ( $ value ) { if ( empty ( $ this -> resources ) ) { $ this -> resources = $ this -> get_resources ( ) ; } if ( ! empty ( $ this -> resources ) ) { foreach ( $ this -> resources as $ resource ) { $ value = $ resource -> parse_value ( $ value ) ; } } return $ value ; }
Parse a string for custom substitution parameter variables supported by this service s resources .
33,427
private function check_signature ( $ consumerkey , $ secret , $ body ) { $ ok = true ; try { lti \ handle_oauth_body_post ( $ consumerkey , $ secret , $ body ) ; } catch ( \ Exception $ e ) { debugging ( $ e -> getMessage ( ) . "\n" ) ; $ ok = false ; } return $ ok ; }
Check the request signature .
33,428
public function parseAddressList ( $ address , array $ params = array ( ) ) { if ( $ address instanceof Horde_Mail_Rfc822_List ) { return $ address ; } if ( empty ( $ params [ 'limit' ] ) ) { $ params [ 'limit' ] = - 1 ; } $ this -> _params = array_merge ( array ( 'default_domain' => null , 'validate' => false ) , $ pa...
Starts the whole process .
33,429
protected function _rfc822IsAtext ( $ chr , $ validate = null ) { if ( ! $ this -> _params [ 'validate' ] && ! is_null ( $ validate ) ) { return strcspn ( $ chr , $ validate ) ; } $ ord = ord ( $ chr ) ; if ( $ ord > 127 ) { return ( $ this -> _params [ 'validate' ] === 'eai' ) ; } if ( $ ord <= 32 ) { return false ; }...
Check if data is an atom .
33,430
protected function _curr ( $ advance = false ) { return ( $ this -> _ptr >= $ this -> _datalen ) ? false : $ this -> _data [ $ advance ? $ this -> _ptr ++ : $ this -> _ptr ] ; }
Return current character .
33,431
public function toHtml ( ) { global $ PAGE ; $ html = parent :: toHTML ( ) ; if ( ! $ this -> isFrozen ( ) ) { $ context = context_system :: instance ( ) ; $ params = [ $ context -> id ] ; $ PAGE -> requires -> js_call_amd ( 'tool_lp/form_competency_element' , 'init' , $ params ) ; $ html .= '<div class="form-group row...
Generate the hidden field and the controls to show and pick the competencies .
33,432
public function get_quiz ( ) { global $ DB ; if ( empty ( $ this -> quiz ) ) { if ( empty ( $ this -> record -> quizid ) ) { throw new \ coding_exception ( 'quizid is not set.' ) ; } $ this -> quiz = $ DB -> get_record ( 'quiz' , array ( 'id' => $ this -> record -> quizid ) ) ; } return $ this -> quiz ; }
Returns the quiz for this question slot . The quiz is fetched the first time it is requested and then stored in a member variable to be returned each subsequent time .
33,433
public function set_quiz ( $ quiz ) { $ this -> quiz = $ quiz ; $ this -> record -> quizid = $ quiz -> id ; }
Sets the quiz object for the quiz slot . It is not mandatory to set the quiz as the quiz slot can fetch it the first time it is accessed however it helps with the performance to set the quiz if you already have it .
33,434
public function set_tags ( $ tags ) { $ this -> tags = [ ] ; foreach ( $ tags as $ tag ) { $ this -> tags [ $ tag -> id ] = $ tag ; } }
Set some tags for this quiz slot .
33,435
public function execute ( ) { global $ CFG ; require_once ( $ CFG -> dirroot . '/course/lib.php' ) ; $ pluginstorefresh = null ; if ( isset ( $ this -> get_custom_data ( ) -> plugins ) ) { $ pluginstorefresh = $ this -> get_custom_data ( ) -> plugins ; } if ( isset ( $ this -> get_custom_data ( ) -> courseid ) ) { $ co...
Run the task to refresh calendar events .
33,436
public function delete_share_dataowner_sysaccount ( $ shareid ) { $ shareid = ( int ) $ shareid ; $ deleteshareparams = [ 'share_id' => $ shareid ] ; $ deleteshareresponse = $ this -> ocsclient -> call ( 'delete_share' , $ deleteshareparams ) ; $ xml = simplexml_load_string ( $ deleteshareresponse ) ; if ( empty ( $ xm...
Deletes the share of the systemaccount and a user . In case the share could not be deleted a notification is displayed .
33,437
public function transfer_file_to_path ( $ srcpath , $ dstpath , $ operation , $ webdavclient = null ) { $ this -> systemwebdavclient -> open ( ) ; $ webdavendpoint = issuer_management :: parse_endpoint_url ( 'webdav' , $ this -> issuer ) ; $ srcpath = ltrim ( $ srcpath , '/' ) ; $ sourcepath = $ webdavendpoint [ 'path'...
Copy or moves a file to a new path .
33,438
public function create_folder_path_access_controlled_links ( $ context , $ component , $ filearea , $ itemid ) { global $ CFG , $ SITE ; $ contextlist = array_reverse ( $ context -> get_parent_contexts ( true ) ) ; $ fullpath = '' ; $ allfolders = [ ] ; foreach ( $ contextlist as $ ctx ) { $ prevlang = force_current_la...
Creates a unique folder path for the access controlled link .
33,439
public function create_system_dav ( ) { $ webdavendpoint = issuer_management :: parse_endpoint_url ( 'webdav' , $ this -> issuer ) ; $ server = $ webdavendpoint [ 'host' ] ; if ( $ webdavendpoint [ 'scheme' ] === 'https' ) { $ webdavtype = 'ssl://' ; $ webdavport = 443 ; } else if ( $ webdavendpoint [ 'scheme' ] === 'h...
Creates a new webdav_client for the system account .
33,440
public function create_storage_folder ( $ controlledlinkfoldername , $ webdavclient ) { $ parsedwebdavurl = issuer_management :: parse_endpoint_url ( 'webdav' , $ this -> issuer ) ; $ webdavprefix = $ parsedwebdavurl [ 'path' ] ; $ webdavclient -> open ( ) ; $ isdir = $ webdavclient -> is_dir ( $ webdavprefix . $ contr...
Creates a folder to store access controlled links .
33,441
public function find_share_in_sysaccount ( $ path ) { $ systemaccount = \ core \ oauth2 \ api :: get_system_account ( $ this -> issuer ) ; $ systemaccountuser = $ systemaccount -> get ( 'username' ) ; $ ocsparams = [ 'path' => $ path , 'reshares' => true ] ; $ getsharesresponse = $ this -> ocsclient -> call ( 'get_shar...
Find a file that has previously been shared with the system account .
33,442
public function download_for_offline_usage ( string $ srcpath , string $ targetpath ) : void { $ this -> systemwebdavclient -> open ( ) ; $ webdavendpoint = issuer_management :: parse_endpoint_url ( 'webdav' , $ this -> issuer ) ; $ srcpath = ltrim ( $ srcpath , '/' ) ; $ sourcepath = $ webdavendpoint [ 'path' ] . $ sr...
Download a file from the system account for the purpose of offline usage .
33,443
public static function check_can_list_insights ( \ context $ context , bool $ return = false ) { global $ USER ; if ( $ context -> contextlevel === CONTEXT_USER && $ context -> instanceid == $ USER -> id ) { $ capability = 'moodle/analytics:listowninsights' ; } else { $ capability = 'moodle/analytics:listinsights' ; } ...
Checks that the user can list that context insights
33,444
public static function get_all_models ( $ enabled = false , $ trained = false , $ predictioncontext = false ) { global $ DB ; $ params = array ( ) ; $ sql = "SELECT am.* FROM {analytics_models} am" ; if ( $ enabled || $ trained || $ predictioncontext ) { $ conditions = [ ] ; if ( $ enabled ) { $ conditions [ ] = 'am.en...
Returns all system models that match the provided filters .
33,445
public static function get_predictions_processor ( $ predictionclass = false , $ checkisready = true ) { $ checkisready = intval ( $ checkisready ) ; if ( ! $ predictionclass ) { $ predictionclass = get_config ( 'analytics' , 'predictionsprocessor' ) ; } if ( empty ( $ predictionclass ) ) { $ predictionclass = self :: ...
Returns the provided predictions processor class .
33,446
public static function get_all_prediction_processors ( ) { $ mlbackends = \ core_component :: get_plugin_list ( 'mlbackend' ) ; $ predictionprocessors = array ( ) ; foreach ( $ mlbackends as $ mlbackend => $ unused ) { $ classfullpath = '\mlbackend_' . $ mlbackend . '\processor' ; $ predictionprocessors [ $ classfullpa...
Return all system predictions processors .
33,447
public static function get_predictions_processor_name ( \ core_analytics \ predictor $ predictionsprocessor ) { $ component = substr ( get_class ( $ predictionsprocessor ) , 0 , strpos ( get_class ( $ predictionsprocessor ) , '\\' , 1 ) ) ; return get_string ( 'pluginname' , $ component ) ; }
Returns the name of the provided predictions processor .
33,448
public static function is_mlbackend_used ( $ plugin ) { $ models = self :: get_all_models ( ) ; foreach ( $ models as $ model ) { $ processor = $ model -> get_predictions_processor ( ) ; $ noprefixnamespace = ltrim ( get_class ( $ processor ) , '\\' ) ; $ processorplugin = substr ( $ noprefixnamespace , 0 , strpos ( $ ...
Whether the provided plugin is used by any model .
33,449
public static function get_all_time_splittings ( ) { if ( self :: $ alltimesplittings !== null ) { return self :: $ alltimesplittings ; } $ classes = self :: get_analytics_classes ( 'time_splitting' ) ; self :: $ alltimesplittings = [ ] ; foreach ( $ classes as $ fullclassname => $ classpath ) { $ instance = self :: ge...
Get all available time splitting methods .
33,450
public static function get_time_splitting_methods_for_evaluation ( bool $ all = false ) { if ( $ all === false ) { if ( $ enabledtimesplittings = get_config ( 'analytics' , 'defaulttimesplittingsevaluation' ) ) { $ enabledtimesplittings = array_flip ( explode ( ',' , $ enabledtimesplittings ) ) ; } } $ timesplittings =...
Returns the time - splitting methods for model evaluation .
33,451
public static function get_all_targets ( ) : array { if ( self :: $ alltargets !== null ) { return self :: $ alltargets ; } $ classes = self :: get_analytics_classes ( 'target' ) ; self :: $ alltargets = [ ] ; foreach ( $ classes as $ fullclassname => $ classpath ) { $ instance = self :: get_target ( $ fullclassname ) ...
Return all targets in the system .
33,452
public static function get_all_indicators ( ) { if ( self :: $ allindicators !== null ) { return self :: $ allindicators ; } $ classes = self :: get_analytics_classes ( 'indicator' ) ; self :: $ allindicators = [ ] ; foreach ( $ classes as $ fullclassname => $ classpath ) { $ instance = self :: get_indicator ( $ fullcl...
Return all system indicators .
33,453
public static function is_valid ( $ fullclassname , $ baseclass ) { if ( is_subclass_of ( $ fullclassname , $ baseclass ) ) { if ( ( new \ ReflectionClass ( $ fullclassname ) ) -> isInstantiable ( ) ) { return true ; } } return false ; }
Returns whether a time splitting method is valid or not .
33,454
public static function get_analytics_logstore ( ) { $ readers = get_log_manager ( ) -> get_readers ( 'core\log\sql_reader' ) ; $ analyticsstore = get_config ( 'analytics' , 'logstore' ) ; if ( ! empty ( $ analyticsstore ) && ! empty ( $ readers [ $ analyticsstore ] ) ) { $ logstore = $ readers [ $ analyticsstore ] ; } ...
Returns the logstore used for analytics .
33,455
public static function get_indicator_calculations ( $ analysable , $ starttime , $ endtime , $ samplesorigin ) { global $ DB ; $ params = array ( 'starttime' => $ starttime , 'endtime' => $ endtime , 'contextid' => $ analysable -> get_context ( ) -> id , 'sampleorigin' => $ samplesorigin ) ; $ calculations = $ DB -> ge...
Returns this analysable calculations during the provided period .
33,456
public static function get_models_with_insights ( \ context $ context ) { self :: check_can_list_insights ( $ context ) ; $ models = self :: get_all_models ( true , true , $ context ) ; foreach ( $ models as $ key => $ model ) { if ( ! $ model -> uses_insights ( ) ) { unset ( $ models [ $ key ] ) ; } } return $ models ...
Returns the models with insights at the provided context .
33,457
public static function get_prediction ( $ predictionid , $ requirelogin = false ) { global $ DB ; if ( ! $ predictionobj = $ DB -> get_record ( 'analytics_predictions' , array ( 'id' => $ predictionid ) ) ) { throw new \ moodle_exception ( 'errorpredictionnotfound' , 'analytics' ) ; } $ context = \ context :: instance_...
Returns a prediction
33,458
public static function cleanup ( ) { global $ DB ; $ sql = "SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap LEFT JOIN {context} ctx ON ap.contextid = ctx.id WHERE ctx.id IS NULL" ; $ apcontexts = $ DB -> get_records_sql ( $ sql ) ; $ sql = "SELECT DISTINCT aic.contextid FRO...
Cleans up analytics db tables that do not directly depend on analysables that may have been deleted .
33,459
private static function get_analytics_classes ( $ element ) { $ element = clean_param ( $ element , PARAM_ALPHANUMEXT ) ; $ classes = \ core_component :: get_component_classes_in_namespace ( null , 'analytics\\' . $ element ) ; return $ classes ; }
Returns the provided element classes in the site .
33,460
public static function update_default_models_for_component ( string $ componentname ) : array { $ result = [ ] ; foreach ( static :: load_default_models_for_component ( $ componentname ) as $ definition ) { if ( ! \ core_analytics \ model :: exists ( static :: get_target ( $ definition [ 'target' ] ) ) ) { $ result [ ]...
Check that all the models declared by the component are up to date .
33,461
public static function load_default_models_for_component ( string $ componentname ) : array { $ dir = \ core_component :: get_component_directory ( $ componentname ) ; if ( ! $ dir ) { return [ ] ; } $ file = $ dir . '/' . self :: ANALYTICS_FILENAME ; if ( ! is_readable ( $ file ) ) { return [ ] ; } $ models = null ; i...
Return the list of models declared by the given component .
33,462
public static function load_default_models_for_all_components ( ) : array { $ tmp = [ ] ; foreach ( \ core_component :: get_component_list ( ) as $ type => $ components ) { foreach ( array_keys ( $ components ) as $ component ) { if ( $ loaded = static :: load_default_models_for_component ( $ component ) ) { $ tmp [ $ ...
Return the list of all the models declared anywhere in this Moodle installation .
33,463
public static function validate_models_declaration ( array $ models ) { foreach ( $ models as $ model ) { if ( ! isset ( $ model [ 'target' ] ) ) { throw new \ coding_exception ( 'Missing target declaration' ) ; } if ( ! static :: is_valid ( $ model [ 'target' ] , '\core_analytics\local\target\base' ) ) { throw new \ c...
Validate the declaration of prediction models according the syntax expected in the component s db folder .
33,464
public static function create_declared_model ( array $ definition ) : \ core_analytics \ model { list ( $ target , $ indicators ) = static :: get_declared_target_and_indicators_instances ( $ definition ) ; if ( isset ( $ definition [ 'timesplitting' ] ) ) { $ timesplitting = $ definition [ 'timesplitting' ] ; } else { ...
Create the defined model .
33,465
public static function get_declared_target_and_indicators_instances ( array $ definition ) : array { $ target = static :: get_target ( $ definition [ 'target' ] ) ; $ indicators = [ ] ; foreach ( $ definition [ 'indicators' ] as $ indicatorname ) { $ indicator = static :: get_indicator ( $ indicatorname ) ; $ indicator...
Given a model definition return actual target and indicators instances .
33,466
public function is_available ( ) { global $ CFG ; $ preventfilelocking = ! empty ( $ CFG -> preventfilelocking ) ; $ lockdirisdataroot = true ; if ( ! empty ( $ CFG -> file_lock_root ) && strpos ( $ CFG -> file_lock_root , $ CFG -> dataroot ) !== 0 ) { $ lockdirisdataroot = false ; } return ! $ preventfilelocking || ! ...
Is available .
33,467
public function get_lock ( $ resource , $ timeout , $ maxlifetime = 86400 ) { $ giveuptime = time ( ) + $ timeout ; $ hash = md5 ( $ this -> type . '_' . $ resource ) ; $ lockdir = $ this -> lockdirectory . '/' . substr ( $ hash , 0 , 2 ) ; if ( ! check_dir_exists ( $ lockdir , true , true ) ) { return false ; } $ lock...
Get a lock within the specified timeout or return false .
33,468
public function make_ui ( $ type , $ label , array $ attributes = null , array $ options = null ) { $ this -> uisetting = backup_setting_ui :: make ( $ this , $ type , $ label , $ attributes , $ options ) ; if ( is_array ( $ options ) || is_object ( $ options ) ) { $ options = ( array ) $ options ; switch ( get_class (...
Creates and sets a user interface for this setting given appropriate arguments
33,469
public function display ( core_backup_renderer $ renderer ) { $ form = $ this -> initialise_stage_form ( ) ; $ form -> require_definition_after_data ( ) ; if ( $ e = $ form -> get_element ( 'submitbutton' ) ) { $ e -> setLabel ( get_string ( 'import' . $ this -> get_ui ( ) -> get_name ( ) . 'stage' . $ this -> get_stag...
Displays the stage
33,470
public static function is_valid_number ( string $ x ) : bool { $ ap = new qtype_numerical_answer_processor ( array ( ) ) ; list ( $ value , $ unit ) = $ ap -> apply_units ( $ x ) ; return ! is_null ( $ value ) && ! $ unit ; }
Validate that a string is a number formatted correctly for the current locale .
33,471
public function add_unit ( $ questiondata , $ answer , $ unit = null ) { if ( is_null ( $ unit ) ) { $ unit = $ this -> get_default_numerical_unit ( $ questiondata ) ; } if ( ! $ unit ) { return $ answer ; } if ( ! empty ( $ questiondata -> options -> unitsleft ) ) { return $ unit -> unit . ' ' . $ answer ; } else { re...
Add a unit to a response for display .
33,472
public function set_characters ( $ decsep , $ thousandssep ) { $ this -> decsep = $ decsep ; $ this -> thousandssep = $ thousandssep ; $ this -> regex = null ; }
Set the decimal point and thousands separator character that should be used .
33,473
protected function parse_response ( $ response ) { if ( ! preg_match ( $ this -> build_regex ( ) , $ response , $ matches ) ) { return array ( null , null , null , null ) ; } $ matches += array ( '' , '' , '' , '' ) ; list ( $ matchedpart , $ beforepoint , $ decimals , $ exponent ) = $ matches ; $ beforepoint = str_rep...
This method can be used for more locale - strict parsing of repsonses . At the moment we don t use it and instead use the more lax parsing in apply_units . This is just a note that this funciton was used in the past so if you are intersted look through version control history .
33,474
public static function get_instance_for_cache ( \ cache_definition $ definition ) { if ( is_null ( self :: $ instance ) ) { self :: $ instance = new time_last_message_between_users ( ) ; } return self :: $ instance ; }
Returns an instance of the data source class that the cache can use for loading data using the other methods specified by the cache_data_source interface .
33,475
public function load_for_cache ( $ key ) { $ message = api :: get_most_recent_conversation_message ( $ key ) ; if ( $ message ) { return $ message -> timecreated ; } else { return null ; } }
Loads the data for the key provided ready formatted for caching .
33,476
public function load_many_for_cache ( array $ keys ) { $ results = [ ] ; foreach ( $ keys as $ key ) { $ results [ ] = $ this -> load_for_cache ( $ key ) ; } return $ results ; }
Loads several keys for the cache .
33,477
protected static function reset_caches ( ) { self :: $ cache_contextsbyid = array ( ) ; self :: $ cache_contexts = array ( ) ; self :: $ cache_count = 0 ; self :: $ cache_preloaded = array ( ) ; self :: $ systemcontext = null ; }
Resets the cache to remove all data .
33,478
protected static function cache_add ( context $ context ) { if ( isset ( self :: $ cache_contextsbyid [ $ context -> id ] ) ) { return ; } if ( self :: $ cache_count >= CONTEXT_CACHE_MAX_SIZE ) { $ i = 0 ; foreach ( self :: $ cache_contextsbyid as $ ctx ) { $ i ++ ; if ( $ i <= 100 ) { continue ; } if ( $ i > ( CONTEXT...
Adds a context to the cache . If the cache is full discards a batch of older entries .
33,479
protected static function cache_remove ( context $ context ) { if ( ! isset ( self :: $ cache_contextsbyid [ $ context -> id ] ) ) { return ; } unset ( self :: $ cache_contexts [ $ context -> contextlevel ] [ $ context -> instanceid ] ) ; unset ( self :: $ cache_contextsbyid [ $ context -> id ] ) ; self :: $ cache_coun...
Removes a context from the cache .
33,480
protected static function cache_get ( $ contextlevel , $ instance ) { if ( isset ( self :: $ cache_contexts [ $ contextlevel ] [ $ instance ] ) ) { return self :: $ cache_contexts [ $ contextlevel ] [ $ instance ] ; } return false ; }
Gets a context from the cache .
33,481
protected static function cache_get_by_id ( $ id ) { if ( isset ( self :: $ cache_contextsbyid [ $ id ] ) ) { return self :: $ cache_contextsbyid [ $ id ] ; } return false ; }
Gets a context from the cache based on its id .
33,482
protected static function preload_from_record ( stdClass $ rec ) { $ notenoughdata = false ; $ notenoughdata = $ notenoughdata || empty ( $ rec -> ctxid ) ; $ notenoughdata = $ notenoughdata || empty ( $ rec -> ctxlevel ) ; $ notenoughdata = $ notenoughdata || ! isset ( $ rec -> ctxinstance ) ; $ notenoughdata = $ note...
Preloads context information from db record and strips the cached info .
33,483
protected static function create_instance_from_record ( stdClass $ record ) { $ classname = context_helper :: get_class_for_level ( $ record -> contextlevel ) ; if ( $ context = context :: cache_get_by_id ( $ record -> id ) ) { return $ context ; } $ context = new $ classname ( $ record ) ; context :: cache_add ( $ con...
This function is also used to work around protected keyword problems in context_helper .
33,484
protected static function merge_context_temp_table ( ) { global $ DB ; $ dbfamily = $ DB -> get_dbfamily ( ) ; if ( $ dbfamily == 'mysql' ) { $ updatesql = "UPDATE {context} ct, {context_temp} temp SET ct.path = temp.path, ct.depth = temp.depth, ...
Copy prepared new contexts from temp table to context table we do this in db specific way for perf reasons only .
33,485
public static function instance_by_id ( $ id , $ strictness = MUST_EXIST ) { global $ DB ; if ( get_called_class ( ) !== 'context' and get_called_class ( ) !== 'context_helper' ) { throw new coding_exception ( 'use only context::instance_by_id() for real context levels use ::instance() methods' ) ; } if ( $ id == SYSCO...
Get a context instance as an object from a given context id .
33,486
public function update_moved ( context $ newparent ) { global $ DB ; $ frompath = $ this -> _path ; $ newpath = $ newparent -> path . '/' . $ this -> _id ; $ trans = $ DB -> start_delegated_transaction ( ) ; $ setdepth = '' ; if ( ( $ newparent -> depth + 1 ) != $ this -> _depth ) { $ diff = $ newparent -> depth - $ th...
Update context info after moving context in the tree structure .
33,487
public function set_locked ( bool $ locked ) { global $ DB ; if ( $ this -> _locked == $ locked ) { return $ this ; } $ this -> _locked = $ locked ; $ DB -> set_field ( 'context' , 'locked' , ( int ) $ locked , [ 'id' => $ this -> id ] ) ; $ this -> mark_dirty ( ) ; self :: reset_caches ( ) ; return $ this ; }
Set whether this context has been locked or not .
33,488
public function reset_paths ( $ rebuild = true ) { global $ DB ; if ( $ this -> _path ) { $ this -> mark_dirty ( ) ; } $ DB -> set_field_select ( 'context' , 'depth' , 0 , "path LIKE '%/$this->_id/%'" ) ; $ DB -> set_field_select ( 'context' , 'path' , NULL , "path LIKE '%/$this->_id/%'" ) ; if ( $ this -> _contextleve...
Remove all context path info and optionally rebuild it .
33,489
public function delete_content ( ) { global $ CFG , $ DB ; blocks_delete_all_for_context ( $ this -> _id ) ; filter_delete_all_for_context ( $ this -> _id ) ; require_once ( $ CFG -> dirroot . '/comment/lib.php' ) ; comment :: delete_comments ( array ( 'contextid' => $ this -> _id ) ) ; require_once ( $ CFG -> dirroot ...
Delete all data linked to content do not delete the context record itself
33,490
public function delete_capabilities ( ) { global $ DB ; $ ids = $ DB -> get_fieldset_select ( 'role_capabilities' , 'DISTINCT roleid' , 'contextid = ?' , array ( $ this -> _id ) ) ; if ( $ ids ) { $ DB -> delete_records ( 'role_capabilities' , array ( 'contextid' => $ this -> _id ) ) ; accesslib_clear_role_cache ( $ id...
Unassign all capabilities from a context .
33,491
public function delete ( ) { global $ DB ; if ( $ this -> _contextlevel <= CONTEXT_SYSTEM ) { throw new coding_exception ( 'Cannot delete system context' ) ; } if ( ! $ DB -> record_exists ( 'context' , array ( 'id' => $ this -> _id ) ) ) { context :: cache_remove ( $ this ) ; return ; } $ this -> delete_content ( ) ; ...
Delete the context content and the context record itself
33,492
protected static function insert_context_record ( $ contextlevel , $ instanceid , $ parentpath ) { global $ DB ; $ record = new stdClass ( ) ; $ record -> contextlevel = $ contextlevel ; $ record -> instanceid = $ instanceid ; $ record -> depth = 0 ; $ record -> path = null ; $ record -> locked = 0 ; $ record -> id = $...
Utility method for context creation
33,493
public function is_locked ( ) { if ( $ this -> _locked ) { return true ; } if ( $ parent = $ this -> get_parent_context ( ) ) { return $ parent -> is_locked ( ) ; } return false ; }
Whether the current context is locked .
33,494
public function get_parent_contexts ( $ includeself = false ) { if ( ! $ contextids = $ this -> get_parent_context_ids ( $ includeself ) ) { return array ( ) ; } context_helper :: preload_contexts_by_id ( $ contextids ) ; $ result = array ( ) ; foreach ( $ contextids as $ contextid ) { $ parent = context :: instance_by...
Returns parent contexts of this context in reversed order i . e . parent first then grand parent etc .
33,495
public function get_parent_context_ids ( $ includeself = false ) { if ( empty ( $ this -> _path ) ) { return array ( ) ; } $ parentcontexts = trim ( $ this -> _path , '/' ) ; $ parentcontexts = explode ( '/' , $ parentcontexts ) ; if ( ! $ includeself ) { array_pop ( $ parentcontexts ) ; } return array_reverse ( $ pare...
Returns parent context ids of this context in reversed order i . e . parent first then grand parent etc .
33,496
public function get_parent_context_paths ( $ includeself = false ) { if ( empty ( $ this -> _path ) ) { return array ( ) ; } $ contextids = explode ( '/' , $ this -> _path ) ; $ path = '' ; $ paths = array ( ) ; foreach ( $ contextids as $ contextid ) { if ( $ contextid ) { $ path .= '/' . $ contextid ; $ paths [ $ con...
Returns parent context paths of this context .
33,497
public function get_parent_context ( ) { if ( empty ( $ this -> _path ) or $ this -> _id == SYSCONTEXTID ) { return false ; } $ parentcontexts = trim ( $ this -> _path , '/' ) ; $ parentcontexts = explode ( '/' , $ parentcontexts ) ; array_pop ( $ parentcontexts ) ; $ contextid = array_pop ( $ parentcontexts ) ; return...
Returns parent context
33,498
public function reload_if_dirty ( ) { global $ ACCESSLIB_PRIVATE , $ USER ; if ( CLI_SCRIPT ) { if ( ! isset ( $ ACCESSLIB_PRIVATE -> dirtycontexts ) ) { $ ACCESSLIB_PRIVATE -> dirtycontexts = array ( ) ; } } else { if ( ! isset ( $ USER -> access [ 'time' ] ) ) { return ; } $ changedsince = $ USER -> access [ 'time' ]...
Reset all cached permissions and definitions if the necessary .
33,499
public static function get_class_for_level ( $ contextlevel ) { self :: init_levels ( ) ; if ( isset ( self :: $ alllevels [ $ contextlevel ] ) ) { return self :: $ alllevels [ $ contextlevel ] ; } else { throw new coding_exception ( 'Invalid context level specified' ) ; } }
Returns a class name of the context level class