/** * test grabbing all Notifications **/ public function testGetValidAllNotifications() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("notification"); // create a new notification and insert to into mySQL $notification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent); $notification->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoNotification = Notification::getAllNotifications($this->getPDO(), $this->VALID_notificationId); foreach ($pdoNotification as $note) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("notification")); $this->assertSame($note->getAlertId(), $this->alertLevel->getAlertId()); $this->assertSame($note->getEmailStatus(), $this->VALID_emailStatus); $this->assertEquals($note->getNotificationDateTime(), $this->VALID_notificationDateTime); $this->assertSame($note->getNotificationHandle(), $this->VALID_notificationHandle2); $this->assertSame($note->getNotificationContent(), $this->VALID_notificationContent); } }
<?php session_start(); if (!isset($_SESSION['id'])) { exit; } include "Notification.php"; $id = $_SESSION['id']; $notification = new Notification(); $notification->to_user = $id; $notifications = $notification->getAllNotifications(); if ($notifications) { echo $notification->newcount . "|"; $unseen_ids = array(); while ($object = $notifications->fetch_object()) { if ($object->seen == 0) { $unseen_ids[] = $object->id; } switch ($object->type) { case "friend_request": ?> <li id="notification_<?php echo $object->id; ?> "> <div style="width:350px;padding:5px;"> <a href="profile.php?id=<?php echo $object->from_user; ?> "><img src="<?php
if (empty($notificationId) === false) { $reply->data = Notification::getNotificationByNotificationId($pdo, $notificationId); } else { if (is_bool($emailStatus) === true) { $reply->data = Notification::getNotificationByEmailStatus($pdo, $emailStatus); } else { if (empty($notificationDateTime) === false) { $notificationDateTimeInt = new DateTime(); $notificationDateTimeInt->setTimestamp($notificationDateTime / 1000); $reply->data = Notification::getNotificationByNotificationDateTime($pdo, $notificationDateTimeInt); } else { if (empty($alertId) === false) { $reply->data = Notification::getProductByAlertId($pdo, $alertId); } else { if ($page >= 0) { $notifications = Notification::getAllNotifications($pdo, $page)->toArray(); foreach ($notifications as $index => $notification) { $product = null; $productAlert = ProductAlert::getProductAlertByAlertId($pdo, $notification->getAlertId()); if ($productAlert !== null) { $product = Product::getProductByProductId($pdo, $productAlert->getProductId()); } $notifications[$index] = json_decode(json_encode($notification)); $notifications[$index]->product = $product; } $reply->data = $notifications; } else { throw new InvalidArgumentException("no parameters given", 405); } } }