예제 #1
0
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::update()
  */
 public function update()
 {
     $this->requireParameter("id");
     $stockEntry = StockEntry::loadById($this->getParameter("id"));
     if (!SessionManager::getCurrentSession()->getUser()->isAdmin() && !(SessionManager::getCurrentSession()->getUser() && $stockEntry->getUser() && SessionManager::getCurrentSession()->getUser()->getId() == $stockEntry->getUser()->getId())) {
         throw new \Exception("Permission denied");
     }
     /* It's not allowed to edit a price for a removal */
     if (!$stockEntry->isRemoval()) {
         $stockEntry->setPrice(abs($this->getParameter("price")));
     }
     /**
      * Only an admin user may correct the in&out stock levels
      */
     if (SessionManager::getCurrentSession()->getUser()->isAdmin()) {
         if ($this->getParameter("direction") == "out") {
             $stockEntry->setStockLevel(-abs($this->getParameter("stockLevel")));
         } else {
             $stockEntry->setStockLevel($this->getParameter("stockLevel"));
         }
     }
     if (SessionManager::getCurrentSession()->getUser()->isAdmin()) {
         try {
             $stockEntry->setUser(User::loadById($this->getParameter("user_id")));
         } catch (\Exception $e) {
             $stockEntry->setUser(null);
         }
     }
     $stockEntry->setComment($this->getParameter("comment"));
     PartKeepr::getEM()->flush();
     return array("data" => $stockEntry->serialize());
 }
 /**
  * Deletes a key-value combination from the database.
  * 
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::destroy()
  */
 public function destroy()
 {
     if ($this->hasParameter("user_id") && SessionManager::getCurrentSession()->getUser()->isAdmin()) {
         UserPreference::deletePreference(User::loadById($this->getParameter("user_id")), $this->getParameter("key"));
     } else {
         UserPreference::deletePreference($this->getUser(), $this->getParameter("key"));
     }
 }
예제 #3
0
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::create()
  */
 public function create()
 {
     $entity = PartManager::getInstance()->createEntity($this->getParameters());
     if ($this->getParameter("initialStockLevel") > 0) {
         try {
             $user = User::loadById($this->getParameter("initialStockLevelUser"));
         } catch (\Exception $e) {
             $user = SessionManager::getCurrentSession()->getUser();
         }
         $stock = new StockEntry($entity, intval($this->getParameter("initialStockLevel")), $user);
         if ($this->getParameter("initialStockLevelPricePerItem") == true) {
             $price = floatval($this->getParameter("initialStockLevelPrice"));
         } else {
             $price = floatval($this->getParameter("initialStockLevelPrice")) / $this->getParameter("initialStockLevel");
         }
         if ($price != 0) {
             $stock->setPrice($price);
         }
         PartKeepr::getEM()->persist($stock);
         PartKeepr::getEM()->flush();
         $entity->updateStockLevel();
         PartKeepr::getEM()->flush();
     }
     return array("data" => $entity->serialize());
 }
예제 #4
0
 /**
  * Deletes an user by id
  * @param int $id The user's id
  */
 public function deleteUser($id)
 {
     $user = User::loadById($id);
     PartKeepr::getEM()->remove($user);
     PartKeepr::getEM()->flush();
 }