/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Block::find()->visible(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'visibility' => $this->visibility]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'class_name', $this->class_name])->andFilterWhere(['like', 'config', $this->config])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @param $id * @param $config * @return \nullref\cms\components\Widget * @throws \yii\base\InvalidConfigException | \Exception */ public function getWidget($id, $config = []) { /** @var BlockModel $block */ $block = BlockModel::getDb()->cache(function () use($id) { return BlockModel::find()->where(['id' => $id])->one(); }, null, new TagDependency(['tags' => 'cms.block.' . $id])); if ($block) { $config = ArrayHelper::merge($config, $block->getData()); $config['class'] = $this->getList()[$block->class_name] . self::CLASS_WIDGET; } else { $config = ['class' => $this->emptyBlockClass, 'id' => $id]; } /** @var \nullref\cms\components\Widget $widget */ $widget = Yii::createObject($config); $blockObj = $this->getBlock($block->class_name, $block->getData()); $blockObj->id = $block->id; $widget->setBlock($blockObj); return $widget; }
/** * Creates a new Block model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = Yii::createObject(Block::className()); if ($pageId = Yii::$app->request->get('page_id')) { $model->visibility = Block::VISIBILITY_PROTECTED; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { Yii::$app->session->set('new-block', $model); return $this->redirect(['config', 'page_id' => $pageId]); } else { return $this->render('create', ['model' => $model]); } }
public static function getNestedList($blockIds) { if (!empty($blockIds)) { $blockIds = self::getBlockIds($blockIds); } $blocks = Block::find()->orderBy(['id' => SORT_ASC])->orderBy(['class_name' => SORT_ASC])->asArray()->all(); $key = -1; $names = []; $result = []; foreach ($blocks as $block) { $name = $block['class_name']; if (!in_array($name, $names)) { $groupName = $name; $key++; array_push($names, $name); $result[$key] = ['title' => $groupName, 'key' => $groupName . '-type', 'selected' => false, 'folder' => true, 'children' => [], 'expanded' => true]; } $selected = false; if (!empty($blockIds)) { $selected = in_array($block['id'], $blockIds) ? true : false; } $block = ['title' => $block['id'], 'key' => $block['id'], 'selected' => $selected]; $result[$key]['children'][] = $block; } return $result; }
/** * @return \yii\db\ActiveQuery */ public function getBlock() { return $this->hasOne(Block::className(), ['id' => 'block_id']); }
?> <?php } ?> <?php echo $form->field($model, 'class_name')->dropDownList(CMSBlock::getManager()->getDropDownArray(), ['prompt' => '']); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'visibility')->dropDownList(Block::getVisibilityList()); ?> </div> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('cms', 'Create') : Yii::t('cms', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
<?php use yii\helpers\Html; use rmrevin\yii\fontawesome\FA; use nullref\cms\models\Block as BlockModel; /* @var $this yii\web\View */ /* @var $model nullref\cms\models\Page */ /* @var BlockModel[] $blocks */ $blocks = BlockModel::find()->visible()->indexBy('id')->all(); ?> <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading"> <?php echo Yii::t('cms', 'Page Content'); ?> <?php echo Html::a(FA::i(FA::_CLONE), ['wysiwyg', 'id' => $model->id], ['class' => 'btn btn-xs btn-primary pull-right', 'target' => 'blank']); ?> </div> <ul class="list-group page-items-list" id="pageItemsList"> <?php foreach ($model->items_list as $item) { ?> <li class="list-group-item"> <button type="button" class="btn btn-danger btn-xs" data-action="remove-block" data-id=""> <i class="fa fa-close"></i>