/** * Updates a topic. * * @param string $id * @param string $title * @param string $description * @param int $average * @param boolean $active * @param int $order * * @throws NonExistentIdApiException */ public function update($id, $title, $description, $average, $active, $order) { $result = $this->connectToStorageInternalWorker->connect()->update(array('id' => $id), array('$set' => array('title' => $title, 'description' => $description, 'average' => $average, 'active' => $active, 'order' => (int) $order))); if ($result['n'] == 0) { throw new NonExistentIdApiException(); } }
/** * Picks the topic with given id. * * @param string $id * * @return array A topic as an array with the following keys: * id, title, description and average. * * @throws NonExistentIdInternalException */ public function pick($id) { $topic = $this->connectToStorageInternalWorker->connect()->findOne(['id' => $id]); if (!$topic) { throw new NonExistentIdInternalException($id); } return $topic; }
/** * Deletes the topic with given id. * * @param string $id * * @throws NonExistentIdApiException */ public function delete($id) { $result = $this->connectToStorageInternalWorker->connect()->remove(['id' => $id]); if ($result['n'] == 0) { throw new NonExistentIdApiException(); } $this->connectToInfoStorageInternalWorker->connect()->remove(['topics' => $id]); }
/** * Collects topics. * * @return \Iterator */ public function collect() { return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]); }
/** * Creates a topic. * * @param string $id * @param string $title * @param string $description * @param int $average * @param int $order */ public function create($id, $title, $description, $average, $order) { $this->connectToStorageInternalWorker->connect()->insert(array('id' => $id, 'title' => $title, 'description' => $description, 'average' => $average, 'active' => true, 'order' => (int) $order)); }
/** * Collects topics. * * @return \Iterator An array of topics with the following keys: * id, title, description, average, active and order. */ public function collect() { return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0])->sort(['active' => -1, 'order' => 1]); }