Online.class.php 1.36 KB
Newer Older
Robin Borgogno's avatar
Robin Borgogno committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?php

class Online extends Model {

   // ===========
   // = Statics =
   // ===========
   protected static $table_name = 'ONLINE';

   public static function addUserOnline($values)
   {
       $stm = parent::exec('ONLINE_ADD',$values);
       return ;
   }

   public static function returnUserOnline($id)
   {
        $stm = parent::exec('ONLINE_IDMIN');
        $res = $stm->fetchAll();
        $idmin = $res[0]->USER_ID;
        if($id == $idmin){
            $game = Online::getIdGame();
            if(count($game) == 1){
                Online::deleteUserOnline(array(":id" => $id));
                Game::addUserGame(array(":GAME_ID" => $game[0]->GAME_ID, ":USER_ID" => $id));
                return $game[0]->GAME_ID;
            }
            else {
                $idgame = Game::createGame(array( ":GAME_DESC" => "Desc", ":private" => "0"));
                Online::deleteUserOnline(array(":id" => $id));
                Game::addUserGame(array(":GAME_ID" => $idgame[0]->id, ":USER_ID" => $id));
                return $idgame[0]->id;
                
            }
        }else {
            return;
        }
   }

   public static function deleteUserOnline($values)
   {
       $stm = parent::exec('ONLINE_DELETE',$values);
       return;
   }

   public static function getIdGame()
   {
       $stm = parent::exec('ONLINE_IDGAME');
       return $stm->fetchAll();
   }

}