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; }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aUser) { $this->aUser->removeNotification($this); } if (null !== $this->aNotification) { $this->aNotification->removeOnUser($this); } $this->id = null; $this->user_id = null; $this->notification_id = null; $this->status = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Filter the query by a related \ORM\Notification object * * @param \ORM\Notification|ObjectCollection $notification The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildPurchaseDetailQuery The current query, for fluid interface */ public function filterByNotification($notification, $comparison = null) { if ($notification instanceof \ORM\Notification) { return $this->addUsingAlias(PurchaseDetailTableMap::COL_NOTIFICATION_ID, $notification->getId(), $comparison); } elseif ($notification instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(PurchaseDetailTableMap::COL_NOTIFICATION_ID, $notification->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByNotification() only accepts arguments of type \\ORM\\Notification or Collection'); } }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aPurchase) { $this->aPurchase->removeDetail($this); } if (null !== $this->aStock) { $this->aStock->removePurchase($this); } if (null !== $this->aNotification) { $this->aNotification->removePurchaseDetail($this); } $this->id = null; $this->purchase_id = null; $this->stock_id = null; $this->amount = null; $this->total_price = null; $this->notification_id = null; $this->status = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * Exclude object from result * * @param ChildNotification $notification Object to remove from the list of results * * @return $this|ChildNotificationQuery The current query, for fluid interface */ public function prune($notification = null) { if ($notification) { $this->addUsingAlias(NotificationTableMap::COL_ID, $notification->getId(), Criteria::NOT_EQUAL); } return $this; }