/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ContentTemplateWidget();
     if ($model->load(Yii::$app->request->post()) && $model->convertPositionIds() && $model->save()) {
         return $this->redirect($this->getRedirectPage('create', $model));
     }
     return $this->renderIsAjax('create', compact('model'));
 }
 public function safeDown()
 {
     ContentPage::deleteAll();
     ContentTemplateWidget::deleteAll(['name' => ['Side menu', 'Top menu']]);
     ContentTemplate::deleteIfExists(['name' => 'Default']);
     ContentMenu::deleteAll(['code' => ['topMenu', 'sideMenu']]);
     Yii::$app->cache->flush();
 }
 public function search($params)
 {
     $query = ContentTemplateWidget::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->created_at) {
         $tmp = explode(' - ', $this->created_at);
         if (isset($tmp[0], $tmp[1])) {
             $query->andFilterWhere(['between', 'content_template_widget.created_at', strtotime($tmp[0]), strtotime($tmp[1])]);
         }
     }
     $query->andFilterWhere(['content_template_widget.id' => $this->id, 'content_template_widget.active' => $this->active, 'content_template_widget.single_per_page' => $this->single_per_page, 'content_template_widget.has_settings' => $this->has_settings]);
     $query->andFilterWhere(['like', 'content_template_widget.name', $this->name])->andFilterWhere(['like', 'content_template_widget.widget_class', $this->widget_class])->andFilterWhere(['like', 'content_template_widget.widget_options', $this->widget_options])->andFilterWhere(['like', 'content_template_widget.link_to_settings', $this->link_to_settings]);
     if ($this->position) {
         $query->andFilterWhere(['like', 'content_template_widget.position', '|' . $this->position . '|']);
     }
     return $dataProvider;
 }
 /**
  * @param int    $id ContentTemplate ID
  * @param string $position
  *
  * @return string
  * @throws \yii\web\BadRequestHttpException
  */
 public function actionAvailableWidgets($id, $position)
 {
     if (!Yii::$app->request->isAjax) {
         throw new BadRequestHttpException('AJAX only');
     }
     $widgets = ContentTemplateWidget::find()->andWhere(['active' => 1])->andWhere(['like', 'position', '|' . $position . '|'])->all();
     return $this->renderAjax('availableWidgets', compact('widgets', 'position'));
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContentTemplateWidgets()
 {
     return $this->hasMany(ContentTemplateWidget::className(), ['id' => 'content_template_widget_id'])->viaTable('{{%content_template_has_widget}}', ['content_template_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContentTemplateWidget()
 {
     return $this->hasOne(ContentTemplateWidget::className(), ['id' => 'content_template_widget_id']);
 }
示例#7
0
 /**
  * Create ContentTemplateWidget or update it
  *
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         $widget = new ContentTemplateWidget();
         $widget->name = $this->name;
         $widget->position = $this->position;
         $widget->widget_class = self::WIDGET_CLASS;
         $widget->code = md5(__CLASS__ . '_' . $this->id);
         $widget->widget_options = serialize(['code' => $this->code]);
         $widget->has_settings = 1;
         $widget->link_to_settings = '/content/content-page/tree?menuId=' . $this->id;
         $widget->save(false);
     } elseif (array_key_exists('name', $changedAttributes) || array_key_exists('position', $changedAttributes) || array_key_exists('code', $changedAttributes)) {
         $widget = ContentTemplateWidget::findOne(['widget_class' => self::WIDGET_CLASS, 'code' => md5(__CLASS__ . '_' . $this->id)]);
         if ($widget) {
             $widget->name = $this->name;
             $widget->position = $this->position;
             $widget->widget_options = serialize(['code' => $this->code]);
             $widget->save(false);
         }
     }
     TagDependency::invalidate(Yii::$app->cache, ContentModule::CACHE_TAG);
     parent::afterSave($insert, $changedAttributes);
 }