コード例 #1
0
 /**
  * Marks the card as consumed.
  *
  * @param string $code
  *
  * @throws NonExistentCodeInternalException
  */
 public function punch($code)
 {
     $result = $this->connectToStorageInternalWorker->connect()->update(array('code' => $code), array('$set' => array('consumed' => true)));
     if ($result['n'] == 0) {
         throw new NonExistentCodeInternalException($code);
     }
 }
コード例 #2
0
 /**
  * Picks the card with given code.
  *
  * @param string $code
  *
  * @return array An array with the following keys:
  *               code, category and consumed.
  *
  * @throws NonExistentCodeInternalException
  */
 public function pick($code)
 {
     $card = $this->connectToStorageInternalWorker->connect()->findOne(['code' => $code], ['_id' => 0]);
     if (!$card) {
         throw new NonExistentCodeInternalException($code);
     }
     return $card;
 }
コード例 #3
0
 /**
  * Generates a code, verifying that no card use it.
  *
  * @return string
  */
 private function generateCode()
 {
     $code = $this->codeGenerator->generate();
     while ($this->connectToStorageInternalWorker->connect()->findOne(array('code' => $code))) {
         $code = $this->codeGenerator->generate();
     }
     return $code;
 }
コード例 #4
0
ファイル: CreateCardTestWorker.php プロジェクト: nabelhm/api
 /**
  * Creates a card.
  *
  * @param string $code
  * @param string $category
  * @param string $consumed
  */
 public function create($code, $category, $consumed)
 {
     $this->connectToStorageInternalWorker->connect()->insert(array('code' => $code, 'category' => $category, 'consumed' => $consumed));
 }
コード例 #5
0
 /**
  * Collects cards.
  */
 public function collect()
 {
     return $this->connectToStorageInternalWorker->connect()->find()->fields(['_id' => 0]);
 }