/** * 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(); }
public function getOpponentID($matchID, $userID) { $sql = new Sql($this->dbAdapter); $where = new \Zend\Db\Sql\Where(); $where->nest()->equalTo('tblmatch.matchID', $matchID)->unnest(); $select = $sql->select('tblmatch')->where($where); $stmt = $sql->prepareStatementForSqlObject($select); $result = $stmt->execute(); $result = $result->current(); if ($result["User1"] == $userID) { return $result["User2"]; } else { return $result["User1"]; } }
protected function saveNewELOToDatabase($newELO, $userID) { $sql = new Sql($this->dbAdapter); $where = new \Zend\Db\Sql\Where(); $where->nest()->equalTo('tbluser.id', $userID); $update = $sql->update('tbluser')->set(array('ELO' => $newELO))->where($where); $stmt = $sql->prepareStatementForSqlObject($update); $stmt->execute(); }
public function login($name, $password) { $where = new \Zend\Db\Sql\Where(); $where->nest()->equalTo('name', $name)->or->equalTo('email', $name)->unnest()->and->equalTo('password', $password); $select = $this->tableGateway->getSql()->select()->where($where)->limit(1); $result = $this->tableGateway->getSql()->prepareStatementForSqlObject($select)->execute(); $rs = new ResultSet(); $rs->initialize($result); return $rs->toArray(); }