public function executeCount(sfWebRequest $request) { $member = $this->getUser()->getMember(); $notifications = opNotificationCenter::getNotifications($member); $this->count = array('link' => 0, 'message' => 0, 'other' => 0); foreach ($notifications as $notification) { if (array_key_exists($notification['category'], $this->count)) { $category = $notification['category']; } else { $category = 'other'; } if ($notification['unread']) { $this->count[$category]++; } } $this->setTemplate('count'); }
//============================================================================== $t->diag('opNotificationCenter::getNotifications()'); $t->info('empty value'); $conn->beginTransaction(); $notifications = opNotificationCenter::getNotifications($member2); $t->ok(is_array($notifications)); $t->is(count($notifications), 0); $conn->rollback(); $t->info('check format'); $conn->beginTransaction(); opNotificationCenter::notify($member1, $member2, 'hogehoge'); $notifications = opNotificationCenter::getNotifications($member2); $t->ok(is_array($notifications)); $t->is(count($notifications), 1); $t->ok(is_string($notifications[0]['id'])); $t->is($notifications[0]['body'], 'hogehoge'); $t->is($notifications[0]['member_id_from'], 1); $t->is($notifications[0]['unread'], true); $t->is($notifications[0]['category'], 'other'); $t->is($notifications[0]['url'], null); $t->is($notifications[0]['icon_url'], null); $conn->rollback(); $t->info('2 notifications'); $conn->beginTransaction(); opNotificationCenter::notify($member1, $member2, 'notify1'); opNotificationCenter::notify($member1, $member2, 'notify2'); $notifications = opNotificationCenter::getNotifications($member2); $t->is(count($notifications), 2); $t->is($notifications[0]['body'], 'notify2'); $t->is($notifications[1]['body'], 'notify1'); $conn->rollback();