Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 402 and 403]

Library of workshop module functions needed by Moodle core and other subsystems All the functions neeeded by Moodle core, gradebook, file subsystem etc are placed here.

Copyright: 2009 David Mudrak <david.mudrak@gmail.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 2282 lines (99 kb)
Included or required: 8 times
Referenced: 4 times
Includes or requires: 2 files
 mod/workshop/lib.php
 mod/workshop/locallib.php

Defines 35 functions


Functions that are not part of a class:

workshop_supports($feature)   X-Ref
Returns the information if the module supports a feature

param: string $feature FEATURE_xx constant for requested feature
return: mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.

workshop_add_instance(stdclass $workshop)   X-Ref
Saves a new instance of the workshop into the database

Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will save a new instance and return the id number
of the new instance.

param: stdClass $workshop An object from the form in mod_form.php
return: int The id of the newly inserted workshop record

workshop_update_instance(stdclass $workshop)   X-Ref
Given an object containing all the necessary data,
(defined by the form in mod_form.php) this function
will update an existing instance with new data.

param: stdClass $workshop An object from the form in mod_form.php
return: bool success

workshop_delete_instance($id)   X-Ref
Given an ID of an instance of this module,
this function will permanently delete the instance
and any data that depends on it.

param: int $id Id of the module instance
return: boolean Success/Failure

workshop_refresh_events($courseid = 0, $instance = null, $cm = null)   X-Ref
This standard function will check all instances of this module
and make sure there are up-to-date events created for each of them.
If courseid = 0, then every workshop event in the site is checked, else
only workshop events belonging to the course specified are checked.

param: integer $courseid The Course ID.
param: int|stdClass $instance workshop module instance or ID.
param: int|stdClass $cm Course module object or ID.
return: bool Returns true if the calendar events were successfully updated.

workshop_get_view_actions()   X-Ref
List the actions that correspond to a view of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = 'r' and edulevel = LEVEL_PARTICIPATING will
be considered as view action.

return: array

workshop_get_post_actions()   X-Ref
List the actions that correspond to a post of this module.
This is used by the participation report.

Note: This is not used by new logging system. Event with
crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
will be considered as post action.

return: array

workshop_user_outline($course, $user, $mod, $workshop)   X-Ref
Return a small object with summary information about what a
user has done with a given particular instance of this module
Used for user activity reports.
$return->time = the time they did it
$return->info = a short text description

param: stdClass $course The course record.
param: stdClass $user The user record.
param: cm_info|stdClass $mod The course module info object or record.
param: stdClass $workshop The workshop instance record.
return: stdclass|null

workshop_user_complete($course, $user, $mod, $workshop)   X-Ref
Print a detailed representation of what a user has done with
a given particular instance of this module, for user activity reports.

param: stdClass $course The course record.
param: stdClass $user The user record.
param: cm_info|stdClass $mod The course module info object or record.
param: stdClass $workshop The workshop instance record.
return: string HTML

workshop_print_recent_activity($course, $viewfullnames, $timestart)   X-Ref
Given a course and a time, this module should find recent activity
that has occurred in workshop activities and print it out.
Return true if there was output, or false is there was none.

param: stdClass $course
param: bool $viewfullnames
param: int $timestart
return: boolean

workshop_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0)   X-Ref
Returns all activity in course workshops since a given time

param: array $activities sequentially indexed array of objects
param: int $index
param: int $timestart
param: int $courseid
param: int $cmid
param: int $userid defaults to 0
param: int $groupid defaults to 0
return: void adds items into $activities and increases $index

workshop_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames)   X-Ref
Print single activity item prepared by {@see workshop_get_recent_mod_activity()}


workshop_scale_used()   X-Ref


workshop_scale_used_anywhere($scaleid)   X-Ref
Is a given scale used by any instance of workshop?

The function asks all installed grading strategy subplugins. The workshop
core itself does not use scales. Both grade for submission and grade for
assessments do not use scales.

param: int $scaleid id of the scale to check
return: bool

workshop_grade_item_update(stdclass $workshop, $submissiongrades=null, $assessmentgrades=null)   X-Ref
Creates or updates grade items for the give workshop instance

Needed by grade_update_mod_grades() in lib/gradelib.php. Also used by
{@link workshop_update_grades()}.

param: stdClass $workshop instance object with extra cmidnumber property
param: stdClass $submissiongrades data for the first grade item
param: stdClass $assessmentgrades data for the second grade item
return: void

workshop_update_grades(stdclass $workshop, $userid=0)   X-Ref
Update workshop grades in the gradebook

Needed by grade_update_mod_grades() in lib/gradelib.php

param: stdClass $workshop instance object with extra cmidnumber and modname property
param: int $userid        update grade of specific user only, 0 means all participants
return: void

workshop_grade_item_category_update($workshop)   X-Ref
Update the grade items categories if they are changed via mod_form.php

We must do it manually here in the workshop module because modedit supports only
single grade item while we use two.

param: stdClass $workshop An object from the form in mod_form.php

workshop_get_file_areas($course, $cm, $context)   X-Ref
Returns the lists of all browsable file areas within the given module context

The file area workshop_intro for the activity introduction field is added automatically
by {@link file_browser::get_file_info_context_module()}

param: stdClass $course
param: stdClass $cm
param: stdClass $context
return: array of [(string)filearea] => (string)description

workshop_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()   X-Ref
Serves the files from the workshop file areas

Apart from module intro (handled by pluginfile.php automatically), workshop files may be
media inserted into submission content (like images) and submission attachments. For these two,
the fileareas submission_content and submission_attachment are used.
Besides that, areas instructauthors, instructreviewers and conclusion contain the media
embedded using the mod_form.php.

param: stdClass $course the course object
param: stdClass $cm the course module object
param: stdClass $context the workshop's context
param: string $filearea the name of the file area
param: array $args extra arguments (itemid, path)
param: bool $forcedownload whether or not force download
param: array $options additional options affecting the file serving
return: bool false if the file not found, just send the file otherwise and do not return anything

workshop_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)   X-Ref
File browsing support for workshop file areas

param: file_browser $browser
param: array $areas
param: stdClass $course
param: stdClass $cm
param: stdClass $context
param: string $filearea
param: int $itemid
param: string $filepath
param: string $filename
return: file_info instance or null if not found

workshop_extend_navigation(navigation_node $navref, stdclass $course, stdclass $module, cm_info $cm)   X-Ref
Extends the global navigation tree by adding workshop nodes if there is a relevant content

This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.

param: navigation_node $navref An object representing the navigation tree node of the workshop module instance
param: stdClass $course
param: stdClass $module
param: cm_info $cm

workshop_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $workshopnode=null)   X-Ref
Extends the settings navigation with the Workshop settings
This function is called when the context for the page is a workshop module. This is not called by AJAX
so it is safe to rely on the $PAGE.

param: settings_navigation $settingsnav {@link settings_navigation}
param: navigation_node $workshopnode {@link navigation_node}

workshop_page_type_list($pagetype, $parentcontext, $currentcontext)   X-Ref
Return a list of page types

param: string $pagetype current page type
param: stdClass $parentcontext Block's parent context
param: stdClass $currentcontext Current context of block

workshop_calendar_update(stdClass $workshop, $cmid)   X-Ref
Updates the calendar events associated to the given workshop

param: stdClass $workshop the workshop instance record
param: int $cmid course module id

mod_workshop_core_calendar_provide_event_action(calendar_event $event,\core_calendar\action_factory $factory, int $userid = 0)   X-Ref
This function receives a calendar event and returns the action associated with it, or null if there is none.

This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
is not displayed on the block.

param: calendar_event $event
param: \core_calendar\action_factory $factory
param: int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
return: \core_calendar\local\event\entities\action_interface|null

mod_workshop_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $workshop)   X-Ref
This function calculates the minimum and maximum cutoff values for the timestart of
the given event.

It will return an array with two values, the first being the minimum cutoff value and
the second being the maximum cutoff value. Either or both values can be null, which
indicates there is no minimum or maximum, respectively.

If a cutoff is required then the function must return an array containing the cutoff
timestamp and error string to display to the user if the cutoff value is violated.

A minimum and maximum cutoff return value will look like:
[
[1505704373, 'The date must be after this date'],
[1506741172, 'The date must be before this date']
]

param: calendar_event $event The calendar event to get the time range for
param: stdClass $workshop The module instance to get the range from
return: array Returns an array with min and max date.

mod_workshop_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $workshop)   X-Ref
This function will update the workshop module according to the
event that has been modified.

param: \calendar_event $event
param: stdClass $workshop The module instance to get the range from

workshop_reset_course_form_definition($mform)   X-Ref
Extends the course reset form with workshop specific settings.

param: MoodleQuickForm $mform

workshop_reset_course_form_defaults(stdClass $course)   X-Ref
Provides default values for the workshop settings in the course reset form.

param: stdClass $course The course to be reset.

workshop_reset_userdata(stdClass $data)   X-Ref
Performs the reset of all workshop instances in the course.

param: stdClass $data The actual course reset settings.
return: array List of results, each being array[(string)component, (string)item, (string)error]

mod_workshop_get_fontawesome_icon_map()   X-Ref
Get icon mapping for font-awesome.


workshop_check_updates_since(cm_info $cm, $from, $filter = array()   X-Ref
Check if the module has any update that affects the current user since a given time.

param: cm_info $cm course module data
param: int $from the time to check updates from
param: array $filter  if we need to check only specific updates
return: stdClass an object with the different type of areas indicating if they were updated or not

mod_workshop_get_path_from_pluginfile(string $filearea, array $args)   X-Ref
Given an array with a file path, it returns the itemid and the filepath for the defined filearea.

param: string $filearea The filearea.
param: array  $args The path (the part after the filearea and before the filename).
return: array|null The itemid and the filepath inside the $args path, for the defined filearea.

workshop_get_coursemodule_info($coursemodule)   X-Ref
Add a get_coursemodule_info function in case any feedback type wants to add 'extra' information
for the course (see resource).

Given a course_module object, this function returns any "extra" information that may be needed
when printing this activity in a course listing.  See get_array_of_activities() in course/lib.php.

param: stdClass $coursemodule The coursemodule object (record).
return: cached_cm_info|false An object on information that the courses will know about (most noticeably, an icon).

mod_workshop_core_calendar_get_event_action_string($eventtype)   X-Ref
Callback to fetch the activity event type lang string.

param: string $eventtype The event type.
return: lang_string The event type lang string.