| @@ 18-137 (lines=120) @@ | ||
| 15 | * Class Application. View and manage system applications. |
|
| 16 | * @package Apps\Controller\Admin |
|
| 17 | */ |
|
| 18 | class Application extends AdminController |
|
| 19 | { |
|
| 20 | public $type = 'app'; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Application constructor. |
|
| 24 | */ |
|
| 25 | public function __construct() |
|
| 26 | { |
|
| 27 | // prevent version checks |
|
| 28 | parent::__construct(false); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * List of all installed applications |
|
| 33 | * @return string |
|
| 34 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 35 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 36 | */ |
|
| 37 | public function actionIndex() |
|
| 38 | { |
|
| 39 | return $this->view->render('index', [ |
|
| 40 | 'apps' => $this->applications |
|
| 41 | ]); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Show installation for of applications |
|
| 46 | * @return string |
|
| 47 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 48 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 49 | */ |
|
| 50 | public function actionInstall() |
|
| 51 | { |
|
| 52 | $model = new FormInstall($this->applications, 'app'); |
|
| 53 | ||
| 54 | // check if model is sended |
|
| 55 | if ($model->send()) { |
|
| 56 | // validate app name |
|
| 57 | if ($model->validate()) { |
|
| 58 | // try to run ::install method from remoute controller |
|
| 59 | if ($model->make()) { |
|
| 60 | App::$Session->getFlashBag()->add('success', __('Application "%app%" is successful installed!', ['app' => $model->sysname])); |
|
| 61 | $this->response->redirect('application/index'); |
|
| 62 | } else { |
|
| 63 | App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with application developer.')); |
|
| 64 | } |
|
| 65 | } else { |
|
| 66 | App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.')); |
|
| 67 | } |
|
| 68 | } |
|
| 69 | ||
| 70 | return $this->view->render('install', [ |
|
| 71 | 'model' => $model |
|
| 72 | ]); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Show and process update form for apps |
|
| 77 | * @param string $sys_name |
|
| 78 | * @return string |
|
| 79 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 80 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 81 | * @throws NotFoundException |
|
| 82 | */ |
|
| 83 | public function actionUpdate($sys_name) |
|
| 84 | { |
|
| 85 | // get controller name and try to find app in db |
|
| 86 | $controller = ucfirst(Str::lowerCase($sys_name)); |
|
| 87 | $search = \Apps\ActiveRecord\App::getItem('app', $controller); |
|
| 88 | ||
| 89 | // check what we got |
|
| 90 | if ($search === null || (int)$search->id < 1) { |
|
| 91 | throw new NotFoundException('App is not founded'); |
|
| 92 | } |
|
| 93 | ||
| 94 | // init model and make update with notification |
|
| 95 | $model = new FormUpdate($search); |
|
| 96 | if ($model->send() && $model->validate()) { |
|
| 97 | $model->make(); |
|
| 98 | App::$Session->getFlashBag()->add('success', __('Application %s% is successful updated to %v% version', ['s' => $sys_name, 'v' => $model->scriptVersion])); |
|
| 99 | $this->response->redirect('application/index'); |
|
| 100 | } |
|
| 101 | ||
| 102 | // render response |
|
| 103 | return $this->view->render('update', [ |
|
| 104 | 'model' => $model |
|
| 105 | ]); |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Allow turn on/off applications |
|
| 110 | * @param $controllerName |
|
| 111 | * @return string |
|
| 112 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 113 | * @throws ForbiddenException |
|
| 114 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 115 | */ |
|
| 116 | public function actionTurn($controllerName) |
|
| 117 | { |
|
| 118 | $controllerName = ucfirst(Str::lowerCase($controllerName)); |
|
| 119 | ||
| 120 | $search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'app')->first(); |
|
| 121 | ||
| 122 | if ($search === null || (int)$search->id < 1) { |
|
| 123 | throw new ForbiddenException('App is not founded'); |
|
| 124 | } |
|
| 125 | ||
| 126 | $model = new FormTurn($search); |
|
| 127 | if ($model->send()) { |
|
| 128 | $model->update(); |
|
| 129 | App::$Session->getFlashBag()->add('success', __('Application status was changed')); |
|
| 130 | } |
|
| 131 | ||
| 132 | return $this->view->render('turn', [ |
|
| 133 | 'app' => $search, |
|
| 134 | 'model' => $model |
|
| 135 | ]); |
|
| 136 | } |
|
| 137 | } |
|
| @@ 19-142 (lines=124) @@ | ||
| 16 | * Class Widget. Control installed and not-installed widgets. |
|
| 17 | * @package Apps\Controller\Admin |
|
| 18 | */ |
|
| 19 | class Widget extends AdminController |
|
| 20 | { |
|
| 21 | public $type = 'widget'; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Widget constructor. Disable installation checking for this controller |
|
| 25 | */ |
|
| 26 | public function __construct() |
|
| 27 | { |
|
| 28 | parent::__construct(false); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Show all installed widgets |
|
| 33 | * @return string |
|
| 34 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 35 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 36 | */ |
|
| 37 | public function actionIndex() |
|
| 38 | { |
|
| 39 | return $this->view->render('index', [ |
|
| 40 | 'widgets' => $this->widgets |
|
| 41 | ]); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Show installation form for widget |
|
| 46 | * @return string |
|
| 47 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 48 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 49 | */ |
|
| 50 | public function actionInstall() |
|
| 51 | { |
|
| 52 | $model = new FormInstall($this->applications, 'widget'); |
|
| 53 | ||
| 54 | // check if model is sended |
|
| 55 | if ($model->send()) { |
|
| 56 | // validate app name |
|
| 57 | if ($model->validate()) { |
|
| 58 | // try to run ::install method from remoute controller |
|
| 59 | if ($model->make()) { |
|
| 60 | App::$Session->getFlashBag()->add('success', __('Widget "%widget%" is successful installed!', ['widget' => $model->sysname])); |
|
| 61 | $this->response->redirect('widget/index'); |
|
| 62 | } else { |
|
| 63 | App::$Session->getFlashBag()->add('error', __('During the installation process an error has occurred! Please contact with widget developer.')); |
|
| 64 | } |
|
| 65 | } else { |
|
| 66 | App::$Session->getFlashBag()->add('error', __('Probably, app or widget with the same name is always used! Try to solve this conflict.')); |
|
| 67 | } |
|
| 68 | } |
|
| 69 | ||
| 70 | return $this->view->render('install', [ |
|
| 71 | 'model' => $model |
|
| 72 | ]); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Run widget update - display submit form & callback execution |
|
| 77 | * @param string $sys_name |
|
| 78 | * @return string |
|
| 79 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 80 | * @throws NotFoundException |
|
| 81 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 82 | */ |
|
| 83 | public function actionUpdate($sys_name) |
|
| 84 | { |
|
| 85 | // get controller name and try to find app in db |
|
| 86 | $controller = ucfirst(Str::lowerCase($sys_name)); |
|
| 87 | $search = \Apps\ActiveRecord\App::getItem('widget', $controller); |
|
| 88 | ||
| 89 | // check what we got |
|
| 90 | if ($search === null || (int)$search->id < 1) { |
|
| 91 | throw new NotFoundException('Widget is not founded'); |
|
| 92 | } |
|
| 93 | ||
| 94 | // init model and make update with notification |
|
| 95 | $model = new FormUpdate($search); |
|
| 96 | ||
| 97 | if ($model->send() && $model->validate()) { |
|
| 98 | $model->make(); |
|
| 99 | App::$Session->getFlashBag()->add('success', __('Widget %w% is successful updated to %v% version', ['w' => $sys_name, 'v' => $model->scriptVersion])); |
|
| 100 | $this->response->redirect('application/index'); |
|
| 101 | } |
|
| 102 | ||
| 103 | // render response |
|
| 104 | return $this->view->render('update', [ |
|
| 105 | 'model' => $model |
|
| 106 | ]); |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Allow turn on/off widget |
|
| 111 | * @param string $controllerName |
|
| 112 | * @return string |
|
| 113 | * @throws \Ffcms\Core\Exception\NativeException |
|
| 114 | * @throws ForbiddenException |
|
| 115 | * @throws \Ffcms\Core\Exception\SyntaxException |
|
| 116 | */ |
|
| 117 | public function actionTurn($controllerName) |
|
| 118 | { |
|
| 119 | // get controller name & find object in db |
|
| 120 | $controllerName = ucfirst(Str::lowerCase($controllerName)); |
|
| 121 | $record = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'widget')->first(); |
|
| 122 | ||
| 123 | // check if widget admin controller exists |
|
| 124 | if ($record === null || (int)$record->id < 1) { |
|
| 125 | throw new ForbiddenException('Widget is not founded'); |
|
| 126 | } |
|
| 127 | ||
| 128 | // initialize turn on/off model |
|
| 129 | $model = new FormTurn($record); |
|
| 130 | if ($model->send()) { |
|
| 131 | $model->update(); |
|
| 132 | App::$Session->getFlashBag()->add('success', __('Widget status was changed')); |
|
| 133 | } |
|
| 134 | ||
| 135 | // render view |
|
| 136 | return $this->view->render('turn', [ |
|
| 137 | 'widget' => $record, |
|
| 138 | 'model' => $model |
|
| 139 | ]); |
|
| 140 | } |
|
| 141 | ||
| 142 | } |
|