Merge file:///media/external_data/workspace/web/sport-group
[sport-group.git] / application / controllers / IndexController.php
blobbfaeaf2750d0ea6e99f7dd5342ce88d326f9f751
1 <?php
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';
11 protected $_model;
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()
22 //overi autorizaciu
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
30 //@todo
34 public function unsignAction()
36 //overi autorizaciu
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();
61 return $this->_model;
64 protected function _getSignForm()
66 $form = new Zend_Form();
67 $form->setAction($this->_helper->url('sign'))
68 ->setMethod('post');
69 $form->addElement('submit', 'prihlasit');
70 return $form;
73 protected function _signPlayer($player_id)
75 $_model = $this->_getModel();
76 try {
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();
87 try {
88 $_model->unsignPlayer($player_id);
89 }catch (Zend_Db_Statement_Exception $exception) {
90 echo $exception->getCode();
91 echo $exception->getMessage();
95 protected function _getAuth()
97 //overi autorizaciu
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');
104 return $auth;