/** * Updates the resell package with given id. * * @param string $id * @param int $amount * @param int $price * @param string $description * * @throws NonExistentIdApiException */ public function update($id, $amount, $price, $description) { $result = $this->connectToStorageInternalWorker->connect()->update(array('id' => $id), array('$set' => array('amount' => (int) $amount, 'price' => (int) $price, 'description' => $description))); if ($result['n'] == 0) { throw new NonExistentIdApiException(); } }
/** * Deletes the resell 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(); } }
/** * Picks the resell package with given id. * * @param string $id * * @return array A resell package as an array with the following keys: * id, amount, and price. * * @throws NonExistentIdInternalException */ public function pick($id) { $resellPackage = $this->connectToStorageInternalWorker->connect()->findOne(['id' => $id], ['_id' => 0]); if (!$resellPackage) { throw new NonExistentIdInternalException(); } return $resellPackage; }
/** * Collect resell packages, sorted ascending by amount. * * @return \Iterator An array of resell packages with the following keys: * id, amount, price and description */ public function collect() { return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0])->sort(['amount' => 1]); }
/** * Creates a resell package. * * @param string $id * @param int $amount * @param int $price * @param string $description */ public function create($id, $amount, $price, $description) { $this->connectToStorageInternalWorker->connect()->insert(array('id' => $id, 'amount' => (int) $amount, 'price' => (int) $price, 'description' => $description)); }