Dsa3Controller.php
00001 <?php
00013 class Hero_Dsa3Controller extends Dsao_Controller_Action
00014 {
00018 protected $_namespaceRegister = null;
00019
00023 protected $_heroCreate = null;
00024
00025
00026 public function createAction()
00027 {
00028
00029 }
00030
00042 public function insertAction()
00043 {
00044 $this->getView()->addTemplate(false);
00045
00046
00047 if ($this->_getModel()->isUniqueHeroname($this->_heroCreate->name))
00048 {
00049
00050
00051 $this->_getModel()->insertHero($this->_heroCreate);
00052
00053 $this->getLog()->affirm
00054 ('hero_dsa3_insert_affirmation_inserted');
00055 }
00056 else
00057 {
00058
00059 $this->getLog()->err('hero_dsa3_insert_error_hero_exists');
00060 }
00061
00062
00063 Zend_Session::namespaceUnset('hero_create');
00064 $this->_heroCreate = null;
00065
00066 return true;
00067 }
00068
00069
00075 public function postDispatch()
00076 {
00077
00078 if (null != $this->_heroCreate)
00079 {
00080
00081 $this->_namespaceRegister->hero = serialize($this->_heroCreate);
00082 }
00083 }
00084
00085 public function preDispatch()
00086 {
00087 $this->_setDefaultModelClass('Hero_Create');
00088
00089
00090 if (!Zend_Session::namespaceIsset('hero_create'))
00091 {
00092
00093 $this->_namespaceRegister = new Zend_Session_Namespace('hero_create');
00094
00095
00096 $this->_namespaceRegister->setExpirationSeconds(24*60*60);
00097
00098
00099 $this->_heroCreate = new Dsao_Hero();
00100 }
00101 else
00102
00103 {
00104 $this->_namespaceRegister = new Zend_Session_Namespace('hero_create');
00105
00106 $this->_heroCreate = unserialize($this->_namespaceRegister->hero);
00107 }
00108 }
00109
00119 public function heronameAction()
00120 {
00121
00122 $this->getView()->addTemplate(false);
00123
00124
00125 $this->getView()->assign
00126 ('heroCreateHeroname', $this->_heroCreate->name);
00127
00128
00129 if (!$this->getRequest()->isPost())
00130 {
00131 return true;
00132 }
00133
00134
00135 $heroname = $this->getRequest()->getPost('heroname');
00136 $heronameSelection = $this->getRequest()->getPost('heronameSelection');
00137
00138
00139 $validator = new Zend_Validate();
00140 $validator->addValidator(new Dsao_Validate_Heroname());
00141
00142
00143 if (!$validator->isValid($heroname))
00144 {
00145
00146 $this->getLog()->err('hero_dsa3_insert_heroname_error_invalid');
00147
00148 return false;
00149 }
00150
00151
00152 if (!$this->_getModel()->isUniqueHeroname($heroname))
00153 {
00154 $this->getLog()->info('hero_dsa3_insert_heroname_info_not_unique');
00155 return false;
00156 }
00157 if (!$this->_getModel()->isUniqueHeroOfUser($this->getUser()->getId()))
00158 {
00159 $this->getLog()->info('hero_dsa3_insert_hero_current_user_info_exist');
00160
00161 return false;
00162 }
00163
00164
00165 $this->_heroCreate->idUser = $this->getUser()->getId();
00166
00167 $this->_heroCreate->name = $heroname;
00168 $this->insertAction();
00169
00170 return true;
00171 }
00172 }