PHP Class ConversationModel, vanilla

Since: 2.0.0
Inheritance: extends Gdn_Model
Show file Open project: vanilla/vanilla Class Usage Examples

Public Methods

Method Description
__construct ( ) Class constructor. Defines the related database table name.
addUserAllowed ( integer $ConversationID, integer $CountRecipients ) : boolean Are we allowed to add more recipients?
addUserToConversation ( integer $ConversationID, integer $UserID ) Add another user to the conversation.
bookmark ( integer $ConversationID, integer $UserID ) : boolean Bookmark (or unbookmark) a conversation for a specific user id.
clear ( integer $ConversationID, integer $ClearingUserID ) Clear a conversation for a specific user id.
conversationQuery ( integer $ViewingUserID, $Join = '' ) Build generic part of conversation query.
countUnread ( integer $UserID, boolean $Save = true ) : integer Count unread messages.
counts ( $Column, $From = false, $To = false, $Max = false )
get ( $OrderFields = '', $OrderDirection = '', $Limit = false, $PageNumber = false )
get2 ( integer $UserID, integer $Offset, integer $Limit ) Get a list of conversations for a user's inbox. This is an optimized version of ConversationModel::get().
getCount ( $wheres = [] )
getCountInbox ( integer $ViewingUserID, array $Wheres = '' ) : integer Get number of conversations involving current user.
getCountWhere ( array $Wheres = '' ) : integer Get number of conversations that meet criteria.
getID ( integer $ConversationID, string $datasetType = false, array $options = [] ) : array | stdClass Get meta data of a single conversation.
getInbox ( integer $ViewingUserID, integer | string $Limit = '', integer | string $Offset = '0' ) : Gdn_DataSet Get list of conversations.
getRecipients ( integer $ConversationID, integer $Limit = 20 ) : Gdn_DataSet Get all users involved in conversation.
inConversation ( integer $ConversationID, integer $UserID ) : integer | boolean Figure out whether or not a user is in a conversation.
joinLastMessages ( &$Data )
joinParticipants ( &$Data, $Max = 5 )
markRead ( integer $ConversationID, integer $ReadingUserID ) Update a conversation as read for a specific user id.
participantTitle ( array | object $Conversation, boolean $Html = true, integer $Max = 3 ) : string Gets a nice title to represent the participants in a conversation.
save ( array $formPostValues, array $settings = [] ) : integer Save conversation from form submission.
updateParticipantCount ( integer $ConversationID ) Update the count of participants.
updateUserUnreadCount ( array $UserIDs, boolean $SkipSelf = false ) Update users' unread conversation counter.

Method Details

__construct() public method

Class constructor. Defines the related database table name.
Since: 2.0.0
public __construct ( )

addUserAllowed() public method

If we pass $CountRecipients then $ConversationID isn't needed (set to zero).
public addUserAllowed ( integer $ConversationID, integer $CountRecipients ) : boolean
$ConversationID integer Unique ID of the conversation.
$CountRecipients integer Optionally skip needing to query the count by passing it.
return boolean Whether user may add more recipients to conversation.

addUserToConversation() public method

Add another user to the conversation.
Since: 2.0.0
public addUserToConversation ( integer $ConversationID, integer $UserID )
$ConversationID integer Unique ID of conversation effected.
$UserID integer Unique ID of current user.

bookmark() public method

Bookmark (or unbookmark) a conversation for a specific user id.
Since: 2.0.0
public bookmark ( integer $ConversationID, integer $UserID ) : boolean
$ConversationID integer Unique ID of conversation effected.
$UserID integer Unique ID of current user.
return boolean Whether it is currently bookmarked.

clear() public method

Clear a conversation for a specific user id.
Since: 2.0.0
public clear ( integer $ConversationID, integer $ClearingUserID )
$ConversationID integer Unique ID of conversation effected.
$ClearingUserID integer Unique ID of current user.

conversationQuery() public method

Build generic part of conversation query.
Since: 2.0.0
public conversationQuery ( integer $ViewingUserID, $Join = '' )
$ViewingUserID integer Unique ID of current user.

countUnread() public method

Count unread messages.
public countUnread ( integer $UserID, boolean $Save = true ) : integer
$UserID integer Unique ID for user being queried.
$Save boolean Whether to update user record.
return integer

counts() public method

public counts ( $Column, $From = false, $To = false, $Max = false )

get() public method

public get ( $OrderFields = '', $OrderDirection = '', $Limit = false, $PageNumber = false )

get2() public method

Get a list of conversations for a user's inbox. This is an optimized version of ConversationModel::get().
public get2 ( integer $UserID, integer $Offset, integer $Limit )
$UserID integer The user looking at the conversations.
$Offset integer Number to skip.
$Limit integer Maximum to return.

getCount() public method

public getCount ( $wheres = [] )

getCountInbox() public method

Get number of conversations involving current user.
public getCountInbox ( integer $ViewingUserID, array $Wheres = '' ) : integer
$ViewingUserID integer Unique ID of current user.
$Wheres array SQL conditions.
return integer Number of messages.

getCountWhere() public method

Get number of conversations that meet criteria.
Since: 2.0.0
public getCountWhere ( array $Wheres = '' ) : integer
$Wheres array SQL conditions.
return integer Number of messages.

getID() public method

Get meta data of a single conversation.
public getID ( integer $ConversationID, string $datasetType = false, array $options = [] ) : array | stdClass
$ConversationID integer Unique ID of conversation.
$datasetType string The format of the resulting conversation.
$options array Options to modify the get. Currently supports `viewingUserID`.
return array | stdClass Returns a conversation.

getInbox() public method

Events: BeforeGet.
public getInbox ( integer $ViewingUserID, integer | string $Limit = '', integer | string $Offset = '0' ) : Gdn_DataSet
$ViewingUserID integer Unique ID of current user.
$Limit integer | string Maximum to return.
$Offset integer | string Number to skip.
return Gdn_DataSet SQL results.

getRecipients() public method

Get all users involved in conversation.
Since: 2.0.0
public getRecipients ( integer $ConversationID, integer $Limit = 20 ) : Gdn_DataSet
$ConversationID integer Unique ID of conversation.
$Limit integer The number of recipients to grab.
return Gdn_DataSet SQL results.

inConversation() public method

Figure out whether or not a user is in a conversation.
public inConversation ( integer $ConversationID, integer $UserID ) : integer | boolean
$ConversationID integer
$UserID integer
return integer | boolean

joinLastMessages() public method

public joinLastMessages ( &$Data )

joinParticipants() public method

public joinParticipants ( &$Data, $Max = 5 )

markRead() public method

Update a conversation as read for a specific user id.
Since: 2.0.0
public markRead ( integer $ConversationID, integer $ReadingUserID )
$ConversationID integer Unique ID of conversation effected.
$ReadingUserID integer Unique ID of current user.

participantTitle() public static method

Gets a nice title to represent the participants in a conversation.
public static participantTitle ( array | object $Conversation, boolean $Html = true, integer $Max = 3 ) : string
$Conversation array | object The conversation to get the participants for.
$Html boolean Whether or not to return HTML.
$Max integer The maximum number of participants to show in the list.
return string Returns a title for the conversation.

save() public method

Save conversation from form submission.
public save ( array $formPostValues, array $settings = [] ) : integer
$formPostValues array Values submitted via form.
$settings array Not used.
return integer Unique ID of conversation created or updated.

updateParticipantCount() public method

Update the count of participants.
public updateParticipantCount ( integer $ConversationID )
$ConversationID integer

updateUserUnreadCount() public method

Update users' unread conversation counter.
public updateUserUnreadCount ( array $UserIDs, boolean $SkipSelf = false )
$UserIDs array Array of ints.
$SkipSelf boolean Whether to omit current user.