Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
mod_chat

Namespaces

namespace  mod_chat
  
 
namespace  mod_chat\analytics\indicator
  
 
namespace  mod_chat\event
  
 
namespace  mod_chat\external
  
 
namespace  mod_chat\privacy
  
 
namespace  mod_chat\search
  
 
namespace  mod_chat\task
  
 

Classes

class  backup_chat_activity_structure_step
 Define all the backup steps that will be used by the backup_chat_activity_task. More...
 
class  backup_chat_activity_task
 Provides the steps to perform one complete backup of the Chat instance. More...
 
class  behat_mod_chat
 Steps definitions related to mod_chat. More...
 
class  chat_portfolio_caller
 
class  event_message
 A chat event such a user entering or leaving a chat activity. More...
 
class  mod_chat\analytics\indicator\activity_base
 Activity base class. More...
 
class  mod_chat\analytics\indicator\cognitive_depth
 Cognitive depth indicator - chat. More...
 
class  mod_chat\analytics\indicator\social_breadth
 Social breadth indicator - chat. More...
 
class  mod_chat\dates
 Class for fetching the important dates in mod_chat for a given module instance and a user. More...
 
class  mod_chat\event\course_module_instance_list_viewed
 The mod_chat instance list viewed event class. More...
 
class  mod_chat\event\course_module_viewed
 The mod_chat course module viewed event class. More...
 
class  mod_chat\event\sessions_viewed
 
class  mod_chat\external\chat_message_exporter
 Class for exporting a chat message. More...
 
class  mod_chat\external\view_sessions
 
class  mod_chat\privacy\provider
 Data provider class. More...
 
class  mod_chat\search\activity
 Search area for mod_chat activities. More...
 
class  mod_chat\task\cron_task
 The main schedule task for the chat module. More...
 
class  mod_chat_external
 Chat external functions. More...
 
class  mod_chat_renderer
 Chat module renderer class. More...
 
class  moodle1_mod_chat_handler
 Chat conversion handler. More...
 
class  restore_chat_activity_structure_step
 Define all the restore steps that will be used by the restore_chat_activity_task. More...
 
class  restore_chat_activity_task
 chat restore task that provides all the settings and steps to perform one complete restore of the activity More...
 
class  user_message
 A chat message from a user. More...
 

Functions

object chat_add_instance ($chat)
 Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will create a new instance and return the id number of the new instance.
 
 chat_calculate_next_chat_time (int $schedule, int $chattime)
 Calculate next chat session time based on schedule.
 
object chat_delete_instance ($id)
 Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.
 
object chat_delete_old_users ()
 Delete the old and in the way.
 
 chat_extend_navigation ($navigation, $course, $module, $cm)
 
 chat_extend_settings_navigation (settings_navigation $settings, navigation_node $chatnode)
 Adds module specific settings to the settings block.
 
object chat_format_message ($message, $courseid, $currentuser, $chatlastrow=null)
 Given a message object this function formats it appropriately into text and html then returns the formatted data.
 
object chat_format_message_manually ($message, $courseid, $sender, $currentuser, $chatlastrow=null)
 @global object
 
object chat_format_message_theme ($message, $chatuser, $currentuser, $groupingid, $theme='bubble')
 
object chat_format_userlist ($users, $course)
 $DB @global object $CFG @global object $COURSE @global object $OUTPUT
 
 chat_get_coursemodule_info ($coursemodule)
 Add a get_coursemodule_info function in case chat instance wants to add 'extra' information for the course (see resource).
 
object chat_get_latest_message ($chatid, $groupid=0)
 
 chat_get_latest_messages ($chatuser, $chatlasttime)
 Return a list of the latest messages in the given chat session.
 
 chat_get_post_actions ()
 List the actions that correspond to a post of this module.
 
 chat_get_session_messages ($chatid, $group=false, $start=0, $end=0, $sort='')
 Return the messages of the given chat session.
 
 chat_get_sessions ($messages, $showall=false)
 Given a set of messages for a chat, return the completed chat sessions (including optionally not completed ones).
 
object chat_get_users ($chatid, $groupid=0, $groupingid=0)
 
 chat_get_view_actions ()
 List the actions that correspond to a view of this module.
 
object chat_login_user ($chatid, $version, $groupid, $course)
 login if not already logged in
 
 chat_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 chat_prepare_update_events ($chat, $cm=null)
 Updates both the normal and completion calendar events for chat.
 
 chat_print_error ($level, $msg)
 Print json format error.
 
 chat_print_overview ()
 
object chat_print_recent_activity ($course, $viewfullnames, $timestart)
 Given a course and a date, prints a summary of all chat rooms past and present This function is called from block_recent_activity.
 
object chat_refresh_events ($courseid=0, $instance=null, $cm=null)
 This standard function will check all instances of this module and make sure there are up-to-date events created for each of them.
 
 chat_reset_course_form_defaults ($course)
 Course reset form defaults.
 
 chat_reset_course_form_definition (&$mform)
 Implementation of the function for printing the form elements that control whether the course reset functionality affects the chat.
 
object chat_reset_userdata ($data)
 Actual implementation of the reset course functionality, delete all the chat messages for course $data->courseid.
 
 chat_send_chatmessage ($chatuser, $messagetext, $issystem=false, $cm=null)
 Send a message on the chat.
 
 chat_supports ($feature)
 
object chat_update_chat_times ($chatid=0)
 Updates chat records so that the next chat time is correct.
 
object chat_update_instance ($chat)
 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.
 
 chat_user_logout (\core\event\user_loggedout $event)
 user logout event handler
 
 chat_view ($chat, $course, $cm, $context)
 Mark the activity completed (if required) and trigger the course_module_viewed event.
 
 mod_chat_core_calendar_provide_event_action (calendar_event $event, core_calendar\action_factory $factory, int $userid=0)
 This function receives a calendar event and returns the action associated with it, or null if there is none.
 
 padding ($n)
 
 xmldb_chat_upgrade ($oldversion)
 

Variables

 $capabilities
 
global $CHAT_DUMMY_DATA = padding(200)
 
global $CHAT_HTMLHEAD
 
 $CHAT_HTMLHEAD_JS =
 
 $CHAT_HTMLHEAD_MSGINPUT
 
 $CHAT_HTMLHEAD_MSGINPUT_JS =
 
global $CHAT_HTMLHEAD_OUT
 
 $functions
 
 $logs
 
 $observers
 
 $plugin = 2023100400
 
 $tasks
 
const CHAT_EVENT_TYPE_CHATTIME 'chattime'
 
const CHAT_SCHEDULE_DAILY 2
 
const CHAT_SCHEDULE_NONE 0
 
const CHAT_SCHEDULE_SINGLE 1
 
const CHAT_SCHEDULE_WEEKLY 3
 
const CHAT_SESSION_GAP 300
 
$plugin component = 'mod_chat'
 
$plugin version = 2023100900
 

Detailed Description

Function Documentation

◆ chat_add_instance()

object chat_add_instance ( $chat)

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

Parameters
object$chat
Return values
int

◆ chat_calculate_next_chat_time()

chat_calculate_next_chat_time ( int $schedule,
int $chattime )

Calculate next chat session time based on schedule.

Parameters
int$schedule
int$chattime
Return values
inttimestamp

◆ chat_delete_instance()

object chat_delete_instance ( $id)

Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.

Parameters
int$id
Return values
bool

◆ chat_delete_old_users()

object chat_delete_old_users ( )

Delete the old and in the way.

@global object

◆ chat_extend_settings_navigation()

chat_extend_settings_navigation ( settings_navigation $settings,
navigation_node $chatnode )

Adds module specific settings to the settings block.

Parameters
settings_navigation$settingsThe settings navigation object
navigation_node$chatnodeThe node to add module settings to

◆ chat_format_message()

object chat_format_message ( $message,
$courseid,
$currentuser,
$chatlastrow = null )

Given a message object this function formats it appropriately into text and html then returns the formatted data.

Parameters
object$message
int$courseid
object$currentuser
string$chatlastrow
Return values
bool|stringReturns HTML or false

◆ chat_format_message_manually()

object chat_format_message_manually ( $message,
$courseid,
$sender,
$currentuser,
$chatlastrow = null )

@global object

Parameters
object$message
int$courseid
object$sender
object$currentuser
string$chatlastrow
Return values
bool|stringReturns HTML or false

◆ chat_format_message_theme()

object chat_format_message_theme ( $message,
$chatuser,
$currentuser,
$groupingid,
$theme = 'bubble' )
Parameters
object$messagemessage to be displayed.
mixed$chatuseruser chat data
object$currentusercurrent user for whom the message should be displayed.
int$groupingidcourse module grouping id
string$themename of the chat theme.
Return values
bool|stringReturns HTML or false

◆ chat_format_userlist()

object chat_format_userlist ( $users,
$course )

$DB @global object $CFG @global object $COURSE @global object $OUTPUT

Parameters
object$users
object$course
Return values
arrayreturn formatted user list

◆ chat_get_coursemodule_info()

chat_get_coursemodule_info ( $coursemodule)

Add a get_coursemodule_info function in case chat instance 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.

Parameters
stdClass$coursemoduleThe coursemodule object (record).
Return values
cached_cm_infoAn object on information that the courses will know about (most noticeably, an icon).

◆ chat_get_latest_message()

object chat_get_latest_message ( $chatid,
$groupid = 0 )
Parameters
int$chatid
int$groupid
Return values
array

◆ chat_get_latest_messages()

chat_get_latest_messages ( $chatuser,
$chatlasttime )

Return a list of the latest messages in the given chat session.

Parameters
stdClass$chatuserchat user session data
int$chatlasttimelast time messages were retrieved
Return values
arraylist of messages
Since
Moodle 3.0

◆ chat_get_post_actions()

chat_get_post_actions ( )

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 values
array

◆ chat_get_session_messages()

chat_get_session_messages ( $chatid,
$group = false,
$start = 0,
$end = 0,
$sort = '' )

Return the messages of the given chat session.

Parameters
int$chatidthe chat id
mixed$groupfalse if groups not used, int if groups used, 0 means all groups
int$startthe session start timestamp (0 to not filter by time)
int$endthe session end timestamp (0 to not filter by time)
string$sortan order to sort the results in (optional, a valid SQL ORDER BY parameter)
Return values
arraysession messages
Since
Moodle 3.5

◆ chat_get_sessions()

chat_get_sessions ( $messages,
$showall = false )

Given a set of messages for a chat, return the completed chat sessions (including optionally not completed ones).

Parameters
array$messageslist of messages from a chat. It is assumed that these are sorted by timestamp in DESCENDING order.
bool$showallwhether to include incomplete sessions or not
Return values
arraythe list of sessions
Since
Moodle 3.5

◆ chat_get_users()

object chat_get_users ( $chatid,
$groupid = 0,
$groupingid = 0 )
Parameters
int$chatid
int$groupid
int$groupingid
Return values
array

◆ chat_get_view_actions()

chat_get_view_actions ( )

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 values
array

◆ chat_login_user()

object chat_login_user ( $chatid,
$version,
$groupid,
$course )

login if not already logged in

@global object

Parameters
int$chatid
string$version
int$groupid
object$course
Return values
bool|intReturns the chat users sid or false

◆ chat_page_type_list()

chat_page_type_list ( $pagetype,
$parentcontext,
$currentcontext )

Return a list of page types.

Parameters
string$pagetypecurrent page type
stdClass$parentcontextBlock's parent context
stdClass$currentcontextCurrent context of block

◆ chat_prepare_update_events()

chat_prepare_update_events ( $chat,
$cm = null )

Updates both the normal and completion calendar events for chat.

Parameters
stdClass$chatThe chat object (from the DB)
stdClass$cmThe course module object.

◆ chat_print_error()

chat_print_error ( $level,
$msg )

Print json format error.

Parameters
string$level
string$msg

◆ chat_print_overview()

chat_print_overview ( )
Deprecated
since Moodle 3.3, when the block_course_overview block was removed.

◆ chat_print_recent_activity()

object chat_print_recent_activity ( $course,
$viewfullnames,
$timestart )

Given a course and a date, prints a summary of all chat rooms past and present This function is called from block_recent_activity.

@global object @global object

Parameters
object$course
bool$viewfullnames
int | string$timestartTimestamp
Return values
bool

◆ chat_refresh_events()

object chat_refresh_events ( $courseid = 0,
$instance = null,
$cm = null )

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 chat event in the site is checked, else only chat events belonging to the course specified are checked. This function is used, in its new format, by restore_refresh_events()

Parameters
int$courseid
int | stdClass$instanceChat module instance or ID.
int | stdClass$cmCourse module object or ID.
Return values
bool

◆ chat_reset_course_form_defaults()

chat_reset_course_form_defaults ( $course)

Course reset form defaults.

Parameters
object$course
Return values
array

◆ chat_reset_course_form_definition()

chat_reset_course_form_definition ( & $mform)

Implementation of the function for printing the form elements that control whether the course reset functionality affects the chat.

Parameters
MoodleQuickForm$mformform passed by reference

◆ chat_reset_userdata()

object chat_reset_userdata ( $data)

Actual implementation of the reset course functionality, delete all the chat messages for course $data->courseid.

@global object

Parameters
object$datathe data submitted from the reset course.
Return values
arraystatus array

◆ chat_send_chatmessage()

chat_send_chatmessage ( $chatuser,
$messagetext,
$issystem = false,
$cm = null )

Send a message on the chat.

Parameters
object$chatuserThe chat user record.
string$messagetextThe message to be sent.
bool$issystemFalse for non-system messages, true for system messages.
object$cmThe course module object, pass it to save a database query when we trigger the event.
Return values
intThe message ID.
Since
Moodle 2.6

◆ chat_supports()

chat_supports ( $feature)
Parameters
string$featureFEATURE_xx constant for requested feature
Return values
mixedTrue if module supports feature, false if not, null if doesn't know or string for the module purpose.

◆ chat_update_chat_times()

object chat_update_chat_times ( $chatid = 0)

Updates chat records so that the next chat time is correct.

Parameters
int$chatid
Return values
void

◆ chat_update_instance()

object chat_update_instance ( $chat)

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.

Parameters
object$chat
Return values
bool

◆ chat_user_logout()

chat_user_logout ( \core\event\user_loggedout $event)

user logout event handler

Parameters
core\event\user_loggedout$eventThe event.
Return values
void

◆ chat_view()

chat_view ( $chat,
$course,
$cm,
$context )

Mark the activity completed (if required) and trigger the course_module_viewed event.

Parameters
stdClass$chatchat object
stdClass$coursecourse object
stdClass$cmcourse module object
stdClass$contextcontext object
Since
Moodle 3.0

◆ mod_chat_core_calendar_provide_event_action()

mod_chat_core_calendar_provide_event_action ( calendar_event $event,
core_calendar\action_factory $factory,
int $userid = 0 )

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.

Parameters
calendar_event$event
core_calendar\action_factory$factory
int$useridUser id to use for all capability checks, etc. Set to 0 for current user (default).
Return values
core_calendar\local\event\entities\action_interface|null

◆ padding()

padding ( $n)
Parameters
int$n
Return values
string

Variable Documentation

◆ $CHAT_HTMLHEAD

$CHAT_HTMLHEAD
Initial value:
= "<!DOCTYPE HTML PUBLIC "-
global $CHAT_HTMLHEAD_JS

◆ $CHAT_HTMLHEAD_MSGINPUT

$CHAT_HTMLHEAD_MSGINPUT
Initial value:
= "<!DOCTYPE HTML PUBLIC "-
global $CHAT_HTMLHEAD_MSGINPUT_JS

◆ $CHAT_HTMLHEAD_OUT

$CHAT_HTMLHEAD_OUT
Initial value:
= "<!DOCTYPE HTML PUBLIC "-
global $CHAT_HTMLHEAD_MSGINPUT

◆ $logs

$logs
Initial value:
= array(
array('module' => 'chat', 'action' => 'view', 'mtable' => 'chat', 'field' => 'name'),
array('module' => 'chat', 'action' => 'add', 'mtable' => 'chat', 'field' => 'name'),
array('module' => 'chat', 'action' => 'update', 'mtable' => 'chat', 'field' => 'name'),
array('module' => 'chat', 'action' => 'report', 'mtable' => 'chat', 'field' => 'name'),
array('module' => 'chat', 'action' => 'talk', 'mtable' => 'chat', 'field' => 'name'),
)

◆ $observers

$observers
Initial value:
= array(
array(
'eventname' => '\core\event\user_loggedout',
'callback' => 'chat_user_logout',
'includefile' => '/mod/chat/lib.php'
)
)
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

◆ $tasks

$tasks
Initial value:
= array(
array(
'classname' => '\mod_chat\task\cron_task',
'blocking' => 0,
'minute' => '*/5',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
)
)