Beispiel #1
0
 private static function newPriceNotification($stock, $purchaseDetail, $con)
 {
     // check price change
     $priceDifference = $stock->getBuy() - $purchaseDetail->getTotalPrice() / $purchaseDetail->getAmount();
     if ($priceDifference == 0) {
         $priceStatus = 'stagnant';
     } elseif ($priceDifference < 0) {
         $priceStatus = 'up';
     } elseif ($priceDifference > 0) {
         $priceStatus = 'down';
     }
     // if price is not stagnant then make new notification
     if ($priceStatus != 'stagnant') {
         // build up notification data
         $notificationData = new \stdClass();
         $notificationData->stock_id = $stock->getId();
         $notificationData->status = $priceStatus;
         $notificationData->difference = abs($priceDifference);
         $notificationData->to_price = $stock->getBuy() - $priceDifference;
         // update stock buy price
         $stock->setBuy($notificationData->to_price)->save($con);
         // check whether price notification for this purchase detail is already there
         $oldNotification = $purchaseDetail->getNotification();
         if ($oldNotification) {
             // if yes, assign the old one
             $isNew = false;
             $notification = $oldNotification;
         } else {
             // if not, create new notification
             $isNew = true;
             $notification = new Notification();
         }
         $notification->setTime(time())->setType('price')->setData(json_encode($notificationData))->save($con);
         // if notification is new, then give notification to user
         // if not, then update notification's status to unread
         if ($isNew == true) {
             // find which role to send notification
             $roles = NotificationOptionQuery::create()->filterByType('price')->find($con);
             // iterate through each role to find users assigned to it
             foreach ($roles as $role) {
                 $users = UserQuery::create()->filterByStatus('Active')->filterByRoleId($role->getRoleId())->find($con);
                 // iterate through each user to give notification
                 foreach ($users as $user) {
                     $notifyUser = new NotificationOnUser();
                     $notifyUser->setUserId($user->getId())->setNotificationId($notification->getId())->save($con);
                 }
             }
         } else {
             $notifyUsers = NotificationOnUserQuery::create()->filterByNotificationId($notification->getId())->find($con);
             foreach ($notifyUsers as $notifyUser) {
                 $notifyUser->setStatus('Unread')->save($con);
             }
         }
         $notificationId = $notification->getId();
     } else {
         $notificationId = 0;
     }
     return $notificationId;
 }
Beispiel #2
0
 /**
  * Filter the query by a related \ORM\NotificationOnUser object
  *
  * @param \ORM\NotificationOnUser|ObjectCollection $notificationOnUser  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildUserQuery The current query, for fluid interface
  */
 public function filterByNotification($notificationOnUser, $comparison = null)
 {
     if ($notificationOnUser instanceof \ORM\NotificationOnUser) {
         return $this->addUsingAlias(UserTableMap::COL_ID, $notificationOnUser->getUserId(), $comparison);
     } elseif ($notificationOnUser instanceof ObjectCollection) {
         return $this->useNotificationQuery()->filterByPrimaryKeys($notificationOnUser->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByNotification() only accepts arguments of type \\ORM\\NotificationOnUser or Collection');
     }
 }
Beispiel #3
0
 /**
  * @param ChildNotificationOnUser $onUser The ChildNotificationOnUser object to add.
  */
 protected function doAddOnUser(ChildNotificationOnUser $onUser)
 {
     $this->collOnUsers[] = $onUser;
     $onUser->setNotification($this);
 }
Beispiel #4
0
 /**
  * @param ChildNotificationOnUser $notification The ChildNotificationOnUser object to add.
  */
 protected function doAddNotification(ChildNotificationOnUser $notification)
 {
     $this->collNotifications[] = $notification;
     $notification->setUser($this);
 }