5 protected $_actual_game_date;
6 protected $_actual_game_id;
8 public function __construct()
10 $res = Zend_Registry
::getInstance()->dbAdapter
11 ->query('SELECT game_id, game_date FROM game ORDER BY game_date DESC LIMIT 1');
12 if ($row=$res->fetch()) {
13 $game_date = new Zend_Date($row['game_date']);
14 $game_id = $row['game_id'];
15 if ( -1 == $game_date->compare(Zend_Date
::now())) {
16 $new_game = $this->_createNewGame();
17 $game_date = value($new_game);
18 $trans = array_flip($new_game);
19 $game_id = value($trans);
21 $this->_actual_game_date
= $game_date;
22 $this->_actual_game_id
= $game_id;
25 $new_game = $this->_createNewGame();
26 $this->_actual_game_date
= value($new_game);
27 $trans = array_flip($new_game);
28 $this->_actual_game_id
= value($trans);
32 public function getTable()
34 if (null === $this->_table
) {
35 // since the dbTable is not a library item but an application item,
36 // we must require it to use it
37 require_once APPLICATION_PATH
. '/models/DbTable/Game.php';
38 $this->_table
= new Model_DbTable_Game();
43 public function getGames()
45 return $this->getTable()->fetchAll()->toArray();
48 public function getActualGameDate()
50 return $this->_actual_game_date
;
53 public function getActualGameID()
55 return $this->_actual_game_id
;
58 protected function _getNewGameDate()
60 $game_date = new Zend_Date();
61 $game_date->setOptions(array('format_type'=>'php'));
63 $game_date->setWeekday(2);
64 //nastavi cas 18:00:00
65 $game_date->setHour(18);
66 $game_date->setMinute(0);
67 $game_date->setSecond(0);
68 if (-1 == $game_date->compare(Zend_Date
::now())) {
69 $game_date->addWeek(1);
74 protected function _createNewGame()
76 $game_date = $this->_getNewGameDate();
77 $game_id = $this->getTable()->insert(array('game_date'=>$game_date->toString('Y-m-j H:i:s')));
78 return array($game_id=>$game_date);