本文整理汇总了PHP中Notification::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Notification::getById方法的具体用法?PHP Notification::getById怎么用?PHP Notification::getById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notification
的用法示例。
在下文中一共展示了Notification::getById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReadUnread
public function testReadUnread()
{
$super = User::getByUsername('super');
$billy = User::getByUsername('billy');
Yii::app()->user->userModel = $super;
$this->deleteAllNotifications();
$createdNotification = $this->createAndSaveNewNotificationForUser($super);
$this->assertEquals(1, $this->rules->getUnreadCountForCurrentUser(), 0);
$savedNotification = Notification::getById($createdNotification->id);
$savedNotification->ownerHasReadLatest = 0;
$savedNotification->save();
$this->assertEquals(1, $this->rules->getUnreadCountForCurrentUser(), 0);
//Other users should have 0 unread notifications
Yii::app()->user->userModel = $billy;
$this->assertEquals(0, $this->rules->getUnreadCountForCurrentUser(), 0);
//Mark notification as ready by super
$this->rules->resolveMarkRead($createdNotification->id);
Yii::app()->user->userModel = $super;
$this->assertTrue((bool) $savedNotification->ownerHasReadLatest);
$this->assertTrue((bool) $this->rules->hasCurrentUserReadLatest($createdNotification->id));
$this->rules->resolveMarkUnread($createdNotification->id);
$savedNotification = Notification::getById($createdNotification->id);
$this->assertFalse((bool) $savedNotification->ownerHasReadLatest);
$this->assertFalse((bool) $this->rules->hasCurrentUserReadLatest($createdNotification->id));
}
示例2: resolveRowHtmlOptionsExpression
public static function resolveRowHtmlOptionsExpression($grid, $row, $data)
{
$notification = Notification::getById($data->id);
if (!$notification->ownerHasReadLatest) {
$params = array("class" => 'unread');
return $params;
}
}
示例3: testNotification
/**
* @depends testGetCountByUser
*/
public function testNotification()
{
Yii::app()->user->userModel = User::getByUsername('super');
$notification = new Notification();
$notification->type = 'Simple';
$notification->owner = Yii::app()->user->userModel;
$this->assertTrue($notification->save());
$this->assertTrue($notification->save());
$notificationId = $notification->id;
$notification->forget();
//Retrieve again.
$notification = Notification::getById($notificationId);
$this->assertEquals('Simple', $notification->type);
$notification->delete();
}
示例4: testDeleteByTypeAndUser
/**
* @depends testRelationsBetweenNotificationAndNotificationMessage
*/
public function testDeleteByTypeAndUser()
{
Yii::app()->user->userModel = User::getByUsername('super');
$joe = UserTestHelper::createBasicUser('joe');
$sally = UserTestHelper::createBasicUser('sally');
//Make sure the relations between Notification and NotificationMessage is working.
$message = new NotificationMessage();
$message->textContent = 'text content3';
$message->htmlContent = 'html content3';
$this->assertTrue($message->save());
$notification1 = new Notification();
$notification1->type = 'SimpleDTest';
$notification1->owner = $joe;
$notification1->notificationMessage = $message;
$this->assertTrue($notification1->save());
//And Billy can create a notification for super
$notification2 = new Notification();
$notification2->type = 'SimpleDTest';
$notification2->owner = $sally;
$notification2->notificationMessage = $message;
$this->assertTrue($notification2->save());
$this->assertEquals(2, $message->notifications->count());
$messageId = $message->id;
$notification1Id = $notification1->id;
$notification2Id = $notification2->id;
$message->forget();
$notification1->forget();
$notification2->forget();
Notification::deleteByTypeAndUser('SimpleDTest', $joe);
// Notification message should exist, because there is still notification point to it
$message = NotificationMessage::getById($messageId);
$this->assertTrue($message instanceof NotificationMessage);
$notification2 = Notification::getById($notification2Id);
$this->assertTrue($notification2 instanceof Notification);
$notifications = Notification::getByNotificationMessageId($messageId);
$this->assertEquals(1, count($notifications));
$this->assertEquals($notification2Id, $notifications[0]->id);
try {
Notification::getById($notification1Id);
$this->fail();
} catch (NotFoundException $e) {
}
$message->forget();
$notification2->forget();
// Now delete second notification, this time notification message should be deleted too
Notification::deleteByTypeAndUser('SimpleDTest', $sally);
try {
NotificationMessage::getById($messageId);
$this->fail();
} catch (NotFoundException $e) {
}
try {
Notification::getById($notification2Id);
$this->fail();
} catch (NotFoundException $e) {
}
}