2 // @todo nacitanie suborov a tried prepracovat pomocou Zend_Loader
3 require_once APPLICATION_PATH
.'/models/Game.php';
4 require_once APPLICATION_PATH
.'/models/GameManager.php';
5 require_once APPLICATION_PATH
.'/models/Player.php';
6 require_once APPLICATION_PATH
.'/models/PlayerList.php';
8 class IndexController
extends Zend_Controller_Action
10 const PLAYER_ID
= 'player_id';
13 public function indexAction()
15 $this->view
->actual_game_date
= $this->_getModel()->getActualGameDate();
16 $this->view
->player_list
= $this->getActualPlayerlist();
17 $this->view
->form
= $this->_getSignForm();
20 public function signAction()
23 $auth = $this->_getAuth();
25 if ($auth->hasIdentity()) {
26 //zaznamena ucast hraca v DB
27 $storage = $auth->getStorage()->read();
28 $this->_signPlayer($storage->player_id
);
29 //aktualizovany view so zoznamom hracov
34 public function unsignAction()
37 $auth = $this->_getAuth();
39 if ($auth->hasIdentity()) {
40 $storage = $auth->getStorage()->read();
41 //odstrani hraca z player_in_game
42 $this->_unsignPlayer($storage->player_id
);
47 * metoda zisti informacie o hracoch prihlasenych na aktualnu hru
48 * @todo tuto informaciu by mal poskytovat model - bude
49 * treba zapracovat na presune metody do modelu
51 public function getActualPlayerlist()
53 return $this->_getModel()->getActualGame()->getPlayerList();
56 protected function _getModel()
58 if (null === $this->_model
) {
59 $this->_model
= new GameManager();
64 protected function _getSignForm()
66 $form = new Zend_Form();
67 $form->setAction($this->_helper
->url('sign'))
69 $form->addElement('submit', 'prihlasit');
73 protected function _signPlayer($player_id)
75 $_model = $this->_getModel();
77 $_model->signPlayer($player_id);
78 }catch (Zend_Db_Statement_Exception
$exception) {
79 echo $exception->getCode();
80 echo $exception->getMessage();
84 protected function _unsignPlayer($player_id)
86 $_model = $this->_getModel();
88 $_model->unsignPlayer($player_id);
89 }catch (Zend_Db_Statement_Exception
$exception) {
90 echo $exception->getCode();
91 echo $exception->getMessage();
95 protected function _getAuth()
98 $auth = Zend_Auth
::getInstance();
99 #$authAdapter = Zend_Registry::get('authAdapter');
100 $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Registry
::get('dbAdapter'));
101 $authAdapter->setTableName('player')
102 ->setIdentityColumn('login')
103 ->setCredentialColumn('passwd');