Exemplo n.º 1
0
 /**
  * Deletes the package with given id.
  *
  * @param string $id
  *
  * @throws NonExistentIdApiException
  */
 public function delete($id)
 {
     $result = $this->connectToStorageInternalWorker->connect()->remove(array('id' => $id));
     if ($result['n'] == 0) {
         throw new NonExistentIdApiException();
     }
 }
Exemplo n.º 2
0
 /**
  * Picks the package with given id.
  *
  * @param string $id
  *
  * @return array An array with the following keys:
  *               id, name, category, amount and price
  *
  * @throws NonExistentIdInternalException
  */
 public function pick($id)
 {
     $package = $this->connectToStorageInternalWorker->connect()->findOne(['id' => $id], ['_id' => 0]);
     if (!$package) {
         throw new NonExistentIdInternalException($id);
     }
     return $package;
 }
Exemplo n.º 3
0
 /**
  * Creates a package.
  *
  * @param string $id
  * @param string $name
  * @param string $category
  * @param int    $amount
  * @param int    $price
  *
  * @throws NonExistentCategoryInternalException
  */
 public function create($id, $name, $category, $amount, $price)
 {
     try {
         $this->pickCategoryInternalWorker->pick($category);
     } catch (NonExistentCategoryInternalException $e) {
         throw $e;
     }
     $this->connectToStorageInternalWorker->connect()->insert(array('id' => $id, 'name' => $name, 'category' => $category, 'amount' => (int) $amount, 'price' => (int) $price));
 }
Exemplo n.º 4
0
 /**
  * Updates the package with given code.
  *
  * @param string $id
  * @param string $name
  * @param string $category
  * @param int    $amount
  * @param int    $price
  *
  * @throws NonExistentCategoryApiException
  * @throws NonExistentIdApiException
  */
 public function update($id, $name, $category, $amount, $price)
 {
     try {
         $this->pickCategoryInternalWorker->pick($category);
     } catch (NonExistentCategoryApiException $e) {
         throw $e;
     }
     $result = $this->connectToStorageInternalWorker->connect()->update(array('id' => $id), array('$set' => array('name' => $name, 'category' => $category, 'amount' => (int) $amount, 'price' => (int) $price)));
     if ($result['n'] == 0) {
         throw new NonExistentIdApiException();
     }
 }
Exemplo n.º 5
0
 /**
  * Collect packages.
  *
  * @return \Iterator An array of packages with the following keys:
  *                   id, name, category, amount and price
  */
 public function collect()
 {
     return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0])->sort(['amount' => 1, 'price' => 1]);
 }