idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
34,600
public function clear_wrong ( question_attempt $ qa , $ reallyclear = true ) { $ question = $ qa -> get_question ( ) ; $ response = $ qa -> get_last_qt_data ( ) ; if ( ! empty ( $ response ) && $ reallyclear ) { $ cleanresponse = $ question -> clear_wrong_from_response ( $ response ) ; } else { $ cleanresponse = $ resp...
Actually this question type abuses this method to always output the hidden fields it needs .
34,601
public function safely ( $ cCode ) { if ( $ this -> oFormat -> get ( 'IgnoreExceptions' ) ) { try { return $ cCode ( ) ; } catch ( OutputException $ e ) { return null ; } } else { return $ cCode ( ) ; } }
Runs the given code either swallowing or passing exceptions depending on the bIgnoreExceptions setting .
34,602
public function initialize ( $ page , $ contexts , $ currentcat , $ defaultcategory , $ todelete , $ addcontexts ) { $ lastlist = null ; foreach ( $ contexts as $ context ) { $ this -> editlists [ $ context -> id ] = new question_category_list ( 'ul' , '' , true , $ this -> pageurl , $ page , 'cpage' , QUESTION_PAGE_LE...
Initializes this classes general category - related variables
34,603
public function get_course_ids ( $ categories ) { $ courseids = array ( ) ; foreach ( $ categories as $ key => $ cat ) { $ courseids [ $ key ] = $ cat -> course ; if ( ! empty ( $ cat -> children ) ) { $ courseids = array_merge ( $ courseids , $ this -> get_course_ids ( $ cat -> children ) ) ; } } return $ courseids ; ...
gets all the courseids for the given categories
34,604
public function set_viable_parents ( & $ parentstrings , $ category ) { unset ( $ parentstrings [ $ category -> id ] ) ; if ( isset ( $ category -> children ) ) { foreach ( $ category -> children as $ child ) { $ this -> set_viable_parents ( $ parentstrings , $ child ) ; } } }
Sets the viable parents
34,605
public function get_question_categories ( $ parent = null , $ sort = "sortorder ASC" ) { global $ COURSE , $ DB ; if ( is_null ( $ parent ) ) { $ categories = $ DB -> get_records ( 'question_categories' , array ( 'course' => $ COURSE -> id ) , $ sort ) ; } else { $ select = "parent = ? AND course = ?" ; $ categories = ...
Gets question categories
34,606
public function delete_category ( $ categoryid ) { global $ CFG , $ DB ; question_can_delete_cat ( $ categoryid ) ; if ( ! $ category = $ DB -> get_record ( "question_categories" , array ( "id" => $ categoryid ) ) ) { print_error ( 'unknowcategory' ) ; } $ DB -> set_field ( "question_categories" , "parent" , $ category...
Deletes an existing question category
34,607
public function add_category ( $ newparent , $ newcategory , $ newinfo , $ return = false , $ newinfoformat = FORMAT_HTML , $ idnumber = null ) { global $ DB ; if ( empty ( $ newcategory ) ) { print_error ( 'categorynamecantbeblank' , 'question' ) ; } list ( $ parentid , $ contextid ) = explode ( ',' , $ newparent ) ; ...
Creates a new category with given params
34,608
protected function attempt_counts_and_averages ( $ quizid , \ core \ dml \ sql_join $ groupstudentsjoins ) { global $ DB ; $ attempttotals = new \ stdClass ( ) ; foreach ( array_keys ( quiz_get_grading_options ( ) ) as $ which ) { list ( $ fromqa , $ whereqa , $ qaparams ) = quiz_statistics_attempts_sql ( $ quizid , $ ...
Calculating count and mean of marks for first and ALL attempts by students .
34,609
protected function median ( $ s , $ fromqa , $ whereqa , $ qaparams ) { global $ DB ; if ( $ s % 2 == 0 ) { $ limitoffset = $ s / 2 - 1 ; $ limit = 2 ; } else { $ limitoffset = floor ( $ s / 2 ) ; $ limit = 1 ; } $ sql = "SELECT quiza.id, quiza.sumgrades FROM $fromqa WHERE $whereqa ...
Median mark .
34,610
protected function sum_of_powers_of_difference_to_mean ( $ mean , $ fromqa , $ whereqa , $ qaparams ) { global $ DB ; $ sql = "SELECT SUM(POWER((quiza.sumgrades - $mean), 2)) AS power2, SUM(POWER((quiza.sumgrades - $mean), 3)) AS power3, SUM(POWER((quiza.sumgrade...
Fetch the sum of squared cubed and to the power 4 differences between sumgrade and it s mean .
34,611
public function get_image_size_in_draft_area ( $ draftitemid ) { global $ USER ; $ usercontext = context_user :: instance ( $ USER -> id ) ; $ fs = get_file_storage ( ) ; $ draftfiles = $ fs -> get_area_files ( $ usercontext -> id , 'user' , 'draft' , $ draftitemid , 'id' ) ; if ( $ draftfiles ) { foreach ( $ draftfile...
Gets the width and height of a draft image .
34,612
function buildPhotoURL ( $ photo , $ size = "Medium" ) { $ sizes = array ( "square" => "_s" , "thumbnail" => "_t" , "small" => "_m" , "medium" => "" , "large" => "_b" , "original" => "_o" ) ; $ size = strtolower ( $ size ) ; if ( ! array_key_exists ( $ size , $ sizes ) ) { $ size = "medium" ; } if ( $ size == "original...
These functions are front ends for the flickr calls
34,613
function groups_pools_add ( $ photo_id , $ group_id ) { $ this -> request ( "flickr.groups.pools.add" , array ( "photo_id" => $ photo_id , "group_id" => $ group_id ) , TRUE ) ; return $ this -> parsed_response ? true : false ; }
Groups Pools Methods
34,614
function photos_comments_addComment ( $ photo_id , $ comment_text ) { $ this -> request ( "flickr.photos.comments.addComment" , array ( "photo_id" => $ photo_id , "comment_text" => $ comment_text ) , TRUE ) ; return $ this -> parsed_response ? $ this -> parsed_response [ 'comment' ] : false ; }
Photos - Comments Methods
34,615
function photos_geo_getLocation ( $ photo_id ) { $ this -> request ( "flickr.photos.geo.getLocation" , array ( "photo_id" => $ photo_id ) ) ; return $ this -> parsed_response ? $ this -> parsed_response [ 'photo' ] : false ; }
Photos - Geo Methods
34,616
function photos_notes_add ( $ photo_id , $ note_x , $ note_y , $ note_w , $ note_h , $ note_text ) { $ this -> request ( "flickr.photos.notes.add" , array ( "photo_id" => $ photo_id , "note_x" => $ note_x , "note_y" => $ note_y , "note_w" => $ note_w , "note_h" => $ note_h , "note_text" => $ note_text ) , TRUE ) ; retu...
Photos - Notes Methods
34,617
function photos_transform_rotate ( $ photo_id , $ degrees ) { $ this -> request ( "flickr.photos.transform.rotate" , array ( "photo_id" => $ photo_id , "degrees" => $ degrees ) , TRUE ) ; return $ this -> parsed_response ? true : false ; }
Photos - Transform Methods
34,618
function photos_upload_checkTickets ( $ tickets ) { if ( is_array ( $ tickets ) ) { $ tickets = implode ( "," , $ tickets ) ; } $ this -> request ( "flickr.photos.upload.checkTickets" , array ( "tickets" => $ tickets ) , TRUE ) ; return $ this -> parsed_response ? $ this -> parsed_response [ 'uploader' ] [ 'ticket' ] :...
Photos - Upload Methods
34,619
function photosets_comments_addComment ( $ photoset_id , $ comment_text ) { $ this -> request ( "flickr.photosets.comments.addComment" , array ( "photoset_id" => $ photoset_id , "comment_text" => $ comment_text ) , TRUE ) ; return $ this -> parsed_response ? $ this -> parsed_response [ 'comment' ] : false ; }
Photosets Comments Methods
34,620
private function get_provide_event_action_num_params ( string $ modulename ) { $ functionname = 'mod_' . $ modulename . '_core_calendar_provide_event_action' ; $ reflection = new \ ReflectionFunction ( $ functionname ) ; return $ reflection -> getNumberOfParameters ( ) ; }
Returns the number of params declared in core_calendar_provide_event_action s implementation .
34,621
public function validation ( $ data , $ files ) { $ errors = parent :: validation ( $ data , $ files ) ; if ( $ this -> instance -> duedate && $ data [ 'extensionduedate' ] ) { if ( $ this -> instance -> duedate > $ data [ 'extensionduedate' ] ) { $ errors [ 'extensionduedate' ] = get_string ( 'extensionnotafterduedate...
Perform validation on the extension form
34,622
private static function lti_extract_parameters ( $ parameters ) { $ params = array ( ) ; foreach ( $ parameters as $ parameter ) { if ( isset ( $ parameter -> variable ) ) { $ value = '$' . $ parameter -> variable ; } else { $ value = $ parameter -> fixed ; if ( strlen ( $ value ) > 0 ) { $ first = substr ( $ value , 0...
Extracts the message parameters from the tool proxy entry
34,623
public function course_info_box ( stdClass $ course ) { $ content = '' ; $ content .= $ this -> output -> box_start ( 'generalbox info' ) ; $ chelper = new coursecat_helper ( ) ; $ chelper -> set_show_courses ( self :: COURSECAT_SHOW_COURSES_EXPANDED ) ; $ content .= $ this -> coursecat_coursebox ( $ chelper , $ course...
Renders course info box .
34,624
public function course_modchooser ( $ modules , $ course ) { if ( ! $ this -> page -> requires -> should_create_one_time_item_now ( 'core_course_modchooser' ) ) { return '' ; } $ modchooser = new \ core_course \ output \ modchooser ( $ course , $ modules ) ; return $ this -> render ( $ modchooser ) ; }
Build the HTML for the module chooser javascript popup
34,625
public function course_section_cm_edit_actions ( $ actions , cm_info $ mod = null , $ displayoptions = array ( ) ) { global $ CFG ; if ( empty ( $ actions ) ) { return '' ; } if ( isset ( $ displayoptions [ 'ownerselector' ] ) ) { $ ownerselector = $ displayoptions [ 'ownerselector' ] ; } else if ( $ mod ) { $ ownersel...
Renders HTML for displaying the sequence of course module editing buttons
34,626
public function course_search_form ( $ value = '' , $ format = 'plain' ) { static $ count = 0 ; $ formid = 'coursesearch' ; if ( ( ++ $ count ) > 1 ) { $ formid .= $ count ; } switch ( $ format ) { case 'navbar' : $ formid = 'coursesearchnavbar' ; $ inputid = 'navsearchbox' ; $ inputsize = 20 ; break ; case 'short' : $...
Renders html to display a course search form .
34,627
protected function is_cm_conditionally_hidden ( cm_info $ mod ) { global $ CFG ; $ conditionalhidden = false ; if ( ! empty ( $ CFG -> enableavailability ) ) { $ info = new \ core_availability \ info_module ( $ mod ) ; $ conditionalhidden = ! $ info -> is_available_for_all ( ) ; } return $ conditionalhidden ; }
Checks if course module has any conditions that may make it unavailable for all or some of the students
34,628
public function availability_info ( $ text , $ additionalclasses = '' ) { $ data = [ 'text' => $ text , 'classes' => $ additionalclasses ] ; $ additionalclasses = array_filter ( explode ( ' ' , $ additionalclasses ) ) ; if ( in_array ( 'ishidden' , $ additionalclasses ) ) { $ data [ 'ishidden' ] = 1 ; } else if ( in_ar...
Displays availability info for a course section or course module
34,629
public function course_section_cm_list_item ( $ course , & $ completioninfo , cm_info $ mod , $ sectionreturn , $ displayoptions = array ( ) ) { $ output = '' ; if ( $ modulehtml = $ this -> course_section_cm ( $ course , $ completioninfo , $ mod , $ sectionreturn , $ displayoptions ) ) { $ modclasses = 'activity ' . $...
Renders HTML to display one course module for display within a section .
34,630
public function course_section_cm ( $ course , & $ completioninfo , cm_info $ mod , $ sectionreturn , $ displayoptions = array ( ) ) { $ output = '' ; if ( ! $ mod -> is_visible_on_course_page ( ) ) { return $ output ; } $ indentclasses = 'mod-indent' ; if ( ! empty ( $ mod -> indent ) ) { $ indentclasses .= ' mod-inde...
Renders HTML to display one course module in a course section
34,631
public function course_section_cm_unavailable_error_message ( cm_info $ cm ) { if ( $ cm -> uservisible ) { return null ; } if ( ! $ cm -> availableinfo ) { return get_string ( 'activityiscurrentlyhidden' ) ; } $ altname = get_accesshide ( ' ' . $ cm -> modfullname ) ; $ name = html_writer :: empty_tag ( 'img' , array ...
Message displayed to the user when they try to access unavailable activity following URL
34,632
public function course_section_cm_list ( $ course , $ section , $ sectionreturn = null , $ displayoptions = array ( ) ) { global $ USER ; $ output = '' ; $ modinfo = get_fast_modinfo ( $ course ) ; if ( is_object ( $ section ) ) { $ section = $ modinfo -> get_section_info ( $ section -> section ) ; } else { $ section =...
Renders HTML to display a list of course modules in a course section Also displays move here controls in Javascript - disabled mode
34,633
public function courses_list ( $ courses , $ showcategoryname = false , $ additionalclasses = null , $ paginationurl = null , $ totalcount = null , $ page = 0 , $ perpage = null ) { global $ CFG ; $ chelper = new coursecat_helper ( ) ; if ( $ showcategoryname ) { $ chelper -> set_show_courses ( self :: COURSECAT_SHOW_C...
Displays a custom list of courses with paging bar if necessary
34,634
protected function coursecat_category_content ( coursecat_helper $ chelper , $ coursecat , $ depth ) { $ content = '' ; $ content .= $ this -> coursecat_subcategories ( $ chelper , $ coursecat , $ depth ) ; $ showcoursesauto = $ chelper -> get_show_courses ( ) == self :: COURSECAT_SHOW_COURSES_AUTO ; if ( $ showcourses...
Returns HTML to display the subcategories and courses in the given category
34,635
protected function coursecat_category ( coursecat_helper $ chelper , $ coursecat , $ depth ) { $ classes = array ( 'category' ) ; if ( empty ( $ coursecat -> visible ) ) { $ classes [ ] = 'dimmed_category' ; } if ( $ chelper -> get_subcat_depth ( ) > 0 && $ depth >= $ chelper -> get_subcat_depth ( ) ) { $ categoryconte...
Returns HTML to display a course category as a part of a tree
34,636
protected function coursecat_tree ( coursecat_helper $ chelper , $ coursecat ) { $ this -> categoryexpandedonload = false ; $ categorycontent = $ this -> coursecat_category_content ( $ chelper , $ coursecat , 0 ) ; if ( empty ( $ categorycontent ) ) { return '' ; } $ content = '' ; $ attributes = $ chelper -> get_and_e...
Returns HTML to display a tree of subcategories and courses in the given category
34,637
public function search_courses ( $ searchcriteria ) { global $ CFG ; $ content = '' ; if ( ! empty ( $ searchcriteria ) ) { $ displayoptions = array ( 'sort' => array ( 'displayname' => 1 ) ) ; $ perpage = optional_param ( 'perpage' , 0 , PARAM_RAW ) ; if ( $ perpage !== 'all' ) { $ displayoptions [ 'limit' ] = ( ( int...
Renders html to display search result page
34,638
public function tagged_courses ( $ tagid , $ exclusivemode = true , $ ctx = 0 , $ rec = true , $ displayoptions = null ) { global $ CFG ; if ( empty ( $ displayoptions ) ) { $ displayoptions = array ( ) ; } $ showcategories = ! core_course_category :: is_simple_site ( ) ; $ displayoptions += array ( 'limit' => $ CFG ->...
Renders html to print list of courses tagged with particular tag
34,639
protected function frontpage_remote_course ( stdClass $ course ) { $ url = new moodle_url ( '/auth/mnet/jump.php' , array ( 'hostid' => $ course -> hostid , 'wantsurl' => '/course/view.php?id=' . $ course -> remoteid ) ) ; $ output = '' ; $ output .= html_writer :: start_tag ( 'div' , array ( 'class' => 'coursebox remo...
Returns HTML to display one remote course
34,640
protected function frontpage_remote_host ( $ host ) { $ output = '' ; $ output .= html_writer :: start_tag ( 'div' , array ( 'class' => 'coursebox remotehost clearfix' ) ) ; $ output .= html_writer :: start_tag ( 'div' , array ( 'class' => 'info' ) ) ; $ output .= html_writer :: start_tag ( 'h3' , array ( 'class' => 'n...
Returns HTML to display one remote host
34,641
public function frontpage_my_courses ( ) { global $ USER , $ CFG , $ DB ; if ( ! isloggedin ( ) or isguestuser ( ) ) { return '' ; } $ output = '' ; $ courses = enrol_get_my_courses ( 'summary, summaryformat' ) ; $ rhosts = array ( ) ; $ rcourses = array ( ) ; if ( ! empty ( $ CFG -> mnet_dispatcher_mode ) && $ CFG -> ...
Returns HTML to print list of courses user is enrolled to for the frontpage
34,642
public function frontpage_available_courses ( ) { global $ CFG ; $ chelper = new coursecat_helper ( ) ; $ chelper -> set_show_courses ( self :: COURSECAT_SHOW_COURSES_EXPANDED ) -> set_courses_display_options ( array ( 'recursive' => true , 'limit' => $ CFG -> frontpagecourselimit , 'viewmoreurl' => new moodle_url ( '/...
Returns HTML to print list of available courses for the frontpage
34,643
public function add_new_course_button ( ) { global $ CFG ; $ output = $ this -> container_start ( 'buttons' ) ; $ url = new moodle_url ( '/course/edit.php' , array ( 'category' => $ CFG -> defaultrequestcategory , 'returnto' => 'topcat' ) ) ; $ output .= $ this -> single_button ( $ url , get_string ( 'addnewcourse' ) ,...
Returns HTML to the add new course button for the page
34,644
public function frontpage_combo_list ( ) { global $ CFG ; $ tree = core_course_category :: top ( ) ; if ( ! $ tree -> get_children_count ( ) ) { return '' ; } $ chelper = new coursecat_helper ( ) ; $ chelper -> set_subcat_depth ( $ CFG -> maxcategorydepth ) -> set_categories_display_options ( array ( 'limit' => $ CFG -...
Returns HTML to print tree with course categories and courses for the frontpage
34,645
public function render_activity_navigation ( \ core_course \ output \ activity_navigation $ page ) { $ data = $ page -> export_for_template ( $ this -> output ) ; return $ this -> output -> render_from_template ( 'core_course/activity_navigation' , $ data ) ; }
Renders the activity navigation .
34,646
public function publicationselector ( $ courseid ) { $ text = '' ; $ advertiseurl = new moodle_url ( "/course/publish/metadata.php" , array ( 'sesskey' => sesskey ( ) , 'id' => $ courseid , 'advertise' => true ) ) ; $ advertisebutton = new single_button ( $ advertiseurl , get_string ( 'advertise' , 'hub' ) ) ; $ text ....
Display the selector to advertise or publish a course
34,647
public function confirmunpublishing ( $ publication ) { $ optionsyes = array ( 'sesskey' => sesskey ( ) , 'id' => $ publication -> courseid , 'hubcourseid' => $ publication -> hubcourseid , 'cancel' => true , 'publicationid' => $ publication -> id , 'confirm' => true ) ; $ optionsno = array ( 'sesskey' => sesskey ( ) ,...
Display unpublishing confirmation page
34,648
public function sendingbackupinfo ( $ backupfile ) { $ sizeinfo = new stdClass ( ) ; $ sizeinfo -> total = number_format ( $ backupfile -> get_filesize ( ) / 1000000 , 2 ) ; $ html = html_writer :: tag ( 'div' , get_string ( 'sendingsize' , 'hub' , $ sizeinfo ) , array ( 'class' => 'courseuploadtextinfo' ) ) ; return $...
Display waiting information about backup size during uploading backup process
34,649
public function sentbackupinfo ( $ id ) { $ html = html_writer :: tag ( 'div' , get_string ( 'sent' , 'hub' ) , array ( 'class' => 'courseuploadtextinfo' ) ) ; $ publishindexurl = new moodle_url ( '/course/publish/index.php' , array ( 'sesskey' => sesskey ( ) , 'id' => $ id , 'published' => true ) ) ; $ continue = $ th...
Display upload successfull message and a button to the publish index page
34,650
public function set_courses_display_options ( $ options ) { $ this -> coursesdisplayoptions = $ options ; $ this -> set_show_courses ( $ this -> showcourses ) ; return $ this ; }
Sets options to display list of courses
34,651
public function get_courses_display_option ( $ optionname , $ defaultvalue = null ) { if ( array_key_exists ( $ optionname , $ this -> coursesdisplayoptions ) ) { return $ this -> coursesdisplayoptions [ $ optionname ] ; } else { return $ defaultvalue ; } }
Return the specified option to display list of courses
34,652
public function get_categories_display_option ( $ optionname , $ defaultvalue = null ) { if ( array_key_exists ( $ optionname , $ this -> categoriesdisplayoptions ) ) { return $ this -> categoriesdisplayoptions [ $ optionname ] ; } else { return $ defaultvalue ; } }
Return the specified option to display list of subcategories
34,653
public function get_and_erase_attributes ( $ classname ) { $ attributes = $ this -> attributes ; $ this -> attributes = array ( ) ; if ( empty ( $ attributes [ 'class' ] ) ) { $ attributes [ 'class' ] = '' ; } $ attributes [ 'class' ] = $ classname . ' ' . $ attributes [ 'class' ] ; return $ attributes ; }
Return all attributes and erases them so they are not applied again
34,654
public function get_category_formatted_description ( $ coursecat , $ options = null ) { if ( $ coursecat -> id && $ coursecat -> is_uservisible ( ) && ! empty ( $ coursecat -> description ) ) { if ( ! isset ( $ coursecat -> descriptionformat ) ) { $ descriptionformat = FORMAT_MOODLE ; } else { $ descriptionformat = $ c...
Returns formatted and filtered description of the given category
34,655
public function get_course_formatted_summary ( $ course , $ options = array ( ) ) { global $ CFG ; require_once ( $ CFG -> libdir . '/filelib.php' ) ; if ( ! $ course -> has_summary ( ) ) { return '' ; } $ options = ( array ) $ options ; $ context = context_course :: instance ( $ course -> id ) ; if ( ! isset ( $ optio...
Returns given course s summary with proper embedded files urls and formatted
34,656
public function get_course_formatted_name ( $ course , $ options = array ( ) ) { $ options = ( array ) $ options ; if ( ! isset ( $ options [ 'context' ] ) ) { $ options [ 'context' ] = context_course :: instance ( $ course -> id ) ; } $ name = format_string ( get_course_display_name_for_list ( $ course ) , true , $ op...
Returns course name as it is configured to appear in courses lists formatted to course context
34,657
public static function fields ( $ tableprefix = '' , array $ extrafields = NULL , $ idalias = 'id' , $ fieldprefix = '' ) { if ( ! $ tableprefix and ! $ extrafields and ! $ idalias ) { return implode ( ',' , self :: $ fields ) ; } if ( $ tableprefix ) { $ tableprefix .= '.' ; } foreach ( self :: $ fields as $ field ) {...
Returns a list of required user fields useful when fetching required user info from db .
34,658
public static function unalias ( stdClass $ record , array $ extrafields = null , $ idalias = 'id' , $ fieldprefix = '' ) { if ( empty ( $ idalias ) ) { $ idalias = 'id' ; } $ return = new stdClass ( ) ; foreach ( self :: $ fields as $ field ) { if ( $ field === 'id' ) { if ( property_exists ( $ record , $ idalias ) ) ...
Extract the aliased user fields from a given record
34,659
public function diag_strings ( ) { $ sm = get_string_manager ( ) ; if ( ! $ sm -> string_exists ( $ this -> identifier , $ this -> component ) ) { debugging ( "Help title string does not exist: [$this->identifier, $this->component]" ) ; } if ( ! $ sm -> string_exists ( $ this -> identifier . '_help' , $ this -> compone...
Verifies that both help strings exists shows debug warnings if not
34,660
public function export_for_pix ( ) { $ title = isset ( $ this -> attributes [ 'title' ] ) ? $ this -> attributes [ 'title' ] : '' ; if ( empty ( $ title ) ) { $ title = isset ( $ this -> attributes [ 'alt' ] ) ? $ this -> attributes [ 'alt' ] : '' ; } return [ 'key' => $ this -> pix , 'component' => $ this -> component...
Much simpler version of export that will produce the data required to render this pix with the pix helper in a mustache tag .
34,661
protected function clean_url ( $ value ) { global $ CFG ; if ( empty ( $ value ) ) { } else if ( strpos ( $ value , $ CFG -> wwwroot . '/' ) === 0 ) { $ value = str_replace ( $ CFG -> wwwroot , '' , $ value ) ; } else if ( strpos ( $ value , '/' ) !== 0 ) { debugging ( "Invalid url_select urls parameter: url '$value' i...
Clean a URL .
34,662
protected function flatten_options ( $ options , $ nothing ) { $ flattened = [ ] ; foreach ( $ options as $ value => $ option ) { if ( is_array ( $ option ) ) { foreach ( $ option as $ groupname => $ optoptions ) { if ( ! isset ( $ flattened [ $ groupname ] ) ) { $ flattened [ $ groupname ] = [ 'name' => $ groupname , ...
Flatten the options for Mustache .
34,663
public static function tag ( $ tagname , $ contents , array $ attributes = null ) { return self :: start_tag ( $ tagname , $ attributes ) . $ contents . self :: end_tag ( $ tagname ) ; }
Outputs a tag with attributes and contents
34,664
public static function nonempty_tag ( $ tagname , $ contents , array $ attributes = null ) { if ( $ contents === '' || is_null ( $ contents ) ) { return '' ; } return self :: tag ( $ tagname , $ contents , $ attributes ) ; }
Outputs a tag but only if the contents are not empty
34,665
public static function attribute ( $ name , $ value ) { if ( $ value instanceof moodle_url ) { return ' ' . $ name . '="' . $ value -> out ( ) . '"' ; } if ( $ value === null ) { return '' ; } return ' ' . $ name . '="' . s ( $ value ) . '"' ; }
Outputs a HTML attribute and value
34,666
public static function attributes ( array $ attributes = null ) { $ attributes = ( array ) $ attributes ; $ output = '' ; foreach ( $ attributes as $ name => $ value ) { $ output .= self :: attribute ( $ name , $ value ) ; } return $ output ; }
Outputs a list of HTML attributes and values
34,667
public static function img ( $ src , $ alt , array $ attributes = null ) { $ attributes = ( array ) $ attributes ; $ attributes [ 'src' ] = $ src ; $ attributes [ 'alt' ] = $ alt ; return self :: empty_tag ( 'img' , $ attributes ) ; }
Generates a simple image tag with attributes .
34,668
public static function random_id ( $ base = 'random' ) { static $ counter = 0 ; static $ uniq ; if ( ! isset ( $ uniq ) ) { $ uniq = uniqid ( ) ; } $ counter ++ ; return $ base . $ uniq . $ counter ; }
Generates random html element id .
34,669
public static function link ( $ url , $ text , array $ attributes = null ) { $ attributes = ( array ) $ attributes ; $ attributes [ 'href' ] = $ url ; return self :: tag ( 'a' , $ text , $ attributes ) ; }
Generates a simple html link
34,670
public static function checkbox ( $ name , $ value , $ checked = true , $ label = '' , array $ attributes = null ) { $ attributes = ( array ) $ attributes ; $ output = '' ; if ( $ label !== '' and ! is_null ( $ label ) ) { if ( empty ( $ attributes [ 'id' ] ) ) { $ attributes [ 'id' ] = self :: random_id ( 'checkbox_' ...
Generates a simple checkbox with optional label
34,671
public static function select ( array $ options , $ name , $ selected = '' , $ nothing = array ( '' => 'choosedots' ) , array $ attributes = null ) { $ attributes = ( array ) $ attributes ; if ( is_array ( $ nothing ) ) { foreach ( $ nothing as $ k => $ v ) { if ( $ v === 'choose' or $ v === 'choosedots' ) { $ nothing ...
Generates a simple select form field
34,672
private static function select_option ( $ label , $ value , array $ selected ) { $ attributes = array ( ) ; $ value = ( string ) $ value ; if ( in_array ( $ value , $ selected , true ) ) { $ attributes [ 'selected' ] = 'selected' ; } $ attributes [ 'value' ] = $ value ; return self :: tag ( 'option' , $ label , $ attri...
Returns HTML to display a select box option .
34,673
private static function select_optgroup ( $ groupname , $ options , array $ selected ) { if ( empty ( $ options ) ) { return '' ; } $ attributes = array ( 'label' => $ groupname ) ; $ output = '' ; foreach ( $ options as $ value => $ label ) { $ output .= self :: select_option ( $ label , $ value , $ selected ) ; } ret...
Returns HTML to display a select box option group .
34,674
public static function select_time ( $ type , $ name , $ currenttime = 0 , $ step = 5 , array $ attributes = null ) { global $ OUTPUT ; if ( ! $ currenttime ) { $ currenttime = time ( ) ; } $ calendartype = \ core_calendar \ type_factory :: get_calendar_instance ( ) ; $ currentdate = $ calendartype -> timestamp_to_date...
This is a shortcut for making an hour selector menu .
34,675
public static function alist ( array $ items , array $ attributes = null , $ tag = 'ul' ) { $ output = html_writer :: start_tag ( $ tag , $ attributes ) . "\n" ; foreach ( $ items as $ item ) { $ output .= html_writer :: tag ( 'li' , $ item ) . "\n" ; } $ output .= html_writer :: end_tag ( $ tag ) ; return $ output ; }
Shortcut for quick making of lists
34,676
public static function input_hidden_params ( moodle_url $ url , array $ exclude = null ) { $ exclude = ( array ) $ exclude ; $ params = $ url -> params ( ) ; foreach ( $ exclude as $ key ) { unset ( $ params [ $ key ] ) ; } $ output = '' ; foreach ( $ params as $ key => $ value ) { $ attributes = array ( 'type' => 'hid...
Returns hidden input fields created from url parameters .
34,677
public static function script ( $ jscode , $ url = null ) { if ( $ jscode ) { $ attributes = array ( 'type' => 'text/javascript' ) ; return self :: tag ( 'script' , "\n//<![CDATA[\n$jscode\n//]]>\n" , $ attributes ) . "\n" ; } else if ( $ url ) { $ attributes = array ( 'type' => 'text/javascript' , 'src' => $ url ) ; r...
Generate a script tag containing the the specified code .
34,678
public static function label ( $ text , $ for , $ colonize = true , array $ attributes = array ( ) ) { if ( ! is_null ( $ for ) ) { $ attributes = array_merge ( $ attributes , array ( 'for' => $ for ) ) ; } $ text = trim ( $ text ) ; $ label = self :: tag ( 'label' , $ text , $ attributes ) ; return $ label ; }
Renders form element label
34,679
private static function add_class ( $ class = '' , array $ attributes = null ) { if ( $ class !== '' ) { $ classattribute = array ( 'class' => $ class ) ; if ( $ attributes ) { if ( array_key_exists ( 'class' , $ attributes ) ) { $ attributes [ 'class' ] = trim ( $ attributes [ 'class' ] . ' ' . $ class ) ; } else { $ ...
Combines a class parameter with other attributes . Aids in code reduction because the class parameter is very frequently used .
34,680
public static function function_call ( $ function , array $ arguments = null , $ delay = 0 ) { if ( $ arguments ) { $ arguments = array_map ( 'json_encode' , convert_to_array ( $ arguments ) ) ; $ arguments = implode ( ', ' , $ arguments ) ; } else { $ arguments = '' ; } $ js = "$function($arguments);" ; if ( $ delay )...
Returns javascript code calling the function
34,681
public static function function_call_with_Y ( $ function , array $ extraarguments = null ) { if ( $ extraarguments ) { $ extraarguments = array_map ( 'json_encode' , convert_to_array ( $ extraarguments ) ) ; $ arguments = 'Y, ' . implode ( ', ' , $ extraarguments ) ; } else { $ arguments = 'Y' ; } return "$function($ar...
Special function which adds Y as first argument of function call .
34,682
public static function object_init ( $ var , $ class , array $ arguments = null , array $ requirements = null , $ delay = 0 ) { if ( is_array ( $ arguments ) ) { $ arguments = array_map ( 'json_encode' , convert_to_array ( $ arguments ) ) ; $ arguments = implode ( ', ' , $ arguments ) ; } if ( $ var === null ) { $ js =...
Returns JavaScript code to initialise a new object
34,683
public static function set_variable ( $ name , $ value , $ usevar = true ) { $ output = '' ; if ( $ usevar ) { if ( strpos ( $ name , '.' ) ) { $ output .= '' ; } else { $ output .= 'var ' ; } } $ output .= "$name = " . json_encode ( $ value ) . ";" ; return $ output ; }
Returns code setting value to variable
34,684
public static function event_handler ( $ selector , $ event , $ function , array $ arguments = null ) { $ selector = json_encode ( $ selector ) ; $ output = "Y.on('$event', $function, $selector, null" ; if ( ! empty ( $ arguments ) ) { $ output .= ', ' . json_encode ( $ arguments ) ; } return $ output . ");\n" ; }
Writes event handler attaching code
34,685
public function add ( $ text , moodle_url $ url = null , $ title = null , $ sort = null ) { $ key = count ( $ this -> children ) ; if ( empty ( $ sort ) ) { $ sort = $ this -> lastsort + 1 ; } $ this -> children [ $ key ] = new custom_menu_item ( $ text , $ url , $ title , $ sort , $ this ) ; $ this -> lastsort = ( int...
Adds a custom menu item as a child of this node given its properties .
34,686
public function remove_child ( custom_menu_item $ menuitem ) { $ removed = false ; if ( ( $ key = array_search ( $ menuitem , $ this -> children ) ) !== false ) { unset ( $ this -> children [ $ key ] ) ; $ this -> children = array_values ( $ this -> children ) ; $ removed = true ; } else { foreach ( $ this -> children ...
Removes a custom menu item that is a child or descendant to the current menu .
34,687
public static function convert_text_to_menu_nodes ( $ text , $ language = null ) { $ root = new custom_menu ( ) ; $ lastitem = $ root ; $ lastdepth = 0 ; $ hiddenitems = array ( ) ; $ lines = explode ( "\n" , $ text ) ; foreach ( $ lines as $ linenumber => $ line ) { $ line = trim ( $ line ) ; if ( strlen ( $ line ) ==...
Converts a string into a structured array of custom_menu_items which can then be added to a custom menu .
34,688
public static function sort_custom_menu_items ( custom_menu_item $ itema , custom_menu_item $ itemb ) { $ itema = $ itema -> get_sort_order ( ) ; $ itemb = $ itemb -> get_sort_order ( ) ; if ( $ itema == $ itemb ) { return 0 ; } return ( $ itema > $ itemb ) ? + 1 : - 1 ; }
Sorts two custom menu items
34,689
protected function set_selected ( $ selected ) { if ( ( string ) $ selected === ( string ) $ this -> id ) { $ this -> selected = true ; return true ; } foreach ( $ this -> subtree as $ subitem ) { if ( $ subitem -> set_selected ( $ selected ) ) { $ this -> activated = true ; return true ; } } return false ; }
Travels through tree and finds the tab to mark as selected all parents are automatically marked as activated
34,690
public function find ( $ id ) { if ( ( string ) $ this -> id === ( string ) $ id ) { return $ this ; } foreach ( $ this -> subtree as $ tab ) { if ( $ obj = $ tab -> find ( $ id ) ) { return $ obj ; } } return null ; }
Travels through tree and finds a tab with specified id
34,691
protected function set_level ( $ level ) { $ this -> level = $ level ; foreach ( $ this -> subtree as $ tab ) { $ tab -> set_level ( $ level + 1 ) ; } }
Allows to mark each tab s level in the tree before rendering .
34,692
protected function format_button_images ( ) { foreach ( $ this -> additionalbuttons as $ buttontype => $ button ) { $ page = $ button [ 'page' ] ; if ( ! isset ( $ button [ 'image' ] ) ) { $ this -> additionalbuttons [ $ buttontype ] [ 'formattedimage' ] = $ button [ 'title' ] ; } else { $ internalimage = $ page -> the...
Adds an array element for a formatted image .
34,693
public function initialise_js ( moodle_page $ page ) { static $ initialised = false ; if ( ! $ initialised ) { $ page -> requires -> yui_module ( 'moodle-core-actionmenu' , 'M.core.actionmenu.init' ) ; $ initialised = true ; } }
Initialises JS required fore the action menu . The JS is only required once as it manages all action menu s on the page .
34,694
public function add ( $ action ) { if ( $ action instanceof action_link ) { if ( $ action -> primary ) { $ this -> add_primary_action ( $ action ) ; } else { $ this -> add_secondary_action ( $ action ) ; } } else if ( $ action instanceof pix_icon ) { $ this -> add_primary_action ( $ action ) ; } else { $ this -> add_se...
Adds an action to this action menu .
34,695
public function add_primary_action ( $ action ) { if ( $ action instanceof action_link || $ action instanceof pix_icon ) { $ action -> attributes [ 'role' ] = 'menuitem' ; if ( $ action instanceof action_menu_link ) { $ action -> actionmenu = $ this ; } } $ this -> primaryactions [ ] = $ action ; }
Adds a primary action to the action menu .
34,696
public function add_secondary_action ( $ action ) { if ( $ action instanceof action_link || $ action instanceof pix_icon ) { $ action -> attributes [ 'role' ] = 'menuitem' ; if ( $ action instanceof action_menu_link ) { $ action -> actionmenu = $ this ; } } $ this -> secondaryactions [ ] = $ action ; }
Adds a secondary action to the action menu .
34,697
public function get_primary_actions ( core_renderer $ output = null ) { global $ OUTPUT ; if ( $ output === null ) { $ output = $ OUTPUT ; } $ pixicon = $ this -> actionicon ; $ linkclasses = array ( 'toggle-display' ) ; $ title = '' ; if ( ! empty ( $ this -> menutrigger ) ) { $ pixicon = '<b class="caret"></b>' ; $ l...
Returns the primary actions ready to be rendered .
34,698
public function set_alignment ( $ dialogue , $ button ) { if ( isset ( $ this -> attributessecondary [ 'data-align' ] ) ) { $ class = $ this -> attributessecondary [ 'class' ] ; $ search = 'align-' . $ this -> attributessecondary [ 'data-align' ] ; $ this -> attributessecondary [ 'class' ] = str_replace ( $ search , ''...
Sets the alignment of the dialogue in relation to button used to toggle it .
34,699
protected function get_align_string ( $ align ) { switch ( $ align ) { case self :: TL : return 'tl' ; case self :: TR : return 'tr' ; case self :: BL : return 'bl' ; case self :: BR : return 'br' ; default : return 'tl' ; } }
Returns a string to describe the alignment .