/** * 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; }
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; }
<?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>