From 6f5f7626340ace7cea8c829044a592556270fd32 Mon Sep 17 00:00:00 2001 From: klingac Date: Tue, 31 Mar 2009 23:53:33 +0200 Subject: [PATCH] modified: application/models/GameManager.php GameManager sa stara o pole hier,nie uz iba o jednu hru modified: documentation/notes.txt deleted: documentation/notes.txt~ par napadov... --- application/models/GameManager.php | 211 +++++++++++++++++++++---------------- documentation/notes.txt | 2 +- 2 files changed, 124 insertions(+), 89 deletions(-) rewrite application/models/GameManager.php (83%) diff --git a/application/models/GameManager.php b/application/models/GameManager.php dissimilarity index 83% index 78ba156..adcba32 100644 --- a/application/models/GameManager.php +++ b/application/models/GameManager.php @@ -1,88 +1,123 @@ -dbAdapter - ->query('SELECT game_id - FROM game - ORDER BY game_date DESC - LIMIT 1'); - if ($row=$res->fetch()) { - $game = new Game($row['game_id']); - $game_date = new Zend_Date($game->getDate()); - if ( -1 == $game_date->compare(Zend_Date::now())) { - $game = $this->createNewGame(); - } - $this->_actual_game = $game; - } - else { - $this->_actual_game_date = $this->createNewGame(); - } - } - - public function getActualGameID() - { - return $this->_actual_game->getID(); - } - - public function getActualGameDate() - { - return $this->_actual_game->getDate(); - } - - public function createNewGame() - { - $game_date = $this->_getNewGameDate(); - $game_table = new Model_DbTable_Game(); - $game_id = $game_table->insert(array('game_date'=>$game_date->toString('Y-m-j H:i:s'))); - return new Game($game_id); - - } - - //@todo dodelat - public function getActualGame() - { - } - - //@todo dodelat - public function getGameByDate() - { - } - - // @todo dodelat - public function getGames() - { - return $this->getTable()->fetchAll()->toArray(); - } - - //@todo dodelat - public function getGameByID() - { - } - - - protected function _getNewGameDate() - { - $game_date = new Zend_Date(); - $game_date->setOptions(array('format_type'=>'php')); - // nastavi utorok - $game_date->setWeekday(2); - //nastavi cas 18:00:00 - $game_date->setHour(18); - $game_date->setMinute(0); - $game_date->setSecond(0); - if (-1 == $game_date->compare(Zend_Date::now())) { - $game_date->addWeek(1); - } - return $game_date; - } - -} -?> +getTable()->select()->order(array(self::GAME_DATE.' DESC')); + if (null !== $start_date) { + $select->where(self::GAME_DATE.'>?', $start_date); + } + + if (null !== $end_date) { + $select->where(self::GAME_DATE.'query(); + + if ($games=$res->fetchAll()) { + foreach ($games as $row) { + $this->_game_list[] = new Game($row[self::GAME_ID]); + } + } + else { + $this->_game_list[] = $this->createNewGame(); + } + + $actual_game = $this->_game_list[0]; + $game_date = new Zend_Date($actual_game->getDate()); + if ( -1 == $game_date->compare(Zend_Date::now())) { + $this->_game_list = array_unshift($this->_game_list, + $this->createNewGame()); + } + + } + + public function getActualGameID() + { + return $this->_game_list[0]->getID(); + } + + public function getActualGameDate() + { + return $this->_game_list[0]->getDate(); + } + + public function createNewGame() + { + $game_date = $this->_getNewGameDate(); + $game_table = new Model_DbTable_Game(); + $game_id = $game_table->insert(array('game_date'=>$game_date->toString('Y-m-j H:i:s'))); + return new Game($game_id); + + } + + //@todo dodelat + public function getActualGame() + { + } + + //@todo dodelat + public function getGameByDate() + { + } + + // @todo dodelat + public function getGames() + { + return $this->getTable()->fetchAll()->toArray(); + } + + //@todo dodelat + public function getGameByID() + { + } + + + protected function _getNewGameDate() + { + $game_date = new Zend_Date(); + $game_date->setOptions(array('format_type'=>'php')); + // nastavi utorok + $game_date->setWeekday(2); + //nastavi cas 18:00:00 + $game_date->setHour(18); + $game_date->setMinute(0); + $game_date->setSecond(0); + if (-1 == $game_date->compare(Zend_Date::now())) { + $game_date->addWeek(1); + } + return $game_date; + } + + /** + * Retrieve table object + * + * @return Model_Guestbook_Table + */ + protected function getTable() + { + if (null === $this->_table) { + // since the dbTable is not a library item but an application item, + // we must require it to use it + $this->_table = new Model_DbTable_Game(); + } + return $this->_table; + } + + +} +?> diff --git a/documentation/notes.txt b/documentation/notes.txt index 0c2adfd..549b68d 100644 --- a/documentation/notes.txt +++ b/documentation/notes.txt @@ -17,6 +17,6 @@ * NEW FEATURES (not recomendet) * ********************************* -vymysliet nejake rozumnejsie nacitanie tried - modely by sa mali nacitavat same, - nie cez require_once + nie cez require_once -synchronizacia s google calendar -spolupraca s google groups -- 2.11.4.GIT