Esempio n. 1
0
 /**
  * Activated widget via ajax
  *
  * @param $id string
  *
  * @return null|string
  */
 public function actionAjaxActivate($id)
 {
     $model = new Widget(['scenario' => 'activate']);
     if ($model->load(Yii::$app->request->post())) {
         $count = Widget::find()->where(['widget_location' => $model->widget_location])->count();
         // Require widget config
         $configPath = $this->_widgetDir . $id . '/config/main.php';
         $widgetConfig = (require $configPath);
         // Set attribute of model
         $model->setAttributes($widgetConfig);
         $model->widget_dir = $id;
         $model->widget_config = Json::encode($model->widget_config);
         $model->widget_order = $count;
         if ($model->save()) {
             return $this->renderPartial('_activated', ['activatedWidget' => $model, 'availableWidget' => [$model->widget_dir => $widgetConfig]]);
         }
     }
     return null;
 }