Example #1
0
 /**
  * Deletes the category 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();
     }
 }
Example #2
0
 /**
  * Updates the category with given id.
  *
  * @param string $id
  * @param string $name
  * @param int    $utility
  *
  * @throws NonExistentIdApiException
  */
 public function update($id, $name, $utility)
 {
     $result = $this->connectToStorageInternalWorker->connect()->update(array('id' => $id), array('$set' => array('name' => $name, 'utility' => (int) $utility)));
     if ($result['n'] == 0) {
         throw new NonExistentIdApiException();
     }
 }
 /**
  * Picks the category with given id.
  *
  * @param string $id
  *
  * @return array An array with the following keys:
  *               id, name and utility
  *
  * @throws NonExistentIdInternalException
  */
 public function pick($id)
 {
     $category = $this->connectToStorageInternalWorker->connect()->findOne(['id' => $id], ['_id' => 0]);
     if (!$category) {
         throw new NonExistentIdInternalException($id);
     }
     return $category;
 }
 /**
  * Collects categories.
  *
  * @return \Iterator An array of categories with the following keys:
  *                   id, name and utility
  */
 public function collect()
 {
     return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]);
 }
 /**
  * Creates a category.
  *
  * @param string $id
  * @param string $name
  * @param int    $utility
  *
  * @throws \MongoCursorException
  */
 public function create($id, $name, $utility)
 {
     $this->connectToStorageInternalWorker->connect()->insert(array('id' => $id, 'name' => $name, 'utility' => $utility));
 }