本文整理汇总了PHP中ActivityModel::QueueNotification方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivityModel::QueueNotification方法的具体用法?PHP ActivityModel::QueueNotification怎么用?PHP ActivityModel::QueueNotification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityModel
的用法示例。
在下文中一共展示了ActivityModel::QueueNotification方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Save2
/**
* Insert or update meta data about the comment.
*
* Updates unread comment totals, bookmarks, and activity. Sends notifications.
*
* @since 2.0.0
* @access public
*
* @param array $CommentID Unique ID for this comment.
* @param int $Insert Used as a boolean for whether this is a new comment.
* @param bool $CheckExisting Not used.
*/
public function Save2($CommentID, $Insert, $CheckExisting = TRUE)
{
$Session = Gdn::Session();
// Load comment data
$Fields = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
// Make a quick check so that only the user making the comment can make the notification.
// This check may be used in the future so should not be depended on later in the method.
if ($Fields['InsertUserID'] != $Session->UserID) {
return;
}
// Update the discussion author's CountUnreadDiscussions (ie.
// the number of discussions created by the user that s/he has
// unread messages in) if this comment was not added by the
// discussion author.
$Data = $this->SQL->Select('d.InsertUserID')->Select('d.DiscussionID', 'count', 'CountDiscussions')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = d.InsertUserID')->Where('w.CountComments >', 0)->Where('c.InsertUserID', $Session->UserID)->Where('c.InsertUserID <>', 'd.InsertUserID', TRUE, FALSE)->GroupBy('d.InsertUserID')->Get();
if ($Data->NumRows() > 0) {
$UserData = $Data->FirstRow();
$this->SQL->Update('User')->Set('CountUnreadDiscussions', $UserData->CountDiscussions)->Where('UserID', $UserData->InsertUserID)->Put();
}
$this->UpdateUser($Session->UserID);
if ($Insert) {
$DiscussionModel = new DiscussionModel();
$DiscussionID = GetValue('DiscussionID', $Fields);
$Discussion = $DiscussionModel->GetID($DiscussionID);
// Prepare the notification queue
$ActivityModel = new ActivityModel();
$ActivityModel->ClearNotificationQueue();
// Notify any users who were mentioned in the comment
$Usernames = GetMentions($Fields['Body']);
$UserModel = Gdn::UserModel();
$Story = '[' . $Discussion->Name . "]\n" . ArrayValue('Body', $Fields, '');
$NotifiedUsers = array();
foreach ($Usernames as $Username) {
$User = $UserModel->GetByUsername($Username);
if ($User && $User->UserID != $Session->UserID) {
$NotifiedUsers[] = $User->UserID;
$ActivityID = $ActivityModel->Add($Session->UserID, 'CommentMention', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $User->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
$ActivityModel->QueueNotification($ActivityID, $Story);
}
}
// Notify users who have bookmarked the discussion
$BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
foreach ($BookmarkData->Result() as $Bookmark) {
if (!in_array($Bookmark->UserID, $NotifiedUsers) && $Bookmark->UserID != $Session->UserID) {
$NotifiedUsers[] = $Bookmark->UserID;
$ActivityModel = new ActivityModel();
$ActivityID = $ActivityModel->Add($Session->UserID, 'BookmarkComment', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $Bookmark->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
$ActivityModel->QueueNotification($ActivityID, $Story);
}
}
// Record user-comment activity
if ($Discussion !== FALSE && !in_array($Session->UserID, $NotifiedUsers)) {
$this->RecordActivity($ActivityModel, $Discussion, $Session->UserID, $CommentID, FALSE);
$ActivityModel->QueueNotification($ActivityID, $Story);
}
// Send all notifications
$ActivityModel->SendNotificationQueue();
}
}
示例2: Save2
/**
* Insert or update meta data about the comment.
*
* Updates unread comment totals, bookmarks, and activity. Sends notifications.
*
* @since 2.0.0
* @access public
*
* @param array $CommentID Unique ID for this comment.
* @param int $Insert Used as a boolean for whether this is a new comment.
* @param bool $CheckExisting Not used.
* @param bool $IncUser Whether or not to just increment the user's comment count rather than recalculate it.
*/
public function Save2($CommentID, $Insert, $CheckExisting = TRUE, $IncUser = FALSE)
{
$Session = Gdn::Session();
// Load comment data
$Fields = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
// Clear any session stashes related to this discussion
$Session->Stash('CommentForDiscussionID_' . GetValue('DiscussionID', $Fields));
// Make a quick check so that only the user making the comment can make the notification.
// This check may be used in the future so should not be depended on later in the method.
if ($Fields['InsertUserID'] != $Session->UserID) {
return;
}
// Update the discussion author's CountUnreadDiscussions (ie.
// the number of discussions created by the user that s/he has
// unread messages in) if this comment was not added by the
// discussion author.
// $Data = $this->SQL
// ->Select('d.InsertUserID')
// ->Select('d.DiscussionID', 'count', 'CountDiscussions')
// ->From('Discussion d')
// ->Join('Comment c', 'd.DiscussionID = c.DiscussionID')
// ->Join('UserDiscussion w', 'd.DiscussionID = w.DiscussionID and w.UserID = d.InsertUserID')
// ->Where('w.CountComments >', 0)
// ->Where('c.InsertUserID', $Session->UserID)
// ->Where('c.InsertUserID <>', 'd.InsertUserID', TRUE, FALSE)
// ->GroupBy('d.InsertUserID')
// ->Get();
//
// if ($Data->NumRows() > 0) {
// $UserData = $Data->FirstRow();
// $this->SQL
// ->Update('User')
// ->Set('CountUnreadDiscussions', $UserData->CountDiscussions)
// ->Where('UserID', $UserData->InsertUserID)
// ->Put();
// }
$this->UpdateUser($Session->UserID, $IncUser && $Insert);
if ($Insert) {
$DiscussionModel = new DiscussionModel();
$DiscussionID = GetValue('DiscussionID', $Fields);
$Discussion = $DiscussionModel->GetID($DiscussionID);
// UPDATE COUNT AND LAST COMMENT ON CATEGORY TABLE
if ($Discussion->CategoryID > 0) {
$CountComments = $this->SQL->Select('CountComments', 'sum', 'CountComments')->From('Discussion')->Where('CategoryID', $Discussion->CategoryID)->Get()->FirstRow()->CountComments;
$CategoryModel = new CategoryModel();
$CategoryModel->SetField($Discussion->CategoryID, array('LastDiscussionID' => $Discussion->DiscussionID, 'LastCommentID' => $Discussion->LastCommentID, 'CountComments' => $CountComments));
// Update the cache.
if ($DiscussionID && Gdn::Cache()->ActiveEnabled()) {
$CategoryCache = array('LastDiscussionID' => $DiscussionID, 'LastCommentID' => $CommentID, 'LastTitle' => $Discussion->Name, 'LastUserID' => $Fields['InsertUserID'], 'LastDateInserted' => $Fields['DateInserted'], 'LastUrl' => "/discussion/comment/{$CommentID}#Comment_{$CommentID}");
CategoryModel::SetCache($Discussion->CategoryID, $CategoryCache);
}
}
// Prepare the notification queue.
$ActivityModel = new ActivityModel();
$ActivityModel->ClearNotificationQueue();
// Notify any users who were mentioned in the comment.
$Usernames = GetMentions($Fields['Body']);
$UserModel = Gdn::UserModel();
$Story = '[' . $Discussion->Name . "]\n" . ArrayValue('Body', $Fields, '');
$NotifiedUsers = array();
foreach ($Usernames as $Username) {
$User = $UserModel->GetByUsername($Username);
// Check user can still see the discussion.
$UserMayView = $UserModel->GetCategoryViewPermission($User->UserID, $Discussion->CategoryID);
if ($User && $User->UserID != $Session->UserID && $UserMayView) {
$NotifiedUsers[] = $User->UserID;
$ActivityID = $ActivityModel->Add($Session->UserID, 'CommentMention', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $User->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
$ActivityModel->QueueNotification($ActivityID, $Story);
}
}
// Notify users who have bookmarked the discussion.
$BookmarkData = $DiscussionModel->GetBookmarkUsers($DiscussionID);
foreach ($BookmarkData->Result() as $Bookmark) {
if (in_array($Bookmark->UserID, $NotifiedUsers) || $Bookmark->UserID == $Session->UserID) {
continue;
}
// Check user can still see the discussion.
$UserMayView = $UserModel->GetCategoryViewPermission($Bookmark->UserID, $Discussion->CategoryID);
if ($UserMayView) {
$NotifiedUsers[] = $Bookmark->UserID;
// $ActivityModel = new ActivityModel();
$ActivityID = $ActivityModel->Add($Session->UserID, 'BookmarkComment', Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID), $Bookmark->UserID, '', 'discussion/comment/' . $CommentID . '/#Comment_' . $CommentID, FALSE);
$ActivityModel->QueueNotification($ActivityID, $Story);
}
}
// Record user-comment activity.
if ($Discussion !== FALSE && !in_array($Session->UserID, $NotifiedUsers)) {
//.........这里部分代码省略.........
示例3: RecordAdvancedNotications
/**
* Record advanced notifications for users.
*
* @param ActivityModel $ActivityModel
* @param array $Discussion
* @param int $CommentID
* @param array $NotifiedUsers
*/
public function RecordAdvancedNotications($ActivityModel, $Discussion, $Comment, &$NotifiedUsers)
{
// Grab all of the users that need to be notified.
$Data = $this->SQL->GetWhere('UserMeta', array('Name' => 'Preferences.Email.NewDiscussion'))->ResultArray();
// Grab all of their follow/unfollow preferences.
$UserIDs = ConsolidateArrayValuesByKey($Data, 'UserID');
$CategoryID = GetValue('CategoryID', $Discussion);
$UserPrefs = $this->SQL->Select('*')->From('UserCategory')->Where('CategoryID', $CategoryID)->WhereIn('UserID', $UserIDs)->Get()->ResultArray();
$UserPrefs = Gdn_DataSet::Index($UserPrefs, 'UserID');
$CommentID = $Comment['CommentID'];
foreach ($UserIDs as $UserID) {
// if ($UserID == $Comment['InsertUserID'])
// continue;
if (in_array($UserID, $NotifiedUsers)) {
continue;
}
if (array_key_exists($UserID, $UserPrefs) && $UserPrefs[$UserID]['Unfollow']) {
continue;
}
$ActivityID = AddActivity($Comment['InsertUserID'], 'NewComment', Gdn_Format::Text(Gdn_Format::To($Comment['Body'], $Comment['Format'])), $UserID, "/discussion/comment/{$CommentID}#Comment_{$CommentID}", TRUE);
$ActivityModel->QueueNotification($ActivityID);
$NotifiedUsers[] = $UserID;
}
}