owner->week; } // end get_week /** * Lisab jooksvale nädalale juurde $nr nädalat. * Peab tegema koos Actioni lisamisega! Actioni lisamine võiks selle välja kutsuda * * @access private * @return $onnestumine * @param $nr nädalat */ function add_weeks($nr) { if ($this->get_weeks_left() >= $nr) { $sql = "UPDATE dsg_game SET week = week + $nr WHERE user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' "; $this->exec_sql($sql); $this->owner->week = $this->get_db_value("SELECT week FROM dsg_game WHERE user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' "); return true; } return false; } // end add_weeks /** * Väljastab, mitu nädalat on veel mängida. * * @return */ function get_weeks_left() { $total_weeks = $this->get_db_value("SELECT COUNT(*) FROM dsg_calendar"); return $total_weeks - $this->get_week() + 1; } // end get_weeks_left /** * nii mitu nädalat tuleb liita alguskuupäevale et saada jooksev kuupäev */ function get_week_offset() { return $this->get_db_value("SELECT week_offset FROM dsg_calendar WHERE week = ".$this->get_week()); } // end get_week /** * Does ... * * @return */ function get_begin_date() { return $this->get_db_value("SELECT UNIX_TIMESTAMP(begin) FROM dsg_vars"); //return $this->get_db_value("SELECT YEAR(begin) year, MONTH(begin) mon, DAYOFMONTH(begin) mday FROM dsg_vars"); } /** * Does ... * * * @return */ function get_date() { return $this->get_begin_date() + $this->get_week_offset()*7*24*60*60; } /** * Does ... * * * @return integer */ function get_month() { $timestamp = $this->get_date(); $date = getdate($timestamp); $month = $date['mon']; return $month; } /** * Siis kui viimane nädal on tegevusega täidetud ja 0 nädalat on jäänud mängu lõpuni * ehk et ühtegi tegevust enam teha ei saa. * * @return */ function is_game_end() { // your code here return ($this->get_weeks_left() == 0); } // end is_game_end /* * Does ... * * @return Group * @param integer $week function &get_subjects($week) { return null; } */ /** * * Idee: * Teeb kindlaks mis klassist on action ja initsialiseerib selle, siis kutsub välja tolle load()-i * mis omakorda vajadusel loob enda sees group-i, ning kutsub välja selle load_subjects * * @return Action * @param integer $week */ function &get_action($week) { //c.user_id, c.game_id, c.week, c.action_id, /* $sql = "SELECT a.class_name FROM dsg_chronology c, dsg_action a WHERE c.week = '$week' AND c.action_id = a.action_id AND c.user_id = '{$this->user_id}' AND c.game_id = '{$this->game_id}' "; $class = $this->get_db_value($sql); */ $sql = "SELECT action_id FROM dsg_chronology WHERE week = '$week' AND user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' "; $action_id = $this->get_db_value($sql); $a =& $this->owner->get_action($action_id); $a->load($week); return $a; } /** * Does ... * * @return array of actions * @param nr * @param beg_week */ function &get_actions_between($beg_week, $end_week) { $sql = "SELECT week, action_id FROM dsg_chronology WHERE week BETWEEN '$beg_week' AND '$end_week' AND user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' ORDER BY week ASC "; $week_action_id_s = $this->get_db_pairs($sql); $arr = array(); foreach ($week_action_id_s as $week => $action_id) { $a =& $this->owner->get_action($action_id); $a->load($week); $arr[] =& $a; } return $arr; } /** * Does ... * * @return * @param nr * @param beg_week */ function &get_actions_from($nr, $beg_week) { $sql = "SELECT week, action_id FROM dsg_chronology WHERE week >= '$beg_week' AND user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' ORDER BY week ASC LIMIT $nr "; $week_action_id_s = $this->get_db_pairs($sql); $arr = array(); foreach ($week_action_id_s as $week => $action_id) { $a =& $this->owner->get_action($action_id); $a->load($week); $arr[] =& $a; } return $arr; } /** * Annab $nr actionit kuni * * @return * @param nr * @param end_week */ function &get_actions_to($nr, $end_week) { //miks see ei võinud juba andmebaasis olla üks väli? :P ..muudaks ära kunagi? //sellep et väljatüübid on erinevad, need võiks ühtlustada, aga kui kasutada //mingit AB mootorit mis haldab tabelite vahelisi seoseid, siis seoseid ei saaks kasutada. $sql = "SELECT week, action_id, IF(action_id = 'A', activity_id, IF(action_id = 'R', group_relation_id, NULL) ) instance_id FROM dsg_chronology WHERE week <= '$end_week' AND user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' ORDER BY week DESC LIMIT $nr "; $key_records = $this->get_db_key_records($sql); //pööraks ringi / järjestame võtme järgi: ksort($key_records); $arr = array(); foreach ($key_records as $week => $rec) { $a =& $this->owner->get_action($rec['action_id'], $rec['instance_id']); $a->load($week); $arr[] =& $a; } return $arr; } /** * Annab $nr viimast actionit * * @return * @param nr */ function &get_last_actions($nr) { // your code here return $this->get_actions_to($nr, $this->get_week() ); } // end get_actions function get_last_action_week_by_type($action_id) { $sql = "SELECT week FROM dsg_chronology WHERE action_id = '$action_id' AND user_id = '{$this->user_id}' AND game_id = '{$this->game_id}' ORDER BY week DESC LIMIT 1 "; return $this->get_db_value($sql); } function &get_last_action_by_type($action_id) { $week = $this->get_last_action_week_by_type($action_id); if (isset($week)) { $a =& $this->owner->get_action($action_id); $a->load($week); return $a; //return get_action($week); } else return null; } /** * Does ... * * * @param action */ function add_action($action) { // your code here } // end add_action } // end Diary ?>