Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Protected Attributes | List of all members
coursecat_helper Class Reference

Class storing display options and functions to help display course category and/or courses lists. More...

Public Member Functions

 get_and_erase_attributes ($classname)
 Return all attributes and erases them so they are not applied again. More...
 
 get_categories_display_option ($optionname, $defaultvalue=null)
 Return the specified option to display list of subcategories. More...
 
 get_categories_display_options ()
 Returns all options to display list of subcategories. More...
 
 get_category_formatted_description ($coursecat, $options=null)
 Returns formatted and filtered description of the given category. More...
 
 get_course_formatted_name ($course, $options=array())
 Returns course name as it is configured to appear in courses lists formatted to course context. More...
 
 get_course_formatted_summary ($course, $options=array())
 Returns given course's summary with proper embedded files urls and formatted. More...
 
 get_courses_display_option ($optionname, $defaultvalue=null)
 Return the specified option to display list of courses. More...
 
 get_courses_display_options ()
 Returns all options to display the courses. More...
 
 get_show_courses ()
 Returns how (if) to show the courses - none, collapsed, expanded, etc. More...
 
 get_subcat_depth ()
 Returns the maximum depth to expand subcategories in the tree. More...
 
 set_attributes ($attributes)
 Sets additional general options to pass between renderer functions, usually HTML attributes. More...
 
 set_categories_display_options ($options)
 Sets options to display list of subcategories. More...
 
 set_courses_display_option ($key, $value)
 Sets one option to display list of courses. More...
 
 set_courses_display_options ($options)
 Sets options to display list of courses. More...
 
 set_search_criteria ($searchcriteria)
 Sets the search criteria if the course is a search result. More...
 
 set_show_courses ($showcourses)
 Sets how (if) to show the courses - none, collapsed, expanded, etc. More...
 
 set_subcat_depth ($subcatdepth)
 Sets the maximum depth to expand subcategories in the tree. More...
 

Protected Attributes

array $attributes = array()
 additional HTML attributes
 
array $categoriesdisplayoptions = array()
 options to display subcategories list
 
array $coursesdisplayoptions = array()
 options to display courses list
 
array $searchcriteria = null
 search criteria if the list is a search result
 
string $showcourses = 10
 [none, collapsed, expanded] how (if) display courses list
 
int $subcatdepth = 1
 depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name)
 

Detailed Description

Class storing display options and functions to help display course category and/or courses lists.

This is a wrapper for core_course_category objects that also stores display options and functions to retrieve sorted and paginated lists of categories/courses.

If theme overrides methods in core_course_renderers that access this class it may as well not use this class at all or extend it.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ get_and_erase_attributes()

coursecat_helper::get_and_erase_attributes (   $classname)

Return all attributes and erases them so they are not applied again.

Parameters
string$classnameadds additional class name to the beginning of $attributes['class']
Return values
array

◆ get_categories_display_option()

coursecat_helper::get_categories_display_option (   $optionname,
  $defaultvalue = null 
)

Return the specified option to display list of subcategories.

Parameters
string$optionnameoption name
mixed$defaultvaluedefault value for option if it is not specified
Return values
mixed

◆ get_categories_display_options()

coursecat_helper::get_categories_display_options ( )

Returns all options to display list of subcategories.

This array is usually passed to core_course_category::get_children()

Return values
array

◆ get_category_formatted_description()

coursecat_helper::get_category_formatted_description (   $coursecat,
  $options = null 
)

Returns formatted and filtered description of the given category.

Parameters
core_course_category$coursecatcategory
stdClass | array$optionsformat options, by default [noclean,overflowdiv], if context is not specified it will be added automatically
Return values
string|null

◆ get_course_formatted_name()

coursecat_helper::get_course_formatted_name (   $course,
  $options = array() 
)

Returns course name as it is configured to appear in courses lists formatted to course context.

Parameters
core_course_list_element$course
array | stdClass$optionsadditional formatting options
Return values
string

◆ get_course_formatted_summary()

coursecat_helper::get_course_formatted_summary (   $course,
  $options = array() 
)

Returns given course's summary with proper embedded files urls and formatted.

Parameters
core_course_list_element$course
array | stdClass$optionsadditional formatting options
Return values
string

◆ get_courses_display_option()

coursecat_helper::get_courses_display_option (   $optionname,
  $defaultvalue = null 
)

Return the specified option to display list of courses.

Parameters
string$optionnameoption name
mixed$defaultvaluedefault value for option if it is not specified
Return values
mixed

◆ get_courses_display_options()

coursecat_helper::get_courses_display_options ( )

Returns all options to display the courses.

This array is usually passed to core_course_category::get_courses() or core_course_category::search_courses()

Return values
array

◆ get_show_courses()

coursecat_helper::get_show_courses ( )

Returns how (if) to show the courses - none, collapsed, expanded, etc.

Return values
int- COURSECAT_SHOW_COURSES_NONE, COURSECAT_SHOW_COURSES_COLLAPSED, COURSECAT_SHOW_COURSES_EXPANDED, etc.

◆ get_subcat_depth()

coursecat_helper::get_subcat_depth ( )

Returns the maximum depth to expand subcategories in the tree.

deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name

Return values
int

◆ set_attributes()

coursecat_helper::set_attributes (   $attributes)

Sets additional general options to pass between renderer functions, usually HTML attributes.

Parameters
array$attributes
Return values
coursecat_helper

◆ set_categories_display_options()

coursecat_helper::set_categories_display_options (   $options)

Sets options to display list of subcategories.

Options 'sort', 'offset' and 'limit' are passed to core_course_category::get_children(). Any other options may be used by renderer functions

Parameters
array$options
Return values
coursecat_helper

◆ set_courses_display_option()

coursecat_helper::set_courses_display_option (   $key,
  $value 
)

Sets one option to display list of courses.

See also
coursecat_helper::set_courses_display_options()
Parameters
string$key
mixed$value
Return values
coursecat_helper

◆ set_courses_display_options()

coursecat_helper::set_courses_display_options (   $options)

Sets options to display list of courses.

Options are later submitted as argument to core_course_category::get_courses() and/or core_course_category::search_courses()

Options that core_course_category::get_courses() accept:

  • recursive - return courses from subcategories as well. Use with care, this may be a huge list!
  • summary - preloads fields 'summary' and 'summaryformat'
  • coursecontacts - preloads course contacts
  • customfields - preloads custom fields data
  • isenrolled - preloads indication whether this user is enrolled in the course
  • sort - list of fields to sort. Example array('idnumber' => 1, 'shortname' => 1, 'id' => -1) will sort by idnumber asc, shortname asc and id desc. Default: array('sortorder' => 1) Only cached fields may be used for sorting!
  • offset
  • limit - maximum number of children to return, 0 or null for no limit

Options summary and coursecontacts are filled automatically in the set_show_courses()

Also renderer can set here any additional options it wants to pass between renderer functions.

Parameters
array$options
Return values
coursecat_helper

◆ set_search_criteria()

coursecat_helper::set_search_criteria (   $searchcriteria)

Sets the search criteria if the course is a search result.

Search string will be used to highlight terms in course name and description

Parameters
array$searchcriteria
Return values
coursecat_helper

◆ set_show_courses()

coursecat_helper::set_show_courses (   $showcourses)

Sets how (if) to show the courses - none, collapsed, expanded, etc.

Parameters
int$showcoursesSHOW_COURSES_NONE, SHOW_COURSES_COLLAPSED, SHOW_COURSES_EXPANDED, etc.
Return values
coursecat_helper

◆ set_subcat_depth()

coursecat_helper::set_subcat_depth (   $subcatdepth)

Sets the maximum depth to expand subcategories in the tree.

deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name

Parameters
int$subcatdepth
Return values
coursecat_helper

The documentation for this class was generated from the following file: