[ 'className' => 'App_Admin_Tool_Project_Provider_Module', 'title' => App_Admin_Tool_Project_Provider_Module::PROVIDER_TITLE, 'directoryName' => 'Module', ], ]; protected $_workflowAreaForm = null; public function __construct($options = []) { $this->_pageHeaderTemplates[self::HEADER_VIEW] = '%itemName%'; parent::__construct($options); } public function exec() { if (isset($this->_restParams[0]) && array_key_exists($this->_restParams[0], $this->_providerMap)) { if (class_exists($this->_providerMap[$this->_restParams[0]]['className'], false)) { $providerClassName = $this->_providerMap[$this->_restParams[0]]['className']; $this->_provider = new $providerClassName(); } } return parent::exec(); } protected function _doView() { $item = [ 'providers' => $this->_providerMap, 'tpl' => $this->getTemplate('view.tpl'), ]; $this->_addItem($item); if ($this->_provider instanceof App_Admin_Tool_Project_Provider_Abstract) { $this->_addForm(); } return $this; } protected function _addForm() { /** @var Qs_Form $form */ $form = $this->_getProviderForm(); $template = $this->_providerMap[$this->_restParams[0]]['directoryName'] . DIRECTORY_SEPARATOR . 'form.tpl'; $item = [ 'form' => $form->render(), 'tpl' => $this->getTemplate($template), ]; $this->_addItem($item, 'WORKFLOW_ITEMS'); return $this; } protected function _getProviderForm() { if (empty($this->_workflowAreaForm)) { $this->_workflowAreaForm = $this->_provider->getWorkflowAreaForm($this->_getFormOptions()); } return $this->_workflowAreaForm; } protected function _doGenerate() { /** @var Qs_Form $form */ $form = $this->_getProviderForm(); if ($form->validate()) { $this->_generate($form->getValues()); $providerClassName = $this->_providerMap[$this->_restParams[0]]['className']; $message = sprintf( $this->_provider->getMessage($providerClassName::SUCCESS_GENERATION), $this->_provider->getModuleName() ); $this->_setBackMessage($message); $this->_doBack(); } else { $this->_workflowAreaForm = $form; $this->_doView(); } return $this; } protected function _doGenerateAjax() { /** @var Qs_Form $form */ $form = $this->_getProviderForm(); $this->_displayJson($form->validateAjax()); } protected function _generate($data) { if (!$data['options']) { $data['options'] = []; } unset($data['action']); $this->_provider->setModuleName($data['name']); $this->_provider->setJsObjectName('Form'); $this->_provider->setParams($data); $this->_provider->generate(); return $this; } protected function _initPrimaryKey() { return false; } }