user_id = $user_id; //$this->game_id = $game_id; if (isset($game_id)) $this->set_id($game_id); //see on nii ainult game enda puhul! $this->diary =& new Diary($this); $this->scoring =& new ScoringSystem($this); } /** * Loob uue mängu ja Väljastab selle id. * @return integer $game_id * @access public */ function create_new($label = ' ') { /* //nii saab teha alates 4.0.14 (htk.tpu.ee-s 4.0.13) $sql = "INSERT INTO dsg_game (user_id, game_id, week, label, created) SELECT '{$this->user_id}', COUNT(*)+1, 1, '$label', '".date('Y-m-d H:i:s')."' FROM dsg_game WHERE user_id = '{$this->user_id}' "; */ $game_id = $this->get_db_value("SELECT MAX(game_id)+1 FROM dsg_game WHERE user_id = '{$this->user_id}'"); //echo $game_id ,"\n"; $sql = "INSERT INTO dsg_game (user_id, game_id, week, label, created) VALUES ('{$this->user_id}', '$game_id', 1, '$label', '".date('Y-m-d H:i:s')."') "; $result = $this->exec_sql($sql); //echo $result ,"\n"; /* $sql = "SELECT game_id FROM dsg_game WHERE user_id = '{$this->user_id}' ORDER BY game_id DESC LIMIT 1"; $game_id = $this->get_db_value($sql); */ //init person states... $sql = "INSERT INTO dsg_states (user_id, game_id, person_id) SELECT '{$this->user_id}', '$game_id', person_id FROM dsg_person ORDER BY person_id"; $result = $this->exec_sql($sql); //echo $result ,"\n"; if (!$result) return false; return $game_id; } /** * Koristab andmebaasist kõik konkreetse mänguga seonduva * @return boolean $result * @access public */ function remove() { /* //ok DELETE dsg_game.*, dsg_states.* FROM dsg_game g, dsg_states t WHERE g.user_id = '1' AND g.game_id = '2' AND t.user_id = g.user_id AND t.game_id = g.game_id //enam ei kustuta :( ??? DELETE dsg_game.*, dsg_states.*, dsg_chronology.* FROM dsg_game g, dsg_states t, dsg_chronology c WHERE g.user_id = '1' AND g.game_id = '2' AND t.user_id = g.user_id AND t.game_id = g.game_id AND c.user_id = g.user_id AND c.game_id = g.game_id DELETE dsg_game.*, dsg_chronology.*, dsg_subject.*, dsg_states.* FROM dsg_game g, dsg_chronology c, dsg_subject s, dsg_states t WHERE g.user_id = '{$this->user_id}' AND g.game_id = '{$this->game_id}' AND c.user_id = g.user_id AND c.game_id = g.game_id AND s.user_id = g.user_id AND s.game_id = g.game_id AND t.user_id = g.user_id AND t.game_id = g.game_id */ $result = 0; foreach (array('dsg_game','dsg_chronology','dsg_subject','dsg_states') as $table) { $sql = "DELETE FROM $table WHERE user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' "; $result += $this->exec_sql($sql); } return $result; //mitu kirjet kustutati :-/ } /** * Väljastab kõik kasutaja mängud. * @return array massiiv kasutaja mängudest. * @access public */ function get_items() { $sql = "SELECT game_id, label, week, created FROM dsg_game ". " WHERE user_id = ". $this->user_id; $arr = $this->get_db_records($sql); return $arr; } /** * Määrab missugust mängu objekt esindab. (Initsialiseerib objekti, määrab identiteedi) * * @param integer $id Game' identifikaator. * @access public */ function set_id($id) { $sql = "SELECT COUNT(*) FROM dsg_game ". " WHERE user_id = {$this->user_id} AND game_id = {$id}"; if ($this->get_db_value($sql)) { parent::set_id($id); $this->assign_record("SELECT label, week FROM dsg_game ". " WHERE user_id = {$this->user_id} AND game_id = {$id}"); $this->game_id = $id; //see on nii ainult game enda puhul! return 1; } else return 0; } /** * Väljastab küsitud Action objekti. * @param string $action_id Action'i identifikaator * @param mixed $instance_id valikuline exemprari identifikaator. Kui on ära jäetud väljastatakse * initsialiseerimata objekt * @access public */ function &get_action($action_id, $instance_id = null) { //$sql = "SELECT * FROM dsg_action WHERE action_id = '$action_id' "; $sql = "SELECT class_name FROM dsg_action WHERE action_id = '$action_id' "; $rec = $this->get_db_record($sql); //see tuleks võtta andmebaasist //$classes = array('A'=>'activity', 'P'=>'person', 'R'=>'grouprelation'); //if ($class = @$classes[$action_id]) { if ($class = @$rec['class_name']) { $a =& new $class($this); //$a->assign_vars($rec); //see peaks toimuma Action initsialiseerimisel /construktoris...!!! } else return null; if (is_null($instance_id)) return $a; //taheti initsialiseerimata objekti //tahetakse initsialiseeritud objekti if($a->set_id($instance_id)) //väljastab true/false sõltuvalt kas õnnestus return $a; else return null; //sellist objekti nagu nõutud, ei ole. } /** * Väljastab assotsiatiivmassiivi valitud tüüpi Action'ite identifikaatorite, nimedega ja * muu vajaliku infoga. * @param string $action_id Action'i identifikaator * @return array Massiiv elementidega kujul (id => record), kus record = array(name => '...' [, ...]) * @access public */ function get_action_items($action_id) { //see tuleks võtta andmebaasist $classes = array('A'=>'activity', 'P'=>'person', 'R'=>'grouprelation'); if ($class = @$classes[$action_id]) { $a =& new $class($this); return $a->get_items(); //return $class::get_items(); } else return null; } function &get_diary() { return $this->diary; } function &get_scoring_system() { return $this->scoring; } /** * Game :: get_choices() * Vahalik v.4 kasutajaliidese jaoks * @return */ function &get_choices() { $arr = array(); //kõik tundmatud inimesed //kõik tundmatud grupisuhted //kõik tegevused return NULL; } } ?>