Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | List of all members
core_message\helper Class Reference

Helper class for the message area. More...

Static Public Member Functions

static create_contact ($contact, $prefix='')
 Helper function for creating a contact object. More...
 
static create_messages ($userid, $messages)
 Helper function to return an array of messages. More...
 
static format_conversation_messages (int $userid, int $convid, array $messages)
 Helper function to return a conversation messages with the involved members (only the ones who have sent any of these messages). More...
 
static get_conversation_hash (array $userids)
 Returns the conversation hash between users for easy look-ups in the DB. More...
 
static get_conversation_messages (int $userid, int $convid, int $timedeleted=0, int $limitfrom=0, int $limitnum=0, string $sort='timecreated ASC', int $timefrom=0, int $timeto=0)
 Helper function to retrieve conversation messages. More...
 
static get_conversations_legacy_formatter (array $conversations)
 Backwards compatibility formatter, transforming the new output of get_conversations() into the old format. More...
 
static get_last_message_time_created_cache_key (int $convid)
 Returns the cache key for the time created value of the last message of this conversation. More...
 
static get_member_info (int $referenceuserid, array $userids, bool $includecontactrequests=false, bool $includeprivacyinfo=false)
 Returns conversation member info for the supplied users, relative to the supplied referenceuserid. More...
 
static get_messages ($userid, $otheruserid, $timedeleted=0, $limitfrom=0, $limitnum=0, $sort='timecreated ASC', $timefrom=0, $timeto=0)
 Helper function to retrieve the messages between two users. More...
 
static get_providers_preferences ($providers, $userid)
 Get providers preferences. More...
 
static is_online ($lastaccess)
 Helper function for checking the time meets the 'online' condition. More...
 
static legacy_messages_exist ($userid)
 Checks if legacy messages exist for a given user. More...
 
static messageuser_link_params (int $useridto)
 Returns the attributes to place on the message user button. More...
 
static messageuser_requirejs ()
 Requires the JS libraries for the message user button. More...
 
static prevent_unclosed_html_tags (string $message, bool $removebody=false)
 Prevent unclosed HTML elements in a message. More...
 
static render_messaging_widget (bool $isdrawer, int $sendtouser=null, int $conversationid=null, string $view=null)
 Renders the messaging widget. More...
 
static search_get_user_details (\stdClass $user)
 Returns user details for a user, if they are visible to the current user in the message search. More...
 
static show_online_status ($user)
 Helper function for checking if we should show the user's online status. More...
 
static togglecontact_link_params ($user, $iscontact=false)
 Returns the attributes to place on a contact button. More...
 
static togglecontact_requirejs ()
 Requires the JS libraries for the toggle contact button. More...
 

Detailed Description

Helper class for the message area.

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

Member Function Documentation

◆ create_contact()

static core_message\helper::create_contact (   $contact,
  $prefix = '' 
)
static

Helper function for creating a contact object.

Parameters
stdClass$contact
string$prefix
Return values
stdClass

◆ create_messages()

static core_message\helper::create_messages (   $userid,
  $messages 
)
static

Helper function to return an array of messages.

TODO: This function should be removed once the related web services go through final deprecation. The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message. Followup: MDL-63261

Parameters
int$userid
array$messages
Return values
array

◆ format_conversation_messages()

static core_message\helper::format_conversation_messages ( int  $userid,
int  $convid,
array  $messages 
)
static

Helper function to return a conversation messages with the involved members (only the ones who have sent any of these messages).

Parameters
int$useridThe current userid.
int$convidThe conversation id.
array$messagesThe formated array messages.
Return values
arrayA conversation array with the messages and the involved members.

◆ get_conversation_hash()

static core_message\helper::get_conversation_hash ( array  $userids)
static

Returns the conversation hash between users for easy look-ups in the DB.

Parameters
array$userids
Return values
string

◆ get_conversation_messages()

static core_message\helper::get_conversation_messages ( int  $userid,
int  $convid,
int  $timedeleted = 0,
int  $limitfrom = 0,
int  $limitnum = 0,
string  $sort = 'timecreated ASC',
int  $timefrom = 0,
int  $timeto = 0 
)
static

Helper function to retrieve conversation messages.

Parameters
int$useridThe current user.
int$convidThe conversation identifier.
int$timedeletedThe time the message was deleted
int$limitfromReturn a subset of records, starting at this point (optional).
int$limitnumReturn a subset comprising this many records in total (optional, required if $limitfrom is set).
string$sortThe column name to order by including optionally direction.
int$timefromThe time from the message being sent.
int$timetoThe time up until the message being sent.
Return values
arrayof messages

◆ get_conversations_legacy_formatter()

static core_message\helper::get_conversations_legacy_formatter ( array  $conversations)
static

Backwards compatibility formatter, transforming the new output of get_conversations() into the old format.

TODO: This function should be removed once the related web services go through final deprecation. The related web services are data_for_messagearea_conversations. Followup: MDL-63261

Parameters
array$conversationsthe array of conversations, which must come from get_conversations().
Return values
arraythe array of conversations, formatted in the legacy style.

◆ get_last_message_time_created_cache_key()

static core_message\helper::get_last_message_time_created_cache_key ( int  $convid)
static

Returns the cache key for the time created value of the last message of this conversation.

Parameters
int$convidThe conversation identifier.
Return values
stringThe key.

◆ get_member_info()

static core_message\helper::get_member_info ( int  $referenceuserid,
array  $userids,
bool  $includecontactrequests = false,
bool  $includeprivacyinfo = false 
)
static

Returns conversation member info for the supplied users, relative to the supplied referenceuserid.

This is the basic structure used when returning members, and includes information about the relationship between each member and the referenceuser, such as a whether the referenceuser has marked the member as a contact, or has blocked them.

Parameters
int$referenceuseridthe id of the user which check contact and blocked status.
array$userids
bool$includecontactrequestsDo we want to include contact requests with this data?
bool$includeprivacyinfoDo we want to include whether the user can message another, and if the user requires a contact.
Return values
arraythe array of objects containing member info, indexed by userid.
Exceptions
coding_exception
dml_exception

◆ get_messages()

static core_message\helper::get_messages (   $userid,
  $otheruserid,
  $timedeleted = 0,
  $limitfrom = 0,
  $limitnum = 0,
  $sort = 'timecreated ASC',
  $timefrom = 0,
  $timeto = 0 
)
static

Helper function to retrieve the messages between two users.

TODO: This function should be removed once the related web services go through final deprecation. The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message. Followup: MDL-63261

Parameters
int$useridthe current user
int$otheruseridthe other user
int$timedeletedthe time the message was deleted
int$limitfrom
int$limitnum
string$sort
int$timefromthe time from the message being sent
int$timetothe time up until the message being sent
Return values
arrayof messages

◆ get_providers_preferences()

static core_message\helper::get_providers_preferences (   $providers,
  $userid 
)
static

Get providers preferences.

Parameters
array$providers
int$userid
Return values
stdClass

◆ is_online()

static core_message\helper::is_online (   $lastaccess)
static

Helper function for checking the time meets the 'online' condition.

Parameters
int$lastaccess
Return values
boolean

◆ legacy_messages_exist()

static core_message\helper::legacy_messages_exist (   $userid)
static

Checks if legacy messages exist for a given user.

Parameters
int$userid
Return values
bool

◆ messageuser_link_params()

static core_message\helper::messageuser_link_params ( int  $useridto)
static

Returns the attributes to place on the message user button.

Parameters
int$useridto
Return values
array

◆ messageuser_requirejs()

static core_message\helper::messageuser_requirejs ( )
static

Requires the JS libraries for the message user button.

Return values
void

◆ prevent_unclosed_html_tags()

static core_message\helper::prevent_unclosed_html_tags ( string  $message,
bool  $removebody = false 
)
static

Prevent unclosed HTML elements in a message.

Parameters
string$messageThe html message.
bool$removebodyTrue if we want to remove tag body.
Return values
stringThe html properly structured.

◆ render_messaging_widget()

static core_message\helper::render_messaging_widget ( bool  $isdrawer,
int  $sendtouser = null,
int  $conversationid = null,
string  $view = null 
)
static

Renders the messaging widget.

Parameters
bool$isdrawerAre we are rendering the drawer or is this on a full page?
int | null$sendtouserThe ID of the user we want to send a message to
int | null$conversationidThe ID of the conversation we want to load
string | null$viewThe first view to load in the message widget
Return values
stringThe HTML.

◆ search_get_user_details()

static core_message\helper::search_get_user_details ( \stdClass  $user)
static

Returns user details for a user, if they are visible to the current user in the message search.

This method checks the visibility of a user specifically for the purpose of inclusion in the message search results. Visibility depends on the site-wide messaging setting 'messagingallusers': If enabled, visibility depends only on the core notion of visibility; a visible site or course profile. If disabled, visibility requires that the user be sharing a course with the searching user, and have a visible profile there. The current user is always returned.

Parameters
stdClass$user
Return values
arraythe array of userdetails, if visible, or an empty array otherwise.

◆ show_online_status()

static core_message\helper::show_online_status (   $user)
static

Helper function for checking if we should show the user's online status.

Parameters
stdClass$user
Return values
boolean

◆ togglecontact_link_params()

static core_message\helper::togglecontact_link_params (   $user,
  $iscontact = false 
)
static

Returns the attributes to place on a contact button.

Parameters
object$userUser object.
bool$iscontact
Return values
array

◆ togglecontact_requirejs()

static core_message\helper::togglecontact_requirejs ( )
static

Requires the JS libraries for the toggle contact button.

Return values
void

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