本文整理汇总了PHP中ActivityModel::Queue方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivityModel::Queue方法的具体用法?PHP ActivityModel::Queue怎么用?PHP ActivityModel::Queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityModel
的用法示例。
在下文中一共展示了ActivityModel::Queue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Award
/**
* Award a badge to a user and record some activity
*
* @param int $BadgeID
* @param int $UserID This is the user that should get the award
* @param int $InsertUserID This is the user that gave the award
* @param string $Reason This is the reason the giver gave with the award
*/
public function Award($BadgeID, $UserID, $InsertUserID = NULL, $Reason = '')
{
$Badge = Yaga::BadgeModel()->GetByID($BadgeID);
if (!empty($Badge)) {
if (!$this->Exists($UserID, $BadgeID)) {
$this->SQL->Insert('BadgeAward', array('BadgeID' => $BadgeID, 'UserID' => $UserID, 'InsertUserID' => $InsertUserID, 'Reason' => $Reason, 'DateInserted' => date(DATE_ISO8601)));
// Record the points for this badge
UserModel::GivePoints($UserID, $Badge->AwardValue, 'Badge');
// Increment the user's badge count
$this->SQL->Update('User')->Set('CountBadges', 'CountBadges + 1', FALSE)->Where('UserID', $UserID)->Put();
if (is_null($InsertUserID)) {
$InsertUserID = Gdn::Session()->UserID;
}
// Record some activity
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'BadgeAward', 'ActivityUserID' => $UserID, 'RegardingUserID' => $InsertUserID, 'Photo' => $Badge->Photo, 'RecordType' => 'Badge', 'RecordID' => $BadgeID, 'Route' => '/badges/detail/' . $Badge->BadgeID . '/' . Gdn_Format::Url($Badge->Name), 'HeadlineFormat' => T('Yaga.Badge.EarnedHeadlineFormat'), 'Data' => array('Name' => $Badge->Name), 'Story' => $Badge->Description);
// Create a public record
$ActivityModel->Queue($Activity, FALSE);
// TODO: enable the grouped notifications after issue #1776 is resolved , array('GroupBy' => 'Route'));
// Notify the user of the award
$Activity['NotifyUserID'] = $UserID;
$ActivityModel->Queue($Activity, 'BadgeAward', array('Force' => TRUE));
// Actually save the activity
$ActivityModel->SaveQueue();
$this->EventArguments['UserID'] = $UserID;
$this->FireEvent('AfterBadgeAward');
}
}
}
示例2: recordAdvancedNotications
/**
* Record advanced notifications for users.
*
* @param ActivityModel $ActivityModel
* @param array $Activity
* @param array $Discussion
* @param array $NotifiedUsers
*/
public function recordAdvancedNotications($ActivityModel, $Activity, $Discussion)
{
if (is_numeric($Discussion)) {
$Discussion = $this->getID($Discussion);
}
$CategoryID = val('CategoryID', $Discussion);
// Figure out the category that governs this notification preference.
$i = 0;
$Category = CategoryModel::categories($CategoryID);
if (!$Category) {
return;
}
while ($Category['Depth'] > 2 && $i < 20) {
if (!$Category || $Category['Archived']) {
return;
}
$i++;
$Category = CategoryModel::categories($Category['ParentCategoryID']);
}
// Grab all of the users that need to be notified.
$Data = $this->SQL->whereIn('Name', array('Preferences.Email.NewComment.' . $Category['CategoryID'], 'Preferences.Popup.NewComment.' . $Category['CategoryID']))->get('UserMeta')->resultArray();
$NotifyUsers = array();
foreach ($Data as $Row) {
if (!$Row['Value']) {
continue;
}
$UserID = $Row['UserID'];
// Check user can still see the discussion.
if (!Gdn::userModel()->GetCategoryViewPermission($UserID, $Category['CategoryID'])) {
continue;
}
$Name = $Row['Name'];
if (strpos($Name, '.Email.') !== false) {
$NotifyUsers[$UserID]['Emailed'] = ActivityModel::SENT_PENDING;
} elseif (strpos($Name, '.Popup.') !== false) {
$NotifyUsers[$UserID]['Notified'] = ActivityModel::SENT_PENDING;
}
}
foreach ($NotifyUsers as $UserID => $Prefs) {
$Activity['NotifyUserID'] = $UserID;
$Activity['Emailed'] = val('Emailed', $Prefs, false);
$Activity['Notified'] = val('Notified', $Prefs, false);
$ActivityModel->Queue($Activity);
}
}
示例3: AddUserToConversation
/**
* Add another user to the conversation.
*
* @since 2.0.0
* @access public
*
* @param int $ConversationID Unique ID of conversation effected.
* @param int $UserID Unique ID of current user.
*/
public function AddUserToConversation($ConversationID, $UserID)
{
if (!is_array($UserID)) {
$UserID = array($UserID);
}
// First define the current users in the conversation
$OldContributorData = $this->GetRecipients($ConversationID);
$OldContributorData = Gdn_DataSet::Index($OldContributorData, 'UserID');
$AddedUserIDs = array();
// Get some information about this conversation
$ConversationData = $this->SQL->Select('LastMessageID')->Select('CountMessages')->From('Conversation')->Where('ConversationID', $ConversationID)->Get()->FirstRow();
// Add the user(s) if they are not already in the conversation
foreach ($UserID as $NewUserID) {
if (!array_key_exists($NewUserID, $OldContributorData)) {
$AddedUserIDs[] = $NewUserID;
$this->SQL->Insert('UserConversation', array('UserID' => $NewUserID, 'ConversationID' => $ConversationID, 'LastMessageID' => $ConversationData->LastMessageID, 'CountReadMessages' => 0, 'DateConversationUpdated' => $ConversationData['DateUpdated']));
} elseif ($OldContributorData[$NewUserID]->Deleted) {
$AddedUserIDs[] = $NewUserID;
$this->SQL->Put('UserConversation', array('Deleted' => 0), array('ConversationID' => $ConversationID, 'UserID' => $NewUserID));
}
}
if (count($AddedUserIDs) > 0) {
$Session = Gdn::Session();
// Update the Contributors field on the conversation
$Contributors = array_unique(array_merge($AddedUserIDs, array_keys($OldContributorData)));
sort($Contributors);
$this->SQL->Update('Conversation')->Set('Contributors', Gdn_Format::Serialize($Contributors))->Where('ConversationID', $ConversationID)->Put();
$ActivityModel = new ActivityModel();
foreach ($AddedUserIDs as $AddedUserID) {
$ActivityModel->Queue(array('ActivityType' => 'AddedToConversation', 'NotifyUserID' => $AddedUserID, 'HeadlineFormat' => T('You were added to a conversation.', '{InsertUserID,user} added {NotifyUserID,you} to a <a href="{Url,htmlencode}">conversation</a>.')), 'ConversationMessage');
}
$ActivityModel->SaveQueue();
$this->UpdateUserUnreadCount($AddedUserIDs);
}
}
示例4: unBan
/**
* Unban a user.
*
* @since 2.1
*
* @param int $UserID
* @param array $Options
*/
public function unBan($UserID, $Options = array())
{
$User = $this->getID($UserID, DATASET_TYPE_ARRAY);
if (!$User) {
throw notFoundException();
}
$Banned = $User['Banned'];
if (!BanModel::isBanned($Banned, BanModel::BAN_MANUAL)) {
throw new Gdn_UserException(t("The user isn't banned.", "The user isn't banned or is banned by some other function."));
}
// Unban the user.
$NewBanned = BanModel::setBanned($Banned, false, BanModel::BAN_MANUAL);
$this->setField($UserID, 'Banned', $NewBanned);
// Restore the user's content.
if (val('RestoreContent', $Options)) {
$BanLogID = $this->getAttribute($UserID, 'BanLogID');
if ($BanLogID) {
$LogModel = new LogModel();
try {
$LogModel->restore($BanLogID);
} catch (Exception $Ex) {
if ($Ex->getCode() != 404) {
throw $Ex;
}
}
$this->saveAttribute($UserID, 'BanLogID', null);
}
}
// Add an activity for the unbanning.
if (val('AddActivity', $Options, true)) {
$ActivityModel = new ActivityModel();
$Story = val('Story', $Options, null);
// Notify the moderators of the unban.
$Activity = array('ActivityType' => 'Ban', 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::session()->UserID, 'HeadlineFormat' => t('HeadlineFormat.Unban', '{RegardingUserID,You} unbanned {ActivityUserID,you}.'), 'Story' => $Story, 'Data' => array('Unban' => true));
$ActivityModel->Queue($Activity);
// Notify the user of the unban.
$Activity['NotifyUserID'] = $UserID;
$Activity['Emailed'] = ActivityModel::SENT_PENDING;
$Activity['HeadlineFormat'] = t('HeadlineFormat.Unban.Notification', "You've been unbanned.");
$ActivityModel->Queue($Activity, false, array('Force' => true));
$ActivityModel->SaveQueue();
}
}
示例5: SaveQueue
public function SaveQueue()
{
$Result = array();
foreach (self::$Queue as $UserID => $Activities) {
foreach ($Activities as $ActivityType => $Row) {
$Result[] = $this->Save($Row[0], FALSE, $Row[1]);
}
}
self::$Queue = array();
return $Result;
}
示例6: NotifyNewDiscussion
/**
*
* @param type $Discussion
* @param type $NotifiedUsers
* @param ActivityModel $ActivityModel
*/
public function NotifyNewDiscussion($Discussion, $ActivityModel, $Activity)
{
if (is_numeric($Discussion)) {
$Discussion = $this->GetID($Discussion);
}
$CategoryID = GetValue('CategoryID', $Discussion);
// Figure out the category that governs this notification preference.
$i = 0;
$Category = CategoryModel::Categories($CategoryID);
if (!$Category) {
return;
}
while ($Category['Depth'] > 2 && $i < 20) {
if (!$Category || $Category['Archived']) {
return;
}
$i++;
$Category = CategoryModel::Categories($Category['ParentCategoryID']);
}
// Grab all of the users that need to be notified.
$Data = $this->SQL->WhereIn('Name', array('Preferences.Email.NewDiscussion.' . $Category['CategoryID'], 'Preferences.Popup.NewDiscussion.' . $Category['CategoryID']))->Get('UserMeta')->ResultArray();
// decho($Data, 'Data');
$NotifyUsers = array();
foreach ($Data as $Row) {
if (!$Row['Value']) {
continue;
}
$UserID = $Row['UserID'];
$Name = $Row['Name'];
if (strpos($Name, '.Email.') !== FALSE) {
$NotifyUsers[$UserID]['Emailed'] = ActivityModel::SENT_PENDING;
} elseif (strpos($Name, '.Popup.') !== FALSE) {
$NotifyUsers[$UserID]['Notified'] = ActivityModel::SENT_PENDING;
}
}
// decho($NotifyUsers);
$InsertUserID = GetValue('InsertUserID', $Discussion);
foreach ($NotifyUsers as $UserID => $Prefs) {
if ($UserID == $InsertUserID) {
continue;
}
$Activity['NotifyUserID'] = $UserID;
$Activity['Emailed'] = GetValue('Emailed', $Prefs, FALSE);
$Activity['Notified'] = GetValue('Notified', $Prefs, FALSE);
$ActivityModel->Queue($Activity);
// decho($Activity, 'die');
}
// die();
}
示例7: UnBan
/**
* Unban a user.
* @since 2.1
* @param int $UserID
* @param array $Options
*/
public function UnBan($UserID, $Options = array())
{
$User = $this->GetID($UserID, DATASET_TYPE_ARRAY);
if (!$User) {
throw NotFoundException();
}
if (!$User['Banned']) {
throw new Gdn_UserException(T("The user isn't banned."));
}
// Unban the user.
$this->SetField($UserID, 'Banned', FALSE);
// Restore the user's content.
if (GetValue('RestoreContent', $Options)) {
$BanLogID = $this->GetAttribute($UserID, 'BanLogID');
if ($BanLogID) {
$LogModel = new LogModel();
try {
$LogModel->Restore($BanLogID);
} catch (Exception $Ex) {
if ($Ex->getCode() != 404) {
throw $Ex;
}
}
$this->SaveAttribute($UserID, 'BanLogID', NULL);
}
}
// Add an activity for the unbanning.
if (GetValue('AddActivity', $Options, TRUE)) {
$ActivityModel = new ActivityModel();
$Story = GetValue('Story', $Options, NULL);
// Notify the moderators of the unban.
$Activity = array('ActivityType' => 'Ban', 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::Session()->UserID, 'HeadlineFormat' => T('HeadlineFormat.Unban', '{RegardingUserID,You} unbanned {ActivityUserID,you}.'), 'Story' => $Story);
$ActivityModel->Queue($Activity);
// Notify the user of the unban.
$Activity['NotifyUserID'] = $UserID;
$Activity['Emailed'] = ActivityModel::SENT_PENDING;
$Activity['HeadlineFormat'] = T('HeadlineFormat.Unban.Notification', "You've been unbanned.");
$ActivityModel->Queue($Activity, FALSE, array('Force' => TRUE));
$ActivityModel->SaveQueue();
}
}
示例8: Set
/**
* Set a user's rank and record some activity if it was a promotion
*
* @param int $RankID
* @param int $UserID This is the user that should get the award
* @param bool $Activity Whether or not to insert an activity record.
*/
public function Set($RankID, $UserID, $Activity = FALSE)
{
$Rank = $this->GetByID($RankID);
if ($Activity) {
// Throw up a promotion activity
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'RankPromotion', 'ActivityUserID' => $UserID, 'RegardingUserID' => $UserID, 'Photo' => C('Yaga.Ranks.Photo'), 'RecordType' => 'Rank', 'RecordID' => $Rank->RankID, 'HeadlineFormat' => T('Yaga.Rank.PromotedHeadlineFormat'), 'Data' => array('Name' => $Rank->Name), 'Story' => $Rank->Description);
// Create a public record
$ActivityModel->Queue($Activity, FALSE);
// TODO: enable the grouped notifications after issue #1776 is resolved , array('GroupBy' => 'Story'));
// Notify the user of the award
$Activity['NotifyUserID'] = $UserID;
$ActivityModel->Queue($Activity, 'RankPromotion', array('Force' => TRUE));
$ActivityModel->SaveQueue();
}
// Update the rank id
$UserModel = Gdn::UserModel();
$OldRankID = $UserModel->GetID($UserID)->RankID;
$UserModel->SetField($UserID, 'RankID', $Rank->RankID);
// Update the roles if necessary
$this->_UpdateUserRoles($UserID, $OldRankID, $Rank->RankID);
$this->EventArguments['Rank'] = $Rank;
$this->EventArguments['UserID'] = $UserID;
$this->FireEvent('AfterRankChange');
}
示例9: saveQueue
/**
*
*
* @return array
*/
public function saveQueue()
{
$Result = [];
foreach (self::$Queue as $UserID => $Activities) {
foreach ($Activities as $ActivityType => $Row) {
$Result[] = $this->save($Row[0], false, $Row[1]);
}
}
self::$Queue = [];
return $Result;
}