Beispiel #1
0
 public function suggestactionlinkAction()
 {
     $uri = $this->getRequest()->getPost('q');
     $jsonModel = new JsonModel();
     if (!$uri) {
         $jsonModel->setVariables([]);
         return $jsonModel;
     }
     $names = explode('/', $uri);
     $moduleName = null;
     $controllerName = null;
     $actionName = null;
     switch (count($names)) {
         case 1:
             $moduleName = $names[0];
             break;
         case 2:
             $moduleName = $names[1];
             break;
         case 3:
             $moduleName = $names[1];
             $controllerName = $names[2];
             break;
         case 4:
             $moduleName = $names[1];
             $controllerName = $names[2];
             $actionName = $names[3];
             break;
     }
     $moduleMapper = $this->getServiceLocator()->get('System\\Model\\ModuleMapper');
     $controllerMapper = $this->getServiceLocator()->get('System\\Model\\ControllerMapper');
     $actionMapper = $this->getServiceLocator()->get('System\\Model\\ActionMapper');
     $result = [];
     if ($actionName !== null) {
         $module = new \System\Model\Module();
         $module->setName($moduleName);
         if (!$moduleMapper->get($module)) {
             $jsonModel->setVariables([]);
             return $jsonModel;
         }
         $controller = new \System\Model\Controller();
         $controller->setName($controllerName);
         $controller->setModuleId($module->getId());
         if (!$controllerMapper->get($controller)) {
             $jsonModel->setVariables([]);
             return $jsonModel;
         }
         $result = $actionMapper->suggestUri($controller->getId(), $actionName);
     } elseif ($controllerName !== null) {
         $module = new \System\Model\Module();
         $module->setName($moduleName);
         if (!$moduleMapper->get($module)) {
             $jsonModel->setVariables([]);
             return $jsonModel;
         }
         $result = $controllerMapper->suggestUri($module->getId(), $controllerName);
     } elseif ($moduleName !== null) {
         $result = $moduleMapper->suggestUri($moduleName);
     }
     $jsonModel->setVariables($result);
     return $jsonModel;
 }
Beispiel #2
0
 public function mcaAction()
 {
     $dbSql = $this->getServiceLocator()->get('dbSql');
     $dbAdapter = $this->getServiceLocator()->get('dbAdapter');
     /* @var $dbSql \Zend\Db\Sql\Sql */
     $update = $dbSql->update(\System\Model\ModuleMapper::TABLE_NAME);
     $update->set(['updatedDateTime' => null]);
     $query = $dbSql->buildSqlString($update);
     $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     $update = $dbSql->update(\System\Model\ControllerMapper::TABLE_NAME);
     $update->set(['updatedDateTime' => null]);
     $query = $dbSql->buildSqlString($update);
     $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     $update = $dbSql->update(\System\Model\ActionMapper::TABLE_NAME);
     $update->set(['updatedDateTime' => null]);
     $query = $dbSql->buildSqlString($update);
     $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     $updatedDateTime = DateBase::getCurrentDateTime();
     $dir = realpath(BASE_PATH . '/module') . '/';
     $modules = scandir($dir);
     $total = 0;
     $moduleMapper = $this->getServiceLocator()->get('\\System\\Model\\ModuleMapper');
     $controllerMapper = $this->getServiceLocator()->get('\\System\\Model\\ControllerMapper');
     $actionMapper = $this->getServiceLocator()->get('\\System\\Model\\ActionMapper');
     foreach ($modules as $moduleName) {
         if ($moduleName != '.' && $moduleName != '..' && !strpos($moduleName, 'svn')) {
             //$moduleName = strtolower($moduleName);
             $module = new \System\Model\Module();
             $module->setName(strtolower($moduleName));
             $module->setCreatedById($this->user()->getIdentity());
             $module->setStatus(\System\Model\Action::STATUS_ACTIVE);
             $module->setCreatedDateTime($updatedDateTime);
             $module->setUpdatedDateTime($updatedDateTime);
             if ($moduleMapper->isExisted($module)) {
                 echo "<b>{$module->getName()} ==========================</b><br>";
                 $module->setUpdatedDateTime($updatedDateTime);
             } else {
                 echo "<b style='color:blue'>{$module->getName()} ==========================</b><br>";
             }
             $moduleMapper->save($module);
             $controllerDir = @scandir($dir . $moduleName . '/src/' . $moduleName . '/Controller/');
             if ($controllerDir) {
                 foreach ($controllerDir as $controllerFile) {
                     if ($controllerFile != '.' && $controllerFile != '..' && !strpos($controllerFile, 'svn') && is_file($dir . $moduleName . '/src/' . $moduleName . '/Controller/' . $controllerFile)) {
                         $controllerName = trim(strtolower(str_replace("Controller.php", "", $controllerFile)));
                         $controller = new \System\Model\Controller();
                         $controller->setModuleId($module->getId());
                         $controller->setName($controllerName);
                         $controller->setStatus(\System\Model\Action::STATUS_ACTIVE);
                         $controller->setCreatedById($this->user()->getIdentity());
                         $controller->setCreatedDateTime($updatedDateTime);
                         $controller->setUpdatedDateTime($updatedDateTime);
                         if ($controllerMapper->isExisted($controller)) {
                             echo "<b>{$controllerName} ---------------------------------</b><br>";
                             $controller->setUpdatedDateTime($updatedDateTime);
                         } else {
                             echo "<b style='color:blue'>{$controllerName} ---------------------------------</b><br>";
                         }
                         $controllerMapper->save($controller);
                         require_once $dir . $moduleName . '/src/' . $moduleName . '/Controller/' . $controllerFile;
                         $actions = get_class_methods("\\" . $moduleName . "\\Controller\\" . $controllerName . "Controller");
                         if (is_array($actions)) {
                             foreach ($actions as $actionName) {
                                 if (strpos($actionName, 'Action') && !in_array($actionName, ['getMethodFromAction', 'notFoundAction'])) {
                                     $actionName = str_replace('Action', '', $actionName);
                                     $action = new \System\Model\Action();
                                     $action->setControllerId($controller->getId());
                                     $action->setName($actionName);
                                     $action->setStatus(\System\Model\Action::STATUS_ACTIVE);
                                     $action->setDisplay(\System\Model\Action::DISPLAY_INACTIVE);
                                     $action->setCreatedById($this->user()->getIdentity());
                                     $action->setCreatedDateTime($updatedDateTime);
                                     $action->setUpdatedDateTime($updatedDateTime);
                                     if ($actionMapper->isExisted($action)) {
                                         $action->setUpdatedDateTime($updatedDateTime);
                                     } else {
                                         echo ++$total . ": <b style='color:blue'>{$actionName}</b><br>";
                                     }
                                     $actionMapper->save($action);
                                 }
                             }
                         } else {
                             echo '<b style="color:red">' . ucfirst($moduleName) . '_' . ucfirst($controllerName) . 'Controller </b> has no actions<br>';
                         }
                     }
                 }
             }
         }
     }
     die;
 }