Action.php
00001 <?php
00011 abstract class Dsao_Controller_Action extends Zend_Controller_Action
00012 {
00016 private $_config = null;
00017
00021 private $_helpersArray = array();
00022
00026 private $_isXmlHttpRequest = null;
00027
00031 private $_log = null;
00032
00036 private $_modelClassDefault = null;
00037
00041 private $_smarty = null;
00042
00046 private $_user = null;
00047
00058 public function __call($action, $parameters)
00059 {
00060
00061
00062 if (substr($action, -6, 6) == 'Action')
00063 {
00064 return $this->_forward('exception', 'error', 'default');
00065 }
00066
00067 throw new Dsao_Exception(array(
00068 'message' => 'dsao_controller_action_method_not_found',
00069 'variables' => array('method' => $action),
00070 ), 500);
00071 }
00072
00076 public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
00077 {
00078 $this->_log = Dsao_Registry::get('log');
00079
00080
00081 $this->_config = Dsao_Registry::get('config');
00082
00083
00084 $this->_initHelpers();
00085
00086 parent::__construct($request, $response, $invokeArgs);
00087 }
00088
00108 protected function _addJsFile($action = null, $controller = null, $module = null)
00109 {
00110
00111 $path = null;
00112
00113 $parameters = array(
00114 'Module' => $module,
00115 'Controller' => $controller,
00116 'Action' => $action
00117 );
00118
00119 foreach ($parameters as $name => $value)
00120 {
00121
00122 if (false === $value)
00123 {
00124 break;
00125 }
00126
00127
00128 $path .= '/';
00129
00130
00131 $method = 'get'.$name.'Name';
00132
00133 $path .= (null === $value ? $this->getRequest()->$method() : $value);
00134 }
00135
00136
00137 if (!$path)
00138 {
00139 return false;
00140 }
00141
00142
00143
00144 return $this->getView()->addJsFile($path);
00145 }
00146
00155 protected function _getModel($modelClass = null)
00156 {
00157 return Dsao_Registry::getModel
00158 ((null === $modelClass ? $this->_modelClassDefault : $modelClass));
00159 }
00160
00171 protected function _gotoSimple($action, $controller = null, $module = null, array $parameters = array(), $exit = true)
00172 {
00173 $this->getHelper('Redirector')->setExit($exit)
00174 ->gotoSimple($action, $controller, $module, $parameters);
00175 }
00176
00182 protected function _initHelpers()
00183 {
00184
00185 if (0 !== Zend_Controller_Action_HelperBroker::getStack()->count())
00186 {
00187 return;
00188 }
00189
00190
00191 Zend_Controller_Action_HelperBroker::addPrefix
00192 ('Dsao_Controller_Action_Helper');
00193
00194
00195
00196
00197
00198 Zend_Controller_Action_HelperBroker::getStaticHelper('Renderer');
00199
00200
00201 Zend_Controller_Action_HelperBroker::getStaticHelper('GarbageCollector');
00202
00203
00204 Zend_Controller_Action_HelperBroker::getStaticHelper('Menu');
00205
00206
00207 $this->_helpersArray['History'] =
00208 Zend_Controller_Action_HelperBroker::getStaticHelper('History');
00209
00210
00211 $this->_helpersArray['Translate'] =
00212 Zend_Controller_Action_HelperBroker::getStaticHelper('Translator');
00213
00214
00215 Zend_Controller_Action_HelperBroker::getStaticHelper('AccessControl');
00216
00217
00218
00219 Zend_Controller_Action_HelperBroker::getStaticHelper('Auth');
00220
00221
00222 $this->_helpersArray['SessionToken'] =
00223 Zend_Controller_Action_HelperBroker::getStaticHelper('SessionToken');
00224
00225
00226 $this->_helpersArray['Uri'] =
00227 Zend_Controller_Action_HelperBroker::getStaticHelper('Uri');
00228 }
00229
00236 protected function _setDefaultModelClass($modelClass)
00237 {
00238 $this->_modelClassDefault = $modelClass;
00239
00240 return $this;
00241 }
00242
00251 public function forward($action, $controller = null, $module = null, array $parameters = array())
00252 {
00253 $this->_forward($action, $controller, $module, $parameters);
00254 }
00255
00261 public final function getConfig()
00262 {
00263 return $this->_config;
00264 }
00265
00272 public final function getHelper($helperName)
00273 {
00274 $helperName = (string) $helperName;
00275
00276
00277 if (!isset($this->_helpersArray[$helperName]))
00278 {
00279
00280 if (null === $this->_helper)
00281 {
00282
00283
00284
00285
00286
00287
00288 $this->_helpersArray[$helperName] =
00289 Zend_Controller_Action_HelperBroker::getExistingHelper($helperName);
00290 }
00291 else
00292 {
00293 $this->_helpersArray[$helperName] = $this->_helper
00294 ->getHelper($helperName);
00295 }
00296 }
00297
00298 return $this->_helpersArray[$helperName];
00299 }
00300
00306 public final function getLog()
00307 {
00308 return $this->_log;
00309 }
00310
00316 public function getModuleNavigation()
00317 {
00318 return $this->_getModel()->getModuleNavigation();
00319 }
00320
00326 public final function getTranslate()
00327 {
00328 return $this->getHelper('Translate')->getTranslate();
00329 }
00330
00336 public final function getUri()
00337 {
00338 return $this->getHelper('Uri')->getUri();
00339 }
00340
00346 public final function getUser()
00347 {
00348 return $this->_user;
00349 }
00350
00356 public final function getView()
00357 {
00358 return $this->_smarty;
00359 }
00360
00368 public final function init()
00369 {
00370
00371 $this->_smarty = new Dsao_View_Smarty($this->isXmlHttpRequest());
00372
00373
00374 if ($this->isXmlHttpRequest())
00375 {
00376
00377 if ($this->_request->getParam('callbackHandler'))
00378 {
00379 $this->_smarty->getAjaxResponse()->setCallbackHandler
00380 ($this->_request->getParam('callbackHandler'));
00381 }
00382 }
00383 }
00384
00390 public function isXmlHttpRequest()
00391 {
00392
00393 if (null === $this->_isXmlHttpRequest)
00394 {
00395 $this->_isXmlHttpRequest = $this->_request->isXmlHttpRequest();
00396 }
00397
00398 return (bool) $this->_isXmlHttpRequest;
00399 }
00400
00406 public function postDispatch()
00407 {}
00408
00412 public function preDispatch()
00413 {}
00414
00423 public function preRedirect()
00424 {}
00425
00432 public function setUser(Dsao_User $user)
00433 {
00434 $this->_user = $user;
00435 }
00436 }