Ejemplo n.º 1
0
 /**
  * Returns a new ChildNotificationOptionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildNotificationOptionQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildNotificationOptionQuery) {
         return $criteria;
     }
     $query = new ChildNotificationOptionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 public static function subOptionPrice($params, $currentUser, $con)
 {
     $options = NotificationOptionQuery::create()->filterById($params->id)->find($con);
     if (!$options) {
         throw new \Exception('Data tidak ditemukan');
     }
     foreach ($options as $option) {
         $option->delete($con);
     }
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Ejemplo n.º 4
0
 /**
  * Returns the number of related NotificationOption objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related NotificationOption objects.
  * @throws PropelException
  */
 public function countNotificationOptions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collNotificationOptionsPartial && !$this->isNew();
     if (null === $this->collNotificationOptions || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collNotificationOptions) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getNotificationOptions());
         }
         $query = ChildNotificationOptionQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByRole($this)->count($con);
     }
     return count($this->collNotificationOptions);
 }
Ejemplo n.º 5
0
 /**
  * Performs an INSERT on the database, given a NotificationOption or Criteria object.
  *
  * @param mixed               $criteria Criteria or NotificationOption object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(NotificationOptionTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from NotificationOption object
     }
     if ($criteria->containsKey(NotificationOptionTableMap::COL_ID) && $criteria->keyContainsValue(NotificationOptionTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . NotificationOptionTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = NotificationOptionQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }
Ejemplo n.º 6
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see NotificationOption::setDeleted()
  * @see NotificationOption::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(NotificationOptionTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildNotificationOptionQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }