public function save(PlayerStage $stage)
 {
     $query = "UPDATE player_stages SET\n        level_id = ? WHERE level_id = ? AND stage_id = ? AND player_id = ? AND university_id = ?";
     $params = [$stage->getLevel()->getLevelId(), $stage->getLevel()->getLevelId() - 1, $stage->getStage()->getId(), $stage->getPlayer()->getId(), $stage->getUniversity()->getId()];
     $this->db->query($query, $params);
     return $this->db->rows() > 0;
 }
 public function save(University $university)
 {
     $query = "\n            INSERT INTO universities\n            (name, player_id, money, lectures)\n            VALUES (?, ?, ?, ?)\n        ";
     $params = [$university->getName(), $university->getPlayer()->getId(), $university->getMoney(), $university->getLecturues()];
     if ($university->getId()) {
         $query = "UPDATE universities SET\n           name = ?, player_id = ?, money = ?, lectures = ?\n           WHERE id = ?\n           ";
         $params[] = $university->getId();
     }
     $this->db->query($query, $params);
     return $this->db->rows() > 0;
 }
 /**
  * @param $levelId
  * @param $stageId
  * @return bool|StageLevel
  */
 public function getOne($levelId, $stageId)
 {
     $query = "SELECT stage_id, level_id, money_consume, lectures_consume, money_income, lectures_income FROM stage_levels WHERE level_id = ? AND stage_id = ?";
     $this->db->query($query, [$levelId, $stageId]);
     $result = $this->db->row();
     if (empty($result)) {
         return false;
     }
     $this->db->query("SELECT id, name FROM stages WHERE id = ?", [$stageId]);
     $stageResult = $this->db->row();
     $stage = new Stage($stageResult['id'], $stageResult['name']);
     $stageLevel = new StageLevel($stage, $result['level_id'], $result['money_consume'], $result['lectures_consume'], $result['money_income'], $result['lectures_income']);
     return $stageLevel;
 }
 public function save(Player $player)
 {
     $query = "\n            INSERT INTO players (username, password)\n            VALUES (?, ?)\n        ";
     $params = [$player->getUsername(), $player->getPassword()];
     if ($player->getId()) {
         $query = "UPDATE players SET username = ?, password = ? WHERE id = ?";
         $params[] = $player->getId();
     }
     $this->db->query($query, $params);
     return $this->db->rows() > 0;
 }