PHP Class ActivityModel, vanilla

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

Public Properties

Property Type Description
$ActivityTypes Allowed activity types.
$MaxMergeCount Limit on number of activity to combine.
$Queue Activity to be saved.

Public Methods

Method Description
__construct ( ) Defines the related database table name.
activityQuery ( boolean $Join = true ) Build basis of common activity SQL query.
add ( integer $ActivityUserID, string $ActivityType, string $Story = null, integer | null $RegardingUserID = null, integer $CommentActivityID = null, string $Route = null, string | boolean $SendEmail = '' ) : integer Add a new activity item.
calculateData ( &$Data )
calculateRow ( &$Row )
canDelete ( $activity ) : boolean
clearNotificationQueue ( ) Clear notification queue.
comment ( array $Comment ) : integer | boolean | string Save a comment on an activity.
defineType ( string $Name, array $Activity = [] ) Define a new activity type.
delete ( $where = [], $options = [] )
deleteComment ( integer $ID ) : Gdn_DataSet Delete an activity comment.
deleteID ( integer $ActivityID, array $Options = [] ) : boolean Delete a particular activity item.
email ( &$Activity, boolean $NoDelete = false ) : boolean
getActivityType ( $ActivityType ) : boolean
getByUser ( integer | boolean $NotifyUserID = false, integer $Offset, integer $Limit = 30 ) : Gdn_DataSet Modifies standard Gdn_Model->Get to use AcitivityQuery.
getComment ( integer $ID ) : array | false
getComments ( array $ActivityIDs ) : Gdn_DataSet Get comments related to designated activity items.
getCount ( string $UserID = '' ) : integer Get number of activity related to a user.
getCountForRole ( integer | string $RoleID = '' ) : integer Get number of activity related to a particular role.
getForRole ( string $RoleID = '', integer $Offset, integer $Limit = 50 ) : Gdn_DataSet Get activity related to a particular role.
getID ( integer $activityID, boolean | string $dataSetType = false, array $options = [] ) : array | object Get a particular activity record.
getNotifications ( integer $NotifyUserID, integer $Offset, integer $Limit = 30 ) : Gdn_DataSet Get notifications for a user.
getNotificationsSince ( integer $UserID, integer $LastActivityID, array | string $FilterToActivityTypeIDs = '', integer $Limit = 5 ) : Gdn_DataSet Get notifications for a user since designated ActivityID.
getPruneAfter ( ) : string Get the delete after time.
getUsers ( &$Data )
getWhere ( array $Where = [], string $orderFields = '', string $orderDirection = '', integer | boolean $Limit = false, integer | boolean $Offset = false ) : Gdn_DataSet Modifies standard Gdn_Model->GetWhere to use AcitivityQuery.
getWhereRecent ( array $where, integer $limit, integer $offset ) : Gdn_DataSet Get the recent activities.
joinComments ( &$Activities )
joinUsers ( &$Activities ) Join the users to the activities.
markRead ( $UserID )
mergeActivities ( $OldActivity, $NewActivity, array $Options = [] ) : array
notificationPreference ( string $ActivityType, array $Preferences, string $Type = null ) : boolean | bool[] Get default notification preference for an activity type.
queue ( array $Data, string | boolean $Preference = false, array $Options = [] ) Queue an activity for saving later.
queueNotification ( integer $ActivityID, string $Story = '', string $Position = 'last', boolean $Force = false ) Queue a notification for sending.
save ( array $Data, boolean $Preference = false, array $Options = [] ) : array | boolean | string | null
saveQueue ( ) : array
sendNotification ( integer $ActivityID, array | string $Story = '', boolean $Force = false ) Send notification.
sendNotificationQueue ( ) Send all notifications in the queue.
setNotified ( $ActivityIDs )
setPruneAfter ( string $pruneAfter ) : ActivityModel Set the prune after date.
share ( &$Activity )

Protected Methods

Method Description
_touch ( &$Data )
notifyWallComment ( array $Comment, $WallPost ) Notify the user of wall comments.
notifyWallPost ( $WallPost )

Private Methods

Method Description
getEmailMessage ( array | object $activity ) : string Takes an array representing an activity and builds the email message based on the activity's story and the contents of the global config Garden.Email.Prefix.
getPruneDate ( ) : DateTime | null Get the exact timestamp to prune.
prune ( ) Prune old activities.

Method Details

__construct() public method

Defines the related database table name.
public __construct ( )

_touch() protected method

protected _touch ( &$Data )
$Data

activityQuery() public method

Build basis of common activity SQL query.
Since: 2.0.0
public activityQuery ( boolean $Join = true )
$Join boolean

add() public method

Getting reworked for 2.1 so I'm cheating and skipping params for now. -mlr
public add ( integer $ActivityUserID, string $ActivityType, string $Story = null, integer | null $RegardingUserID = null, integer $CommentActivityID = null, string $Route = null, string | boolean $SendEmail = '' ) : integer
$ActivityUserID integer
$ActivityType string
$Story string
$RegardingUserID integer | null
$CommentActivityID integer
$Route string
$SendEmail string | boolean
return integer ActivityID of item created.

calculateData() public method

public calculateData ( &$Data )
$Data

calculateRow() public method

public calculateRow ( &$Row )
$Row

canDelete() public static method

public static canDelete ( $activity ) : boolean
$activity
return boolean

clearNotificationQueue() public method

Clear notification queue.
Since: 2.0.17

comment() public method

Save a comment on an activity.
Since: 2.1
public comment ( array $Comment ) : integer | boolean | string
$Comment array
return integer | boolean | string

defineType() public method

Define a new activity type.
Since: 2.1
public defineType ( string $Name, array $Activity = [] )
$Name string The string code of the activity type.
$Activity array The data that goes in the ActivityType table.

delete() public method

public delete ( $where = [], $options = [] )

deleteComment() public method

Delete an activity comment.
Since: 2.1
public deleteComment ( integer $ID ) : Gdn_DataSet
$ID integer
return Gdn_DataSet

deleteID() public method

Delete a particular activity item.
public deleteID ( integer $ActivityID, array $Options = [] ) : boolean
$ActivityID integer The unique ID of activity to be deleted.
$Options array Not used.
return boolean Returns **true** if the activity was deleted or **false** otherwise.

email() public method

public email ( &$Activity, boolean $NoDelete = false ) : boolean
$Activity
$NoDelete boolean
return boolean

getActivityType() public static method

public static getActivityType ( $ActivityType ) : boolean
$ActivityType
return boolean

getByUser() public method

Events: BeforeGet, AfterGet.
public getByUser ( integer | boolean $NotifyUserID = false, integer $Offset, integer $Limit = 30 ) : Gdn_DataSet
$NotifyUserID integer | boolean Unique ID of user to gather activity for or one of the NOTIFY_* constants in this class.
$Offset integer Number to skip.
$Limit integer How many to return.
return Gdn_DataSet SQL results.

getComment() public method

public getComment ( integer $ID ) : array | false
$ID integer
return array | false

getComments() public method

Events: BeforeGetComments.
public getComments ( array $ActivityIDs ) : Gdn_DataSet
$ActivityIDs array IDs of activity items.
return Gdn_DataSet SQL results.

getCount() public method

Events: BeforeGetCount.
Since: 2.0.0
public getCount ( string $UserID = '' ) : integer
$UserID string Unique ID of user.
return integer Number of activity items found.

getCountForRole() public method

Get number of activity related to a particular role.
Since: 2.0.18
public getCountForRole ( integer | string $RoleID = '' ) : integer
$RoleID integer | string Unique ID of role.
return integer Number of activity items.

getForRole() public method

Events: AfterGet.
Since: 2.0.18
public getForRole ( string $RoleID = '', integer $Offset, integer $Limit = 50 ) : Gdn_DataSet
$RoleID string Unique ID of role.
$Offset integer Number to skip.
$Limit integer Max number to return.
return Gdn_DataSet SQL results.

getID() public method

Get a particular activity record.
public getID ( integer $activityID, boolean | string $dataSetType = false, array $options = [] ) : array | object
$activityID integer Unique ID of activity item.
$dataSetType boolean | string The format of the resulting data.
$options array Not used.
return array | object A single SQL result.

getNotifications() public method

Events: BeforeGetNotifications.
Since: 2.0.0
public getNotifications ( integer $NotifyUserID, integer $Offset, integer $Limit = 30 ) : Gdn_DataSet
$NotifyUserID integer Unique ID of user.
$Offset integer Number to skip.
$Limit integer Max number to return.
return Gdn_DataSet SQL results.

getNotificationsSince() public method

Events: BeforeGetNotificationsSince.
Since: 2.0.18
public getNotificationsSince ( integer $UserID, integer $LastActivityID, array | string $FilterToActivityTypeIDs = '', integer $Limit = 5 ) : Gdn_DataSet
$UserID integer Unique ID of user.
$LastActivityID integer ID of activity to start at.
$FilterToActivityTypeIDs array | string Limits returned activity to particular types.
$Limit integer Max number to return.
return Gdn_DataSet SQL results.

getPruneAfter() public method

Get the delete after time.
public getPruneAfter ( ) : string
return string Returns a string compatible with {@link strtotime()}.

getUsers() public static method

public static getUsers ( &$Data )

getWhere() public method

Events: AfterGet.
public getWhere ( array $Where = [], string $orderFields = '', string $orderDirection = '', integer | boolean $Limit = false, integer | boolean $Offset = false ) : Gdn_DataSet
$Where array A filter suitable for passing to Gdn_SQLDriver::Where().
$orderFields string A comma delimited string to order the data.
$orderDirection string One of **asc** or **desc**.
$Limit integer | boolean The database limit.
$Offset integer | boolean The database offset.
return Gdn_DataSet SQL results.

getWhereRecent() public method

Get the recent activities.
public getWhereRecent ( array $where, integer $limit, integer $offset ) : Gdn_DataSet
$where array
$limit integer
$offset integer
return Gdn_DataSet

joinComments() public method

Since: 2.1
public joinComments ( &$Activities )

joinUsers() public static method

Join the users to the activities.
public static joinUsers ( &$Activities )

markRead() public method

public markRead ( $UserID )
$UserID

mergeActivities() public method

public mergeActivities ( $OldActivity, $NewActivity, array $Options = [] ) : array
$OldActivity
$NewActivity
$Options array
return array

notificationPreference() public static method

Get default notification preference for an activity type.
Since: 2.0.0
public static notificationPreference ( string $ActivityType, array $Preferences, string $Type = null ) : boolean | bool[]
$ActivityType string
$Preferences array
$Type string One of the following: - Popup: Popup a notification. - Email: Email the notification. - NULL: True if either notification is true. - both: Return an array of (Popup, Email).
return boolean | bool[]

notifyWallComment() protected method

Notify the user of wall comments.
protected notifyWallComment ( array $Comment, $WallPost )
$Comment array
$WallPost

notifyWallPost() protected method

protected notifyWallPost ( $WallPost )
$WallPost

queue() public method

Queue an activity for saving later.
public queue ( array $Data, string | boolean $Preference = false, array $Options = [] )
$Data array The data in the activity.
$Preference string | boolean The name of the preference governing the activity.
$Options array Additional options for saving.

queueNotification() public method

Queue a notification for sending.
Since: 2.0.17
public queueNotification ( integer $ActivityID, string $Story = '', string $Position = 'last', boolean $Force = false )
$ActivityID integer
$Story string
$Position string
$Force boolean

save() public method

public save ( array $Data, boolean $Preference = false, array $Options = [] ) : array | boolean | string | null
$Data array
$Preference boolean
$Options array
return array | boolean | string | null

saveQueue() public method

public saveQueue ( ) : array
return array

sendNotification() public method

Send notification.
Since: 2.0.17
public sendNotification ( integer $ActivityID, array | string $Story = '', boolean $Force = false )
$ActivityID integer
$Story array | string
$Force boolean

sendNotificationQueue() public method

Send all notifications in the queue.
Since: 2.0.17

setNotified() public method

public setNotified ( $ActivityIDs )
$ActivityIDs

setPruneAfter() public method

Set the prune after date.
public setPruneAfter ( string $pruneAfter ) : ActivityModel
$pruneAfter string A string compatible with {@link strtotime()}. Be sure to specify a negative string.
return ActivityModel Returns `$this` for fluent calls.

share() public method

public share ( &$Activity )
$Activity

Property Details

$ActivityTypes public static property

Allowed activity types.
public static $ActivityTypes

$MaxMergeCount public static property

Limit on number of activity to combine.
public static $MaxMergeCount

$Queue public static property

Activity to be saved.
public static $Queue