Beispiel #1
0
 /**
  * Used to start/finish adding a link between a system and an owner
  * Optionally add a new system using the Systems model class
  *
  * @param array $options
  */
 public function sysaddAction($options)
 {
     // get system object
     $system = new \Videogames\Model\Systems();
     if (isset($_POST) && sizeof($_POST) > 0 && isset($_POST['own_id'])) {
         if (!isset($_POST['sys_id']) || $_POST['sys_id'] == '0') {
             if (!isset($_POST['sys_long']) || !isset($_POST['sys_short'])) {
                 $this->errorMsg['error_msg'] = "No system passed!";
                 $this->render($this->errorPage, $this->errorMsg, $this->stdHeader);
                 exit;
             }
             // Check if a system is known with given code
             $temp = $system->getSystemByCode($_POST['sys_short']);
             // No system exists, then add it
             if ($temp === false) {
                 $system->add($_POST);
                 $sys_id = \Videogames\Db::getInstance()->lastInsertId();
             } else {
                 // otherwise use this system (for now give an error)
                 // $sys_id = $temp['sys_id'];
                 $this->errorMsg['error_msg'] = "Abbreviation " . $_POST['sys_short'] . " already exsists!";
                 $this->render($this->errorPage, $this->errorMsg, $this->stdHeader);
                 exit;
             }
         } else {
             $sys_id = $_POST['sys_id'];
         }
         $own_id = $_POST['own_id'];
         if ($this->data->addSystem(['own_id' => $own_id, 'sys_id' => $sys_id])) {
             header("Location: /owner/syslist/" . $own_id);
             exit;
         } else {
             $this->errorMsg['error_msg'] = "Add failed.";
             $this->render($this->errorPage, $this->errorMsg, $this->stdHeader);
             exit;
         }
     }
     if (!isset($options['own_id']) || empty($options['own_id'])) {
         $this->errorMsg['error_msg'] = "No owner ID passed!";
         $this->render($this->errorPage, $this->errorMsg, $this->stdHeader);
         exit;
     }
     $owner = $this->data->getOwner($options['own_id']);
     if ($owner === false) {
         $this->errorMsg['error_msg'] = "Owner not found!";
         $this->render($this->errorPage, $this->errorMsg, $this->stdHeader);
         exit;
     }
     $systems = $system->getAllSystems();
     $sysown = $this->data->getSystems($options['own_id']);
     $this->render("owner/addsystem.phtml", ['owner' => $owner, 'systems' => $systems, 'sysown' => $sysown], $this->stdHeader);
 }
Beispiel #2
0
 /**
  * Count number of games for a system
  *
  * @param int $sys_id
  *
  * @return int Number of game rows
  */
 public function countGames($sys_id)
 {
     $sql = "SELECT COUNT(*) FROM game\n                WHERE sys_id = :sys_id";
     $values = [':sys_id' => $sys_id];
     $query = \Videogames\Db::getInstance()->prepare($sql);
     $query->execute($values);
     return $query->fetchColumn();
 }
Beispiel #3
0
 /**
  * Delete a sys_own row to unlink a system from an owner
  *
  * @param int $sysown_id
  *
  * @return bool
  */
 public function deleteSystem($sysown_id)
 {
     $sql = "DELETE FROM sys_own WHERE sysown_id = :sysown_id";
     $values = [':sysown_id' => $sysown_id];
     $query = \Videogames\Db::getInstance()->prepare($sql);
     return $query->execute($values);
 }
Beispiel #4
0
 /**
  * Fetch all game rows from 1 system
  *
  * @param int $sys_id
  *            System id
  *
  * @return mixed Array with rows or false
  */
 public function getSystemGames($sys_id)
 {
     $sql = "SELECT * FROM game ga\n                WHERE ga.sys_id = :sys_id\n                ORDER BY ga.sort_title";
     $values = [':sys_id' => $sys_id];
     $query = \Videogames\Db::getInstance()->prepare($sql);
     $query->execute($values);
     return $query->fetchAll();
 }