Esempio n. 1
0
 /**
  * Allow turn on/off widget
  * @param string $controllerName
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionTurn($controllerName)
 {
     // get controller name & find object in db
     $controllerName = ucfirst(Str::lowerCase($controllerName));
     $record = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'widget')->first();
     // check if widget admin controller exists
     if ($record === null || (int) $record->id < 1) {
         throw new ForbiddenException('Widget is not founded');
     }
     // initialize turn on/off model
     $model = new FormTurn($record);
     if ($model->send()) {
         $model->update();
         App::$Session->getFlashBag()->add('success', __('Widget status was changed'));
     }
     // render view
     return $this->view->render('turn', ['widget' => $record, 'model' => $model]);
 }
Esempio n. 2
0
 /**
  * Install function callback
  */
 public static function install()
 {
     // prepare application information to extend inserted before row to table apps
     $appData = new \stdClass();
     $appData->configs = ['textCfg' => 'Some value', 'intCfg' => 10, 'boolCfg' => true];
     $appData->name = ['ru' => 'Демо приложение', 'en' => 'Demo app'];
     // get current app row from db (like SELECT ... WHERE type='app' and sys_name='Demoapp')
     $query = AppRecord::where('type', '=', 'app')->where('sys_name', '=', 'Demoapp');
     if ($query->count() !== 1) {
         return;
     }
     $query->update(['name' => Serialize::encode($appData->name), 'configs' => Serialize::encode($appData->configs), 'disabled' => 0]);
     // create your own table in database
     App::$Database->schema()->create('demos', function ($table) {
         $table->increments('id');
         $table->string('text', 1024);
         $table->timestamps();
     });
     $now = Date::convertToDatetime(time(), Date::FORMAT_SQL_DATE);
     // insert some data in table, id|text columns, id is autoincrement
     App::$Database->connection()->table('demos')->insert([['text' => 'Hello world 1', 'created_at' => $now, 'updated_at' => $now], ['text' => 'Hello world 2', 'created_at' => $now, 'updated_at' => $now]]);
 }
Esempio n. 3
0
 /**
  * Allow turn on/off applications
  * @param $controllerName
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionTurn($controllerName)
 {
     $controllerName = ucfirst(Str::lowerCase($controllerName));
     $search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'app')->first();
     if ($search === null || (int) $search->id < 1) {
         throw new ForbiddenException('App is not founded');
     }
     $model = new FormTurn($search);
     if ($model->send()) {
         $model->update();
         App::$Session->getFlashBag()->add('success', __('Application status was changed'));
     }
     return $this->view->render('turn', ['app' => $search, 'model' => $model]);
 }