/**
  * @return University[]
  */
 public function getAll()
 {
     $query = "SELECT id, name, player_id, money, lectures\n        FROM universities";
     $this->db->query($query);
     $result = $this->db->fetchAll();
     $collection = [];
     foreach ($result as $row) {
         $player = PlayerRepository::create()->getOne($row['player_id']);
         $collection[] = new University($row['id'], $row['name'], $player, $row['money'], $row['lectures']);
     }
     return $collection;
 }
 protected function onLoad()
 {
     if (!isset($_SESSION['userid'])) {
         $this->redirect('users', 'login');
     }
     if ($this->currentPlayer == null) {
         $this->currentPlayer = PlayerRepository::create()->getOne($_SESSION['userid']);
     }
     if ($this->currentUniversity == null) {
         $this->currentUniversity = UniversityRepository::create()->getOne($_SESSION['university_id']);
     }
     $this->view->playerName = $this->currentPlayer->getUsername();
     $this->view->university = $this->currentUniversity;
     $this->view->partial('authHeader');
 }
 public function login()
 {
     $this->view->error = false;
     $this->view->user = false;
     if (isset($_POST['login'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $player = PlayerRepository::create()->getOneByDetails($username, $password);
         if (!$player) {
             $this->view->error = 'Invalid details';
             return;
         }
         $_SESSION['userid'] = $player->getId();
         $_SESSION['university_id'] = $player->getUniversities()[0]->getId();
         $this->view->user = $player->getUsername();
         $this->redirect('game');
     }
 }
Ejemplo n.º 4
0
 public function save()
 {
     return PlayerRepository::create()->save($this);
 }