Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cm_info Class Reference
Inheritance diagram for cm_info:

Public Member Functions

 __construct (course_modinfo $modinfo, $notused1, $mod, $notused2)
 Constructor should not be called directly; use get_fast_modinfo(). More...
 
 __call ($name, $arguments)
 Magic method to call functions that are now declared as private but were public in Moodle before 2.6. More...
 
 __empty ($name)
 Magic method for function empty() More...
 
 __get ($name)
 Magic method getter. More...
 
 __isset ($name)
 Magic method for function isset() More...
 
 __set ($name, $value)
 Magic method setter. More...
 
 get_course ()
 Returns course object that was used in the first get_fast_modinfo() call. More...
 
 get_course_module_record ($additionalfields=false)
 Returns itself in the form of stdClass. More...
 
 get_formatted_content ($options=array())
 Returns the content to display on course/overview page, formatted and passed through filters. More...
 
 get_formatted_name ($options=array())
 Returns the name to display on course/overview page, formatted and passed through filters. More...
 
 get_grouping_label ($textclasses='')
 
 get_icon_url ($output=null)
 
 get_modinfo ()
 
 get_module_type_name ($plural=false)
 Returns a localised human-readable name of the module type. More...
 
 get_section_info ()
 Returns the section this module belongs to. More...
 
 getIterator ()
 Implementation of IteratorAggregate::getIterator(), allows to cycle through properties and use convert_to_array(). More...
 
 has_view ()
 
 is_stealth ()
 Whether this module is available but hidden from course page. More...
 
 is_user_access_restricted_by_capability ()
 Checks whether mod/...:view capability restricts the current user's access. More...
 
 is_user_access_restricted_by_conditional_access ()
 Checks whether the module's conditional access settings mean that the user cannot see the activity at all. More...
 
 is_user_access_restricted_by_group ()
 This method has been deprecated and should not be used. More...
 
 is_visible_on_course_page ()
 Returns whether this module is visible to the current user on course page. More...
 
 set_after_edit_icons ($afterediticons)
 Sets HTML that displays after edit icons on course view page. More...
 
 set_after_link ($afterlink)
 Sets HTML that displays after link on course view page. More...
 
 set_available ($available, $showavailability=0, $availableinfo='')
 Sets the 'available' flag and related details. More...
 
 set_content ($content, $isformatted=false)
 Sets content to display on course view page below link (if present). More...
 
 set_extra_classes ($extraclasses)
 Sets extra classes to include in CSS. More...
 
 set_icon_url (moodle_url $iconurl)
 Sets the external full url that points to the icon being used by the activity. More...
 
 set_name ($name)
 Changes the name (text of link) for this module instance. More...
 
 set_no_view_link ()
 Turns off the view link for this module instance. More...
 
 set_on_click ($onclick)
 Sets value of on-click attribute for JavaScript. More...
 
 set_user_visible ($uservisible)
 Sets the 'uservisible' flag. More...
 

Static Public Member Functions

static create ($cm, $userid=0)
 Creates a cm_info object from a database record (also accepts cm_info in which case it is just returned unchanged). More...
 

Public Attributes

const STATE_BASIC = 0
 State: Only basic data from modinfo cache is available.
 
const STATE_BUILDING_DYNAMIC = 1
 State: In the process of building dynamic data (to avoid recursive calls to obtain_dynamic_data())
 
const STATE_BUILDING_VIEW = 3
 State: In the process of building view data (to avoid recursive calls to obtain_view_data())
 
const STATE_DYNAMIC = 2
 State: Dynamic data is available too.
 
const STATE_VIEW = 4
 State: View data (for course page) is available.
 

Constructor & Destructor Documentation

◆ __construct()

cm_info::__construct ( course_modinfo  $modinfo,
  $notused1,
  $mod,
  $notused2 
)

Constructor should not be called directly; use get_fast_modinfo().

Parameters
course_modinfo$modinfoParent object
stdClass$notused1Argument not used
stdClass$modModule object from the modinfo field of course table
stdClass$notused2Argument not used

Member Function Documentation

◆ __call()

cm_info::__call (   $name,
  $arguments 
)

Magic method to call functions that are now declared as private but were public in Moodle before 2.6.

These private methods can not be used anymore.

Parameters
string$name
array$arguments
Return values
mixed
Exceptions
coding_exception

◆ __empty()

cm_info::__empty (   $name)

Magic method for function empty()

Parameters
string$name
Return values
bool

◆ __get()

cm_info::__get (   $name)

Magic method getter.

Parameters
string$name
Return values
mixed

◆ __isset()

cm_info::__isset (   $name)

Magic method for function isset()

Parameters
string$name
Return values
bool

◆ __set()

cm_info::__set (   $name,
  $value 
)

Magic method setter.

Will display the developer warning when trying to set/overwrite property.

Parameters
string$name
mixed$value

◆ create()

static cm_info::create (   $cm,
  $userid = 0 
)
static

Creates a cm_info object from a database record (also accepts cm_info in which case it is just returned unchanged).

Parameters
stdClass | cm_info | null | bool$cmStdclass or cm_info (or null or false)
int$useridOptional userid (default to current)
Return values
cm_info|nullObject as cm_info, or null if input was null/false

◆ get_course()

cm_info::get_course ( )

Returns course object that was used in the first get_fast_modinfo() call.

It may not contain all fields from DB table {course} but always has at least the following: id,shortname,fullname,format,enablecompletion,groupmode,groupmodeforce,cacherev

If the course object lacks the field you need you can use the global function get_course() that will save extra query if you access current course or frontpage course.

Return values
stdClass

◆ get_course_module_record()

cm_info::get_course_module_record (   $additionalfields = false)

Returns itself in the form of stdClass.

The object includes all fields that table course_modules has and additionally fields 'name', 'modname', 'sectionnum' (if requested).

This can be used as a faster alternative to get_coursemodule_from_id()

Parameters
bool$additionalfieldsinclude additional fields 'name', 'modname', 'sectionnum'
Return values
stdClass

◆ get_formatted_content()

cm_info::get_formatted_content (   $options = array())

Returns the content to display on course/overview page, formatted and passed through filters.

if $options['context'] is not specified, the module context is used

Parameters
array | stdClass$optionsformatting options, see format_text()
Return values
string

◆ get_formatted_name()

cm_info::get_formatted_name (   $options = array())

Returns the name to display on course/overview page, formatted and passed through filters.

if $options['context'] is not specified, the module context is used

Parameters
array | stdClass$optionsformatting options, see format_string()
Return values
string

◆ get_grouping_label()

cm_info::get_grouping_label (   $textclasses = '')
Parameters
string$textclassesadditionnal classes for grouping label
Return values
stringAn empty string or HTML grouping label span tag

◆ get_icon_url()

cm_info::get_icon_url (   $output = null)
Parameters
moodle_core_renderer$outputOutput render to use, or null for default (global)
Return values
moodle_urlIcon URL for a suitable icon to put beside this cm

◆ get_modinfo()

cm_info::get_modinfo ( )
Return values
course_modinfoModinfo object that this came from

◆ get_module_type_name()

cm_info::get_module_type_name (   $plural = false)

Returns a localised human-readable name of the module type.

Parameters
bool$pluralreturn plural form
Return values
string

◆ get_section_info()

cm_info::get_section_info ( )

Returns the section this module belongs to.

Return values
section_info

◆ getIterator()

cm_info::getIterator ( )

Implementation of IteratorAggregate::getIterator(), allows to cycle through properties and use convert_to_array().

Return values
ArrayIterator

◆ has_view()

cm_info::has_view ( )
Return values
boolTrue if this module has a 'view' page that should be linked to in navigation etc (note: modules may still have a view.php file, but return false if this is not intended to be linked to from 'normal' parts of the interface; this is what label does).

◆ is_stealth()

cm_info::is_stealth ( )

Whether this module is available but hidden from course page.

"Stealth" modules are the ones that are not shown on course page but available by following url. They are normally also displayed in grade reports and other reports. Module will be stealth either if visibleoncoursepage=0 or it is a visible module inside the hidden section.

Return values
bool

◆ is_user_access_restricted_by_capability()

cm_info::is_user_access_restricted_by_capability ( )

Checks whether mod/...:view capability restricts the current user's access.

Return values
boolTrue if the user access is restricted.

◆ is_user_access_restricted_by_conditional_access()

cm_info::is_user_access_restricted_by_conditional_access ( )

Checks whether the module's conditional access settings mean that the user cannot see the activity at all.

Deprecated:
since 2.7 MDL-44070

◆ is_user_access_restricted_by_group()

cm_info::is_user_access_restricted_by_group ( )

This method has been deprecated and should not be used.

See also
$uservisible
Deprecated:
Since Moodle 2.8

◆ is_visible_on_course_page()

cm_info::is_visible_on_course_page ( )

Returns whether this module is visible to the current user on course page.

Activity may be visible on the course page but not available, for example when it is hidden conditionally but the condition information is displayed.

Return values
bool

◆ set_after_edit_icons()

cm_info::set_after_edit_icons (   $afterediticons)

Sets HTML that displays after edit icons on course view page.

Parameters
string$afterediticonsHTML string (empty string if none)
Return values
void

◆ set_after_link()

cm_info::set_after_link (   $afterlink)

Sets HTML that displays after link on course view page.

Parameters
string$afterlinkHTML string (empty string if none)
Return values
void

◆ set_available()

cm_info::set_available (   $available,
  $showavailability = 0,
  $availableinfo = '' 
)

Sets the 'available' flag and related details.

This flag is normally used to make course modules unavailable until a certain date or condition is met. (When a course module is unavailable, it is still visible to users who have viewhiddenactivities permission.)

When this is function is called, user-visible status is recalculated automatically.

The $showavailability flag does not really do anything any more, but is retained for backward compatibility. Setting this to false will cause $availableinfo to be ignored.

Note: May not be called from _cm_info_view (only _cm_info_dynamic).

Parameters
bool$availableFalse if this item is not 'available'
int$showavailability0 = do not show this item at all if it's not available, 1 = show this item greyed out with the following message
string$availableinfoInformation about why this is not available, or empty string if not displaying
Return values
void

◆ set_content()

cm_info::set_content (   $content,
  $isformatted = false 
)

Sets content to display on course view page below link (if present).

Parameters
string$contentNew content as HTML string (empty string if none)
bool$isformattedWhether user content is already passed through format_text/format_string and should not be formatted again. This can be useful when module adds interactive elements on top of formatted user text.
Return values
void

◆ set_extra_classes()

cm_info::set_extra_classes (   $extraclasses)

Sets extra classes to include in CSS.

Parameters
string$extraclassesExtra classes (empty string if none)
Return values
void

◆ set_icon_url()

cm_info::set_icon_url ( moodle_url  $iconurl)

Sets the external full url that points to the icon being used by the activity.

Useful for external-tool modules (lti...) If set, takes precedence over $icon and $iconcomponent

Parameters
moodle_url$iconurlfull external url pointing to icon image for activity
Return values
void

◆ set_name()

cm_info::set_name (   $name)

Changes the name (text of link) for this module instance.

Note: May not be called from _cm_info_view (only _cm_info_dynamic).

Parameters
string$nameName of activity / link text
Return values
void

◆ set_no_view_link()

cm_info::set_no_view_link ( )

Turns off the view link for this module instance.

Note: May not be called from _cm_info_view (only _cm_info_dynamic).

Return values
void

◆ set_on_click()

cm_info::set_on_click (   $onclick)

Sets value of on-click attribute for JavaScript.

Note: May not be called from _cm_info_view (only _cm_info_dynamic).

Parameters
string$onclickNew onclick attribute which should be HTML-escaped (empty string if none)
Return values
void

◆ set_user_visible()

cm_info::set_user_visible (   $uservisible)

Sets the 'uservisible' flag.

This can be used (by setting false) to prevent access and display of this module link for the current user. Note: May not be called from _cm_info_view (only _cm_info_dynamic).

Parameters
bool$uservisible
Return values
void

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