本文整理汇总了PHP中ActivityModel::GetNotificationsSince方法的典型用法代码示例。如果您正苦于以下问题:PHP ActivityModel::GetNotificationsSince方法的具体用法?PHP ActivityModel::GetNotificationsSince怎么用?PHP ActivityModel::GetNotificationsSince使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActivityModel
的用法示例。
在下文中一共展示了ActivityModel::GetNotificationsSince方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: InformNotifications
/**
* Grabs all new notifications and adds them to the sender's inform queue.
*
* This method gets called by dashboard's hooks file to display new
* notifications on every pageload.
*
* @since 2.0.18
* @access public
*
* @param object $Sender The object calling this method.
*/
public static function InformNotifications($Sender)
{
$Session = Gdn::Session();
if (!$Session->IsValid()) {
return;
}
// Set the user's DateLastInform attribute to now. This value can be used
// by addons to determine if their inform messages have already been sent.
$InformLastActivityID = $Session->GetAttribute('Notifications.InformLastActivityID', 0);
// Allow pluggability
$Sender->EventArguments['InformLastActivityID'] =& $InformLastActivityID;
$Sender->FireEvent('BeforeInformNotifications');
// Retrieve default preferences
$Preferences = array();
$DefaultPreferences = C('Preferences.Popup', array());
foreach ($DefaultPreferences as $Preference => $Val) {
if ($Val) {
$Preferences[] = $Preference;
}
}
// $User = Gdn::Database()->SQL()->Select('Preferences')->From('User')->Where('UserID', $Session->UserID)->Get()->FirstRow();
// if ($User) {
// $PrefData = Gdn_Format::Unserialize($User->Preferences);
// foreach ($PrefData as $Pref => $Val) {
// if (substr($Pref, 0, 6) == 'Popup.') {
// $Pref = substr($Pref, 6);
// if ($Val) {
// $Preferences[] = $Pref;
// } else {
// if (in_array($Pref, $Preferences))
// unset($Preferences[array_search($Pref, $Preferences)]);
// }
// }
// }
// }
// if (count($Preferences) > 0) {
// Grab the activity type ids for the desired notification prefs.
$ActivityTypeIDs = array();
// $ActivityTypes = array();
$Data = Gdn::Database()->SQL()->GetWhere('ActivityType', array('Notify' => TRUE))->ResultArray();
// ->WhereIn('Name', $Preferences)->Get();
foreach ($Data as $ActivityType) {
if (Gdn::Session()->GetPreference("Popup.{$ActivityType['Name']}", C("Preferences.Popup.{$ActivityType['Name']}", TRUE))) {
$ActivityTypeIDs[] = $ActivityType['ActivityTypeID'];
// $ActivityTypes[] = $ActivityType['Name'];
}
}
if (count($ActivityTypeIDs) > 0) {
// Retrieve new notifications
$ActivityModel = new ActivityModel();
$NotificationData = $ActivityModel->GetNotificationsSince($Session->UserID, $InformLastActivityID, $ActivityTypeIDs);
$InformLastActivityID = -1;
// Add (no more than 5) notifications to the inform stack
foreach ($NotificationData->Result() as $Notification) {
// Make sure the user wants to be notified of this
// if (!in_array($Notification->ActivityType, $Preferences)) {
// continue;
// }
$UserPhoto = UserPhoto(UserBuilder($Notification, 'Activity'), 'Icon');
$ActivityType = explode(' ', $Notification->ActivityType);
$ActivityType = $ActivityType[0];
$Excerpt = $Notification->Story;
if (in_array($ActivityType, array('WallComment', 'AboutUpdate'))) {
$Excerpt = Gdn_Format::Display($Excerpt);
}
// Inform the user of new messages
$Sender->InformMessage($UserPhoto . Wrap(Gdn_Format::ActivityHeadline($Notification, $Session->UserID), 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . ($UserPhoto == '' ? '' : ' HasIcon'));
// Assign the most recent activity id
if ($InformLastActivityID == -1) {
$InformLastActivityID = $Notification->ActivityID;
}
}
}
// }
if ($InformLastActivityID > 0) {
Gdn::UserModel()->SaveAttribute($Session->UserID, 'Notifications.InformLastActivityID', $InformLastActivityID);
}
}