示例#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
 /**
  * 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]);
 }