/**
  * Gets the 5 last Matches for User by ID
  * @param type $id
  * @return MatchList
  */
 public function getMatchList($id)
 {
     $sql = new Sql($this->dbAdapter);
     //Creating WHERE OR Statement!!
     $where = new \Zend\Db\Sql\Where();
     $where->nest()->equalTo('tblmatch.User1', $id)->or->equalTo('tblmatch.User2', $id)->unnest();
     //Inserting Statement into Select with ORDER BY 'Date' DESC and TOP 5
     $select = $sql->select('tblmatch')->where($where)->order('Date DESC')->limit(5);
     $stmt = $sql->prepareStatementForSqlObject($select);
     $result = $stmt->execute();
     if ($result instanceof ResultInterface && $result->isQueryResult() && $result->getAffectedRows()) {
         $array = array();
         $match = new Match();
         $match->user1Name = $this->getUsernameByID($result->current()['User1']);
         $match->user2Name = $this->getUsernameByID($result->current()['User2']);
         $match->exchangeArray($result->current());
         array_push($array, $match);
         // Minus 1 Because we already pushed 1 MatchObject into the Array
         for ($count = $result->count() - 1; $count > 0; $count--) {
             $newResult = $result->next();
             $match = new Match();
             $match->user1Name = $this->getUsernameByID($newResult['User1']);
             $match->user2Name = $this->getUsernameByID($newResult['User2']);
             $match->exchangeArray($newResult);
             array_push($array, $match);
         }
         //Add all Matches to the MatchList
         $matchList = new MatchList();
         $matchList->addMatchesFromTable($array);
         return $matchList;
     }
     return new MatchList();
 }
Пример #2
0
 /**
  * Gets Match by ID
  * @param Integer $id
  * @return Match match
  */
 protected function getMatch($id)
 {
     $sql = new Sql($this->dbAdapter);
     $select = $sql->select('tblmatch');
     $select->where(array('matchID = ?' => $id));
     $stmt = $sql->prepareStatementForSqlObject($select);
     $result = $stmt->execute();
     $match = new Match();
     $match->exchangeArray($result->current());
     return $match;
 }
Пример #3
0
 /**
  * Gets a Match by ID
  * @param type $matchID
  * @return \ShipsUnburned\Model\Table\Match
  */
 protected function getMatch($matchID)
 {
     //REFACTORING NEEDED (SAME EXISTS IN GameTable Class)
     $sql = new Sql($this->dbAdapter);
     $select = $sql->select('tblmatch')->where(array('matchID = ?' => $matchID));
     $stmt = $sql->prepareStatementForSqlObject($select);
     $result = $stmt->execute();
     $match = new Match();
     $match->exchangeArray($result->current());
     return $match;
 }