idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
31,700
public function change_parent ( $ newparentcat ) { if ( is_object ( $ newparentcat ) ) { $ newparentcat = self :: get ( $ newparentcat -> id , MUST_EXIST , true ) ; } else { $ newparentcat = self :: get ( ( int ) $ newparentcat , MUST_EXIST , true ) ; } if ( $ newparentcat -> id != $ this -> parent ) { $ this -> change...
Efficiently moves a category - NOTE that this can have a huge impact access - control - wise ...
31,701
public function get_formatted_name ( $ options = array ( ) ) { if ( $ this -> id ) { $ context = $ this -> get_context ( ) ; return format_string ( $ this -> name , true , array ( 'context' => $ context ) + $ options ) ; } else { return get_string ( 'top' ) ; } }
Returns name of the category formatted as a string
31,702
public function get_nested_name ( $ includelinks = true , $ separator = ' / ' , $ options = [ ] ) { $ parents = $ this -> get_parents ( ) ; $ categories = static :: get_many ( $ parents ) ; $ categories [ ] = $ this ; $ names = array_map ( function ( $ category ) use ( $ options , $ includelinks ) { if ( $ includelinks...
Get the nested name of this category with all of it s parents .
31,703
public static function wake_from_cache ( $ a ) { $ record = new stdClass ; foreach ( self :: $ coursecatfields as $ property => $ cachedirectives ) { if ( $ cachedirectives !== null ) { list ( $ shortname , $ defaultvalue ) = $ cachedirectives ; if ( array_key_exists ( $ shortname , $ a ) ) { $ record -> $ property = $...
Takes the data provided by prepare_to_cache and reinitialises an instance of the associated from it .
31,704
public function can_review_filters ( ) { return $ this -> is_uservisible ( ) && has_capability ( 'moodle/filter:manage' , $ this -> get_context ( ) ) && count ( filter_get_available_in_context ( $ this -> get_context ( ) ) ) > 0 ; }
Returns true if the current user can review filter settings for this category .
31,705
public function resort_subcategories ( $ field , $ cleanup = true ) { global $ DB ; $ desc = false ; if ( substr ( $ field , - 4 ) === "desc" ) { $ desc = true ; $ field = substr ( $ field , 0 , - 4 ) ; } if ( $ field !== 'name' && $ field !== 'idnumber' ) { throw new coding_exception ( 'Invalid field requested' ) ; } ...
Resorts the sub categories of this category by the given field .
31,706
public function resort_courses ( $ field , $ cleanup = true ) { global $ DB ; $ desc = false ; if ( substr ( $ field , - 4 ) === "desc" ) { $ desc = true ; $ field = substr ( $ field , 0 , - 4 ) ; } if ( $ field !== 'fullname' && $ field !== 'shortname' && $ field !== 'idnumber' && $ field !== 'timecreated' ) { throw n...
Resort the courses within this category by the given field .
31,707
public function change_sortorder_by_one ( $ up ) { global $ DB ; $ params = array ( $ this -> sortorder , $ this -> parent ) ; if ( $ up ) { $ select = 'sortorder < ? AND parent = ?' ; $ sort = 'sortorder DESC' ; } else { $ select = 'sortorder > ? AND parent = ?' ; $ sort = 'sortorder ASC' ; } fix_course_sortorder ( ) ...
Changes the sort order of this categories parent shifting this category up or down one .
31,708
public function can_request_course ( ) { global $ CFG ; if ( empty ( $ CFG -> enablecourserequests ) || $ this -> id != $ CFG -> defaultrequestcategory ) { return false ; } return ! $ this -> can_create_course ( ) && has_capability ( 'moodle/course:request' , $ this -> get_context ( ) ) ; }
Returns true if the user is able to request a new course be created .
31,709
public static function can_approve_course_requests ( ) { global $ CFG , $ DB ; if ( empty ( $ CFG -> enablecourserequests ) ) { return false ; } $ context = context_system :: instance ( ) ; if ( ! has_capability ( 'moodle/site:approvecourse' , $ context ) ) { return false ; } if ( ! $ DB -> record_exists ( 'course_requ...
Returns true if the user can approve course requests .
31,710
public function sign ( $ http_method , $ url , $ params , $ secret ) { $ sig = array ( strtoupper ( $ http_method ) , preg_replace ( '/%7E/' , '~' , rawurlencode ( $ url ) ) , rawurlencode ( $ this -> get_signable_parameters ( $ params ) ) , ) ; $ base_string = implode ( '&' , $ sig ) ; $ sig = base64_encode ( hash_hma...
Create signature for oauth request
31,711
public function request_token ( ) { $ this -> sign_secret = $ this -> consumer_secret . '&' ; if ( empty ( $ this -> oauth_callback ) ) { $ params = [ ] ; } else { $ params = [ 'oauth_callback' => $ this -> oauth_callback -> out ( false ) ] ; } $ params = $ this -> prepare_oauth_parameters ( $ this -> request_token_api...
Request token for authentication This is the first step to use OAuth it will return oauth_token and oauth_token_secret
31,712
public function get_access_token ( $ token , $ secret , $ verifier = '' ) { $ this -> sign_secret = $ this -> consumer_secret . '&' . $ secret ; $ params = $ this -> prepare_oauth_parameters ( $ this -> access_token_api , array ( 'oauth_token' => $ token , 'oauth_verifier' => $ verifier ) , 'POST' ) ; $ this -> setup_o...
Request oauth access token from server
31,713
public function request ( $ method , $ url , $ params = array ( ) , $ token = '' , $ secret = '' ) { if ( empty ( $ token ) ) { $ token = $ this -> access_token ; } if ( empty ( $ secret ) ) { $ secret = $ this -> access_token_secret ; } $ this -> sign_secret = $ this -> consumer_secret . '&' . $ secret ; if ( strtolow...
Request oauth protected resources
31,714
public function get ( $ url , $ params = array ( ) , $ token = '' , $ secret = '' ) { return $ this -> request ( 'GET' , $ url , $ params , $ token , $ secret ) ; }
shortcut to start http get request
31,715
public function post ( $ url , $ params = array ( ) , $ token = '' , $ secret = '' ) { return $ this -> request ( 'POST' , $ url , $ params , $ token , $ secret ) ; }
shortcut to start http post request
31,716
public function parse_result ( $ str ) { if ( empty ( $ str ) ) { throw new moodle_exception ( 'error' ) ; } $ parts = explode ( '&' , $ str ) ; $ result = array ( ) ; foreach ( $ parts as $ part ) { list ( $ k , $ v ) = explode ( '=' , $ part , 2 ) ; $ result [ urldecode ( $ k ) ] = urldecode ( $ v ) ; } if ( empty ( ...
A method to parse oauth response to get oauth_token and oauth_token_secret
31,717
function get_nonce ( ) { if ( ! empty ( $ this -> nonce ) ) { $ nonce = $ this -> nonce ; unset ( $ this -> nonce ) ; return $ nonce ; } $ mt = microtime ( ) ; $ rand = mt_rand ( ) ; return md5 ( $ mt . $ rand ) ; }
Generate nonce for oauth request
31,718
public function is_logged_in ( ) { if ( isset ( $ this -> accesstoken -> expires ) && time ( ) >= $ this -> accesstoken -> expires ) { $ this -> log_out ( ) ; return false ; } if ( isset ( $ this -> accesstoken -> token ) ) { $ scopemissing = false ; $ scopecheck = ' ' . $ this -> accesstoken -> scope . ' ' ; $ require...
Is the user logged in? Note that if this is called after the first part of the authorisation flow the token is upgraded to an accesstoken .
31,719
public function get_login_url ( ) { $ callbackurl = self :: callback_url ( ) ; $ params = array_merge ( [ 'client_id' => $ this -> clientid , 'response_type' => 'code' , 'redirect_uri' => $ callbackurl -> out ( false ) , 'state' => $ this -> returnurl -> out_as_local_url ( false ) , 'scope' => $ this -> scope , ] , $ t...
Returns the login link for this oauth request
31,720
public function upgrade_token ( $ code ) { $ callbackurl = self :: callback_url ( ) ; $ params = array ( 'code' => $ code , 'grant_type' => 'authorization_code' , 'redirect_uri' => $ callbackurl -> out ( false ) , ) ; if ( $ this -> basicauth ) { $ idsecret = urlencode ( $ this -> clientid ) . ':' . urlencode ( $ this ...
Upgrade a authorization token from oauth 2 . 0 to an access token
31,721
protected function request ( $ url , $ options = array ( ) , $ acceptheader = 'application/json' ) { $ murl = new moodle_url ( $ url ) ; if ( $ this -> accesstoken ) { if ( $ this -> use_http_get ( ) ) { $ murl -> param ( 'access_token' , $ this -> accesstoken -> token ) ; } else { $ this -> setHeader ( 'Authorization:...
Make a HTTP request adding the access token we have
31,722
protected function multi ( $ requests , $ options = array ( ) ) { if ( $ this -> accesstoken ) { $ this -> setHeader ( 'Authorization: Bearer ' . $ this -> accesstoken -> token ) ; } return parent :: multi ( $ requests , $ options ) ; }
Multiple HTTP Requests This function could run multi - requests in parallel .
31,723
protected function store_token ( $ token ) { global $ SESSION ; $ this -> accesstoken = $ token ; $ name = $ this -> get_tokenname ( ) ; if ( $ token !== null ) { $ SESSION -> { $ name } = $ token ; } else { unset ( $ SESSION -> { $ name } ) ; } }
Store a token between requests . Currently uses session named by get_tokenname
31,724
protected function get_stored_token ( ) { global $ SESSION ; $ name = $ this -> get_tokenname ( ) ; if ( isset ( $ SESSION -> { $ name } ) ) { return $ SESSION -> { $ name } ; } return null ; }
Retrieve a token stored .
31,725
public function disconnect ( ) { if ( is_object ( $ this -> _smtp ) && $ this -> _smtp -> disconnect ( ) ) { $ this -> _smtp = null ; } return ( $ this -> _smtp === null ) ; }
Disconnect and destroy the current SMTP connection .
31,726
public function print_login ( ) { $ client = $ this -> get_user_oauth_client ( ) ; $ url = $ client -> get_login_url ( ) ; if ( $ this -> options [ 'ajax' ] ) { $ popup = new stdClass ( ) ; $ popup -> type = 'popup' ; $ popup -> url = $ url -> out ( false ) ; return array ( 'login' => array ( $ popup ) ) ; } else { ech...
Print or return the login form .
31,727
public function print_login_popup ( $ attr = null ) { global $ OUTPUT , $ PAGE ; $ client = $ this -> get_user_oauth_client ( false ) ; $ url = new moodle_url ( $ client -> get_login_url ( ) ) ; $ state = $ url -> get_param ( 'state' ) . '&reloadparent=true' ; $ url -> param ( 'state' , $ state ) ; $ PAGE -> set_pagela...
Print the login in a popup .
31,728
protected function build_breadcrumb ( $ path ) { $ bread = explode ( '/' , $ path ) ; $ crumbtrail = '' ; foreach ( $ bread as $ crumb ) { list ( $ id , $ name ) = $ this -> explode_node_path ( $ crumb ) ; $ name = empty ( $ name ) ? $ id : $ name ; $ breadcrumb [ ] = array ( 'name' => $ name , 'path' => $ this -> buil...
Build the breadcrumb from a path .
31,729
protected function build_node_path ( $ id , $ name = '' , $ root = '' ) { $ path = $ id ; if ( ! empty ( $ name ) ) { $ path .= '|' . urlencode ( $ name ) ; } if ( ! empty ( $ root ) ) { $ path = trim ( $ root , '/' ) . '/' . $ path ; } return $ path ; }
Generates a safe path to a node .
31,730
protected function explode_node_path ( $ node ) { if ( strpos ( $ node , '|' ) !== false ) { list ( $ id , $ name ) = explode ( '|' , $ node , 2 ) ; $ name = urldecode ( $ name ) ; } else { $ id = $ node ; $ name = '' ; } $ id = urldecode ( $ id ) ; return array ( 0 => $ id , 1 => $ name , 'id' => $ id , 'name' => $ na...
Returns information about a node in a path .
31,731
protected function delete_file_by_path ( \ repository_onedrive \ rest $ client , $ fullpath ) { try { $ response = $ client -> call ( 'delete_file_by_path' , [ 'fullpath' => $ fullpath ] ) ; } catch ( \ core \ oauth2 \ rest_exception $ re ) { return false ; } return true ; }
Delete a file by full path .
31,732
protected function create_folder_in_folder ( \ repository_onedrive \ rest $ client , $ foldername , $ parentid ) { $ params = [ 'parentid' => $ parentid ] ; $ folder = [ 'name' => $ foldername , 'folder' => [ 'childCount' => 0 ] ] ; $ created = $ client -> call ( 'create_folder' , $ params , json_encode ( $ folder ) ) ...
Create a folder within a folder
31,733
protected function get_mimetype_from_filename ( $ filename ) { $ mimetype = 'application/unknown' ; $ types = core_filetypes :: get_types ( ) ; $ fileextension = '.bin' ; if ( strpos ( $ filename , '.' ) !== false ) { $ fileextension = substr ( $ filename , strrpos ( $ filename , '.' ) + 1 ) ; } if ( isset ( $ types [ ...
Given a filename use the core_filetypes registered types to guess a mimetype .
31,734
protected function upload_file ( \ repository_onedrive \ rest $ service , \ curl $ curl , \ curl $ authcurl , $ filepath , $ mimetype , $ parentid , $ filename ) { $ params = [ 'parentid' => $ parentid , 'filename' => urlencode ( $ filename ) ] ; $ behaviour = [ 'item' => [ "@microsoft.graph.conflictBehavior" => "renam...
Upload a file to onedrive .
31,735
public function get_reference_details ( $ reference , $ filestatus = 0 ) { if ( empty ( $ reference ) ) { return get_string ( 'unknownsource' , 'repository' ) ; } $ source = json_decode ( $ reference ) ; if ( empty ( $ source -> usesystem ) ) { return '' ; } $ systemauth = \ core \ oauth2 \ api :: get_system_oauth_clie...
Get human readable file info from the reference .
31,736
public static function can_import_skydrive_files ( ) { global $ DB ; $ skydrive = $ DB -> get_record ( 'repository' , [ 'type' => 'skydrive' ] , 'id' , IGNORE_MISSING ) ; $ onedrive = $ DB -> get_record ( 'repository' , [ 'type' => 'onedrive' ] , 'id' , IGNORE_MISSING ) ; if ( empty ( $ skydrive ) || empty ( $ onedrive...
Return true if any instances of the skydrive repo exist - and we can import them .
31,737
public static function import_skydrive_files ( ) { global $ DB ; if ( ! self :: can_import_skydrive_files ( ) ) { return false ; } $ skydrivetype = repository :: get_type_by_typename ( 'skydrive' ) ; $ skydriveinstances = repository :: get_instances ( [ 'type' => 'skydrive' ] ) ; $ skydriveinstance = reset ( $ skydrive...
Import all the files that were created with the skydrive repo to this repo .
31,738
public function after_restore ( ) { global $ DB ; $ blockid = $ this -> get_blockid ( ) ; if ( $ configdata = $ DB -> get_field ( 'block_instances' , 'configdata' , array ( 'id' => $ blockid ) ) ) { $ config = unserialize ( base64_decode ( $ configdata ) ) ; if ( ! empty ( $ config -> activityparentid ) ) { if ( $ mapp...
This function executed after all the tasks in the plan have been executed will perform the recode of the target activity for the block . This must be done here and not in normal execution steps because the activity can be restored after the block .
31,739
public static function save_filter_values_from_form ( tour $ tour , \ stdClass $ data ) { $ filtername = static :: get_filter_name ( ) ; $ key = "filter_{$filtername}" ; $ newvalue = $ data -> $ key ; foreach ( $ data -> $ key as $ value ) { if ( $ value === static :: ANYVALUE ) { $ newvalue = [ ] ; break ; } } $ tour ...
Save the filter values from the form to the tour .
31,740
public function get_field_config_form ( field_controller $ field ) : field_config_form { $ form = new field_config_form ( null , [ 'field' => $ field ] ) ; $ form -> set_data ( api :: prepare_field_for_config_form ( $ field ) ) ; return $ form ; }
The form to create or edit a field
31,741
public function create_category ( string $ name = null ) : int { global $ DB ; $ params = [ 'component' => $ this -> get_component ( ) , 'area' => $ this -> get_area ( ) , 'itemid' => $ this -> get_itemid ( ) ] ; if ( empty ( $ name ) ) { for ( $ suffix = 0 ; $ suffix < 100 ; $ suffix ++ ) { $ name = $ this -> generate...
Creates a new category and inserts it to the database
31,742
protected function validate_category ( category_controller $ category ) : category_controller { $ categories = $ this -> get_categories_with_fields ( ) ; if ( ! array_key_exists ( $ category -> get ( 'id' ) , $ categories ) ) { throw new \ moodle_exception ( 'categorynotfound' , 'core_customfield' ) ; } return $ catego...
Validate that the given category belongs to this handler
31,743
protected function validate_field ( field_controller $ field ) : field_controller { if ( ! array_key_exists ( $ field -> get ( 'categoryid' ) , $ this -> get_categories_with_fields ( ) ) ) { throw new \ moodle_exception ( 'fieldnotfound' , 'core_customfield' ) ; } $ category = $ this -> get_categories_with_fields ( ) [...
Validate that the given field belongs to this handler
31,744
public function rename_category ( category_controller $ category , string $ name ) { $ this -> validate_category ( $ category ) ; $ category -> set ( 'name' , $ name ) ; api :: save_category ( $ category ) ; $ this -> clear_configuration_cache ( ) ; }
Change name for a field category
31,745
public function move_category ( category_controller $ category , int $ beforeid = 0 ) { $ category = $ this -> validate_category ( $ category ) ; api :: move_category ( $ category , $ beforeid ) ; $ this -> clear_configuration_cache ( ) ; }
Change sort order of the categories
31,746
public function delete_category ( category_controller $ category ) : bool { $ category = $ this -> validate_category ( $ category ) ; $ result = api :: delete_category ( $ category ) ; $ this -> clear_configuration_cache ( ) ; return $ result ; }
Permanently delete category all fields in it and all associated data
31,747
public function delete_all ( ) { $ categories = $ this -> get_categories_with_fields ( ) ; foreach ( $ categories as $ category ) { api :: delete_category ( $ category ) ; } $ this -> clear_configuration_cache ( ) ; }
Deletes all data and all fields and categories defined in this handler
31,748
public function delete_field_configuration ( field_controller $ field ) : bool { $ field = $ this -> validate_field ( $ field ) ; $ result = api :: delete_field_configuration ( $ field ) ; $ this -> clear_configuration_cache ( ) ; return $ result ; }
Permanently delete a custom field configuration and all associated data
31,749
public function get_instance_data ( int $ instanceid , bool $ returnall = false ) : array { $ fields = $ returnall ? $ this -> get_fields ( ) : $ this -> get_visible_fields ( $ instanceid ) ; return api :: get_instance_fields_data ( $ fields , $ instanceid ) ; }
Returns the custom field values for an individual instance
31,750
public function get_instances_data ( array $ instanceids , bool $ returnall = false ) : array { $ result = api :: get_instances_fields_data ( $ this -> get_fields ( ) , $ instanceids ) ; if ( ! $ returnall ) { $ handler = $ this ; foreach ( $ instanceids as $ instanceid ) { $ result [ $ instanceid ] = array_filter ( $ ...
Returns the custom fields values for multiple instances
31,751
public function display_custom_fields_data ( array $ fieldsdata ) : string { global $ PAGE ; $ output = $ PAGE -> get_renderer ( 'core_customfield' ) ; $ content = '' ; foreach ( $ fieldsdata as $ data ) { $ fd = new field_data ( $ data ) ; $ content .= $ output -> render ( $ fd ) ; } return $ content ; }
Display visible custom fields . This is a sample implementation that can be overridden in each handler .
31,752
public function get_categories_with_fields ( ) : array { if ( $ this -> categories === null ) { $ this -> categories = api :: get_categories_with_fields ( $ this -> get_component ( ) , $ this -> get_area ( ) , $ this -> get_itemid ( ) ) ; } $ handler = $ this ; array_walk ( $ this -> categories , function ( category_co...
Returns array of categories each of them contains a list of fields definitions .
31,753
protected function can_backup ( field_controller $ field , int $ instanceid ) : bool { return $ this -> can_view ( $ field , $ instanceid ) || $ this -> can_edit ( $ field , $ instanceid ) ; }
Checks if current user can backup a given field
31,754
public function get_instance_data_for_backup ( int $ instanceid ) : array { $ finalfields = [ ] ; $ data = $ this -> get_instance_data ( $ instanceid , true ) ; foreach ( $ data as $ d ) { if ( $ d -> get ( 'id' ) && $ this -> can_backup ( $ d -> get_field ( ) , $ instanceid ) ) { $ finalfields [ ] = [ 'id' => $ d -> g...
Get raw data associated with all fields current user can view or edit
31,755
public function instance_form_definition_after_data ( \ MoodleQuickForm $ mform , int $ instanceid = 0 ) { $ editablefields = $ this -> get_editable_fields ( $ instanceid ) ; $ fields = api :: get_instance_fields_data ( $ editablefields , $ instanceid ) ; foreach ( $ fields as $ formfield ) { $ formfield -> instance_fo...
Form data definition callback .
31,756
public function instance_form_save ( stdClass $ instance , bool $ isnewinstance = false ) { if ( empty ( $ instance -> id ) ) { throw new \ coding_exception ( 'Caller must ensure that id is already set in data before calling this method' ) ; } if ( ! preg_grep ( '/^customfield_/' , array_keys ( ( array ) $ instance ) )...
Saves the given data for custom fields must be called after the instance is saved and id is present
31,757
public function instance_form_definition ( \ MoodleQuickForm $ mform , int $ instanceid = 0 ) { $ editablefields = $ this -> get_editable_fields ( $ instanceid ) ; $ fieldswithdata = api :: get_instance_fields_data ( $ editablefields , $ instanceid ) ; $ lastcategoryid = null ; foreach ( $ fieldswithdata as $ data ) { ...
Adds custom fields to instance editing form
31,758
public function save_field_configuration ( field_controller $ field , stdClass $ data ) { if ( $ field -> get ( 'id' ) ) { $ field = $ this -> validate_field ( $ field ) ; } else { $ this -> validate_category ( $ field -> get_category ( ) ) ; } api :: save_field_configuration ( $ field , $ data ) ; $ this -> clear_conf...
Save the field configuration with the data from the form
31,759
protected function get_visible_fields ( int $ instanceid ) : array { $ handler = $ this ; return array_filter ( $ this -> get_fields ( ) , function ( $ field ) use ( $ handler , $ instanceid ) { return $ handler -> can_view ( $ field , $ instanceid ) ; } ) ; }
Get visible fields
31,760
public function get_editable_fields ( int $ instanceid ) : array { $ handler = $ this ; return array_filter ( $ this -> get_fields ( ) , function ( $ field ) use ( $ handler , $ instanceid ) { return $ handler -> can_edit ( $ field , $ instanceid ) ; } ) ; }
Get editable fields
31,761
public function delete_instance ( int $ instanceid ) { $ fielddata = api :: get_instance_fields_data ( $ this -> get_fields ( ) , $ instanceid , false ) ; foreach ( $ fielddata as $ data ) { $ data -> delete ( ) ; } }
Deletes all data related to all fields of an instance .
31,762
public function export_for_template ( \ renderer_base $ output ) { $ value = $ this -> get_value ( ) ; return ( object ) [ 'value' => $ value , 'type' => $ this -> get_type ( ) , 'shortname' => $ this -> get_shortname ( ) , 'name' => $ this -> get_name ( ) , 'hasvalue' => ( $ value !== null ) , 'instanceid' => $ this -...
Export data for using as template context .
31,763
public static function export_user_data ( approved_contextlist $ contextlist ) { global $ DB ; $ context = \ context_user :: instance ( $ contextlist -> get_user ( ) -> id ) ; $ sql = "SELECT ml.id, mh.wwwroot, mh.name, ml.remoteid, ml.time, ml.userid, ml.ip, ml.course, ml.coursename, ml.module, m...
Export all user data for the specified user in the specified contexts using the supplied exporter instance .
31,764
public static function update_user_preferences ( $ userid = 0 , $ emailstop = null , $ preferences = array ( ) ) { global $ USER , $ CFG ; require_once ( $ CFG -> dirroot . '/user/lib.php' ) ; require_once ( $ CFG -> dirroot . '/user/editlib.php' ) ; require_once ( $ CFG -> dirroot . '/message/lib.php' ) ; if ( empty (...
Update the user s preferences .
31,765
public static function get_users_by_field ( $ field , $ values ) { global $ CFG , $ USER , $ DB ; require_once ( $ CFG -> dirroot . "/user/lib.php" ) ; $ params = self :: validate_parameters ( self :: get_users_by_field_parameters ( ) , array ( 'field' => $ field , 'values' => $ values ) ) ; $ cleanedvalues = array ( )...
Get user information for a unique field .
31,766
public static function get_course_user_profiles ( $ userlist ) { global $ CFG , $ USER , $ DB ; require_once ( $ CFG -> dirroot . "/user/lib.php" ) ; $ params = self :: validate_parameters ( self :: get_course_user_profiles_parameters ( ) , array ( 'userlist' => $ userlist ) ) ; $ userids = array ( ) ; $ courseids = ar...
Get course participant s details
31,767
public static function add_user_private_files ( $ draftid ) { global $ CFG , $ USER ; require_once ( $ CFG -> libdir . "/filelib.php" ) ; $ params = self :: validate_parameters ( self :: add_user_private_files_parameters ( ) , array ( 'draftid' => $ draftid ) ) ; if ( isguestuser ( ) ) { throw new invalid_parameter_exc...
Copy files from a draft area to users private files area .
31,768
public static function view_user_list ( $ courseid ) { global $ CFG ; require_once ( $ CFG -> dirroot . "/user/lib.php" ) ; require_once ( $ CFG -> dirroot . '/course/lib.php' ) ; $ params = self :: validate_parameters ( self :: view_user_list_parameters ( ) , array ( 'courseid' => $ courseid ) ) ; $ warnings = array (...
Trigger the user_list_viewed event .
31,769
public static function view_user_profile ( $ userid , $ courseid = 0 ) { global $ CFG , $ USER ; require_once ( $ CFG -> dirroot . "/user/profile/lib.php" ) ; $ params = self :: validate_parameters ( self :: view_user_profile_parameters ( ) , array ( 'userid' => $ userid , 'courseid' => $ courseid ) ) ; $ warnings = ar...
Trigger the user profile viewed event .
31,770
public static function get_user_preferences ( $ name = '' , $ userid = 0 ) { global $ USER ; $ params = self :: validate_parameters ( self :: get_user_preferences_parameters ( ) , array ( 'name' => $ name , 'userid' => $ userid ) ) ; $ preferences = array ( ) ; $ warnings = array ( ) ; $ context = context_system :: ins...
Return user preferences .
31,771
public static function update_picture ( $ draftitemid , $ delete = false , $ userid = 0 ) { global $ CFG , $ USER , $ PAGE ; $ params = self :: validate_parameters ( self :: update_picture_parameters ( ) , array ( 'draftitemid' => $ draftitemid , 'delete' => $ delete , 'userid' => $ userid ) ) ; $ context = context_sys...
Update or delete the user picture in the site
31,772
public static function set_user_preferences ( $ preferences ) { global $ USER ; $ params = self :: validate_parameters ( self :: set_user_preferences_parameters ( ) , array ( 'preferences' => $ preferences ) ) ; $ warnings = array ( ) ; $ saved = array ( ) ; $ context = context_system :: instance ( ) ; self :: validate...
Set user preferences .
31,773
public static function agree_site_policy ( ) { global $ CFG , $ DB , $ USER ; $ warnings = array ( ) ; $ context = context_system :: instance ( ) ; try { self :: validate_context ( $ context ) ; } catch ( Exception $ e ) { if ( ! ( $ e instanceof moodle_exception ) or $ e -> errorcode != 'sitepolicynotagreed' ) { throw...
Agree the site policy for the current user .
31,774
public static function get_private_files_info ( $ userid = 0 ) { global $ CFG , $ USER ; require_once ( $ CFG -> libdir . '/filelib.php' ) ; $ params = self :: validate_parameters ( self :: get_private_files_info_parameters ( ) , array ( 'userid' => $ userid ) ) ; $ warnings = array ( ) ; $ context = context_system :: ...
Returns general information about files in the user private files area .
31,775
public static function get_service_for_user_context ( \ context_user $ context ) : local \ service \ user_favourite_service { return new local \ service \ user_favourite_service ( $ context , new local \ repository \ favourite_repository ( ) ) ; }
Returns a basic service object providing operations for user favourites .
31,776
public function process_extraanswerdata ( $ data ) { global $ DB ; $ extra = $ this -> qtypeobj -> extra_answer_fields ( ) ; $ tablename = array_shift ( $ extra ) ; $ oldquestionid = $ this -> get_old_parentid ( 'question' ) ; $ questioncreated = $ this -> get_mappingid ( 'question_created' , $ oldquestionid ) ? true :...
Processes the extra answer data
31,777
protected function can_preview ( ) { return empty ( $ this -> question -> beingcopied ) && ! empty ( $ this -> question -> id ) && $ this -> question -> formoptions -> canedit ; }
Is the question being edited in a state where it can be previewed?
31,778
protected function get_per_answer_fields ( $ mform , $ label , $ gradeoptions , & $ repeatedoptions , & $ answersoption ) { $ repeated = array ( ) ; $ answeroptions = array ( ) ; $ answeroptions [ ] = $ mform -> createElement ( 'text' , 'answer' , $ label , array ( 'size' => 40 ) ) ; $ answeroptions [ ] = $ mform -> cr...
Get the list of form elements to repeat one for each answer .
31,779
protected function add_tag_fields ( $ mform ) { global $ CFG , $ DB ; $ hastagcapability = question_has_capability_on ( $ this -> question , 'tag' ) ; $ qcontext = $ this -> categorycontext ; $ qcoursecontext = $ qcontext -> get_course_context ( false ) ; $ iscourseoractivityquestion = ! empty ( $ qcoursecontext ) ; $ ...
Add the tag and course tag fields to the mform .
31,780
protected function add_per_answer_fields ( & $ mform , $ label , $ gradeoptions , $ minoptions = QUESTION_NUMANS_START , $ addoptions = QUESTION_NUMANS_ADD ) { $ mform -> addElement ( 'header' , 'answerhdr' , get_string ( 'answers' , 'question' ) , '' ) ; $ mform -> setExpanded ( 'answerhdr' , 1 ) ; $ answersoption = '...
Add a set of form fields obtained from get_per_answer_fields to the form one for each existing answer with some blanks for some new ones .
31,781
protected function get_hint_fields ( $ withclearwrong = false , $ withshownumpartscorrect = false ) { $ mform = $ this -> _form ; $ repeatedoptions = array ( ) ; $ repeated = array ( ) ; $ repeated [ ] = $ mform -> createElement ( 'editor' , 'hint' , get_string ( 'hintn' , 'question' ) , array ( 'rows' => 5 ) , $ this ...
Create the form elements required by one hint .
31,782
protected function data_preprocessing_extra_answer_fields ( $ question , $ extraanswerfields ) { $ extrafieldsdata = array ( ) ; foreach ( $ extraanswerfields as $ field ) { $ extrafieldsdata [ $ field ] = array ( ) ; } $ key = 0 ; foreach ( $ question -> options -> answers as $ answer ) { foreach ( $ extraanswerfields...
Perform the necessary preprocessing for the extra answer fields .
31,783
public static function delete_data_for_all_users_in_context ( \ context $ context ) { global $ DB ; if ( $ context instanceof \ context_course ) { $ sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = ?) AND type = ?" ; $ DB -> delete_records_select ( 'backup_controllers' , $ sectionsql , [ $ conte...
Delete all user data which matches the specified context . Only dealing with the specific context - not it s child contexts .
31,784
public static function delete_data_for_users ( approved_userlist $ userlist ) { global $ DB ; if ( empty ( $ userlist -> get_userids ( ) ) ) { return ; } $ context = $ userlist -> get_context ( ) ; if ( $ context instanceof \ context_course ) { list ( $ usersql , $ userparams ) = $ DB -> get_in_or_equal ( $ userlist ->...
Delete multiple users within a single context . Only dealing with the specific context - not it s child contexts .
31,785
public static function delete_data_for_user ( approved_contextlist $ contextlist ) { global $ DB ; if ( empty ( $ contextlist -> count ( ) ) ) { return ; } $ userid = $ contextlist -> get_user ( ) -> id ; foreach ( $ contextlist -> get_contexts ( ) as $ context ) { if ( $ context instanceof \ context_course ) { $ selec...
Delete all user data for the specified user in the specified contexts . Only dealing with the specific context - not it s child contexts .
31,786
public function convert_to_timestamp ( $ year , $ month , $ day , $ hour = 0 , $ minute = 0 ) { $ gregorianinfo = $ this -> convert_to_gregorian ( $ year , $ month , $ day , $ hour , $ minute ) ; return make_timestamp ( $ gregorianinfo [ 'year' ] , $ gregorianinfo [ 'month' ] , $ gregorianinfo [ 'day' ] , $ gregorianin...
Provided with a day month year hour and minute in the specific calendar type convert it into the equivalent Unix Time Stamp .
31,787
public function get_prev_day ( $ daytimestamp ) { $ date = new \ DateTime ( ) ; $ date -> setTimestamp ( $ daytimestamp ) ; $ date -> modify ( '-1 day' ) ; return $ date -> getTimestamp ( ) ; }
Get the previous day .
31,788
public function get_next_day ( $ daytimestamp ) { $ date = new \ DateTime ( ) ; $ date -> setTimestamp ( $ daytimestamp ) ; $ date -> modify ( '+1 day' ) ; return $ date -> getTimestamp ( ) ; }
Get the next day .
31,789
public function set_value ( $ value ) { if ( $ this -> running_javascript ( ) ) { $ this -> field -> click ( ) ; if ( ! empty ( $ value ) && ! $ this -> field -> isSelected ( ) ) { $ this -> trigger_on_change ( ) ; } } else { $ this -> field -> setValue ( $ this -> field -> getAttribute ( 'value' ) ) ; } }
Sets the value of a radio
31,790
private function div ( $ s1 , $ s2 , $ scale ) { if ( $ this -> bcmath ) { return bcdiv ( $ s1 , $ s2 , $ scale ) ; } else { return $ this -> scale ( ( float ) $ s1 / ( float ) $ s2 , $ scale ) ; } }
Divides two numbers using arbitrary precision when available .
31,791
function DropColumnSQL ( $ tabname , $ flds , $ tableflds = '' , $ tableoptions = '' ) { $ tabname = $ this -> TableName ( $ tabname ) ; if ( ! is_array ( $ flds ) ) $ flds = explode ( ',' , $ flds ) ; $ f = array ( ) ; $ s = 'ALTER TABLE ' . $ tabname ; foreach ( $ flds as $ v ) { if ( $ constraintname = $ this -> Def...
Drop a column syntax is ALTER TABLE table DROP COLUMN column column
31,792
public static function instance ( $ prototype = null ) { static $ instance = null ; if ( $ prototype !== null ) { $ instance = $ prototype ; } elseif ( $ instance === null || $ prototype == true ) { $ instance = new HTMLPurifier_URISchemeRegistry ( ) ; } return $ instance ; }
Retrieve sole instance of the registry .
31,793
public function getScheme ( $ scheme , $ config , $ context ) { if ( ! $ config ) { $ config = HTMLPurifier_Config :: createDefault ( ) ; } $ allowed_schemes = $ config -> get ( 'URI.AllowedSchemes' ) ; if ( ! $ config -> get ( 'URI.OverrideAllowedSchemes' ) && ! isset ( $ allowed_schemes [ $ scheme ] ) ) { return ; } ...
Retrieves a scheme validator object
31,794
public function compute_correlations ( $ mincorrelation = 2 ) { global $ DB ; $ sql = 'SELECT pairs.tagid, pairs.correlation, pairs.ocurrences, co.id AS correlationid FROM ( SELECT ta.tagid, tb.tagid AS correlation, COUNT(*) AS ocurrences FROM {tag_...
Calculates and stores the correlated tags of all tags .
31,795
public function cleanup ( ) { global $ DB ; $ sql = "SELECT ti.id FROM {tag_instance} ti LEFT JOIN {tag} t ON t.id = ti.tagid WHERE t.id IS null" ; $ tagids = $ DB -> get_records_sql ( $ sql ) ; $ tagarray = array ( ) ; foreach ( $ tagids as $ tagid ) { $ tagarray [ ] = $ ta...
Clean up the tag tables making sure all tagged object still exists .
31,796
public function process_computed_correlation ( stdClass $ tagcorrelation ) { global $ DB ; if ( empty ( $ tagcorrelation -> tagid ) || ! isset ( $ tagcorrelation -> correlatedtags ) || ! is_array ( $ tagcorrelation -> correlatedtags ) ) { return false ; } $ tagcorrelation -> correlatedtags = join ( ',' , $ tagcorrelati...
This function processes a tag correlation and makes changes in the database as required .
31,797
public function bulk_delete_instances ( $ instances ) { global $ DB ; $ instanceids = array ( ) ; foreach ( $ instances as $ instance ) { $ instanceids [ ] = $ instance -> id ; } list ( $ insql , $ params ) = $ DB -> get_in_or_equal ( $ instanceids ) ; $ sql = 'id ' . $ insql ; $ DB -> delete_records_select ( 'tag_inst...
This function will delete numerous tag instances efficiently . This removes tag instances only . It doesn t check to see if it is the last use of a tag .
31,798
protected function adaptive_mark_details_from_step ( question_attempt_step $ gradedstep , question_state $ state , $ maxmark , $ penalty ) { $ details = new qbehaviour_adaptive_mark_details ( $ state ) ; $ details -> maxmark = $ maxmark ; $ details -> actualmark = $ gradedstep -> get_fraction ( ) * $ details -> maxmark...
Actually populate the qbehaviour_adaptive_mark_details object .
31,799
public function get_params_rawencoded ( ) { $ params = $ this -> get_params ( ) ; $ encoded = array ( ) ; $ encoded [ ] = 'contextid=' . $ params [ 'contextid' ] ; $ encoded [ ] = 'component=' . $ params [ 'component' ] ; $ encoded [ ] = 'filearea=' . $ params [ 'filearea' ] ; $ encoded [ ] = 'itemid=' . ( is_null ( $ ...
Returns array of url encoded params .