/** * Check is current instance of application is enabled and can be executed * @return bool */ public function isEnabled() { $appName = App::$Request->getController(); // if app class extend current class we can get origin name $nativeName = Str::lastIn(get_class($this), '\\', true); // check if this controller is enabled $this->application = AppRecord::getItem('app', [$appName, $nativeName]); // not exist? false if ($this->application === null) { return false; } // check if disabled (0 = enabled, anything else = on) return (int) $this->application->disabled === 0; }
/** * Run widget update - display submit form & callback execution * @param string $sys_name * @return string * @throws \Ffcms\Core\Exception\NativeException * @throws NotFoundException * @throws \Ffcms\Core\Exception\SyntaxException */ public function actionUpdate($sys_name) { // get controller name and try to find app in db $controller = ucfirst(Str::lowerCase($sys_name)); $search = \Apps\ActiveRecord\App::getItem('widget', $controller); // check what we got if ($search === null || (int) $search->id < 1) { throw new NotFoundException('Widget is not founded'); } // init model and make update with notification $model = new FormUpdate($search); if ($model->send() && $model->validate()) { $model->make(); App::$Session->getFlashBag()->add('success', __('Widget %w% is successful updated to %v% version', ['w' => $sys_name, 'v' => $model->scriptVersion])); $this->response->redirect('application/index'); } // render response return $this->view->render('update', ['model' => $model]); }
/** * Check if widget is enabled * @param string|null $class * @return bool */ public static function enabled($class = null) { self::$class = $class !== null ? $class : get_called_class(); // get widget classname from passed data or from stacttrace if (!class_exists(self::$class)) { App::$Debug->addMessage(__('Widget autoload is disabled for class: %class%', ['class' => self::$class])); return false; } // get widget name self::$name = Str::lastIn(self::$class, '\\', true); $wData = AppRecord::getItem('widget', self::$name); // widget is not founded, deny run if ($wData === null) { if (App::$Debug !== null) { App::$Debug->addMessage(__('Widget with name %name%[%class%] is not found', ['name' => self::$name, 'class' => self::$class])); } return false; } // if widget is disabled - lets return nothing return !(bool) $wData->disabled; }