Пример #1
0
 /**
  * @return array|bool|null|CmsTree|\yii\db\ActiveRecord
  */
 public function getModel()
 {
     if ($this->_model !== false) {
         return $this->_model;
     }
     if (!($id = \Yii::$app->request->get('id'))) {
         $this->_model = null;
         return false;
     }
     $this->_model = CmsTree::find()->where(['id' => $id])->one();
     return $this->_model;
 }
 public function safeUp()
 {
     $rows = (new \yii\db\Query())->select(['id', 'files'])->from('cms_tree')->all();
     if ($rows) {
         foreach ($rows as $row) {
             /**
              * @var \skeeks\cms\models\CmsTree $model
              */
             if (!($modelId = \yii\helpers\ArrayHelper::getValue($row, 'id'))) {
                 continue;
             }
             if (!($model = \skeeks\cms\models\CmsTree::findOne($modelId))) {
                 continue;
             }
             $files = \yii\helpers\ArrayHelper::getValue($row, 'files');
             if (!$files) {
                 continue;
             }
             $files = Json::decode($files);
             if ($images = \yii\helpers\ArrayHelper::getValue($files, 'images')) {
                 foreach ($images as $src) {
                     $storageFile = \skeeks\cms\models\StorageFile::find()->where(['src' => $src])->one();
                     if ($storageFile) {
                         if (!$model->getCmsTreeImages()->andWhere(['storage_file_id' => $storageFile->id])->one()) {
                             $model->link('images', $storageFile);
                         }
                     }
                 }
             }
             if ($files = \yii\helpers\ArrayHelper::getValue($files, 'files')) {
                 foreach ($files as $src) {
                     $storageFile = \skeeks\cms\models\StorageFile::find()->where(['src' => $src])->one();
                     if ($storageFile) {
                         if (!$model->getCmsTreeFiles()->andWhere(['storage_file_id' => $storageFile->id])->one()) {
                             $model->link('files', $storageFile);
                         }
                     }
                 }
             }
         }
     }
     $rows = (new \yii\db\Query())->select(['id', 'files'])->from('cms_content_element')->all();
     if ($rows) {
         foreach ($rows as $row) {
             /**
              * @var \skeeks\cms\models\CmsContentElement $model
              */
             if (!($modelId = \yii\helpers\ArrayHelper::getValue($row, 'id'))) {
                 continue;
             }
             if (!($model = \skeeks\cms\models\CmsContentElement::findOne($modelId))) {
                 continue;
             }
             $files = \yii\helpers\ArrayHelper::getValue($row, 'files');
             if (!$files) {
                 continue;
             }
             $files = Json::decode($files);
             if ($images = \yii\helpers\ArrayHelper::getValue($files, 'images')) {
                 foreach ($images as $src) {
                     $storageFile = \skeeks\cms\models\StorageFile::find()->where(['src' => $src])->one();
                     if ($storageFile) {
                         if (!$model->getCmsContentElementImages()->andWhere(['storage_file_id' => $storageFile->id])->one()) {
                             $model->link('images', $storageFile);
                         }
                     }
                 }
             }
             if ($files = \yii\helpers\ArrayHelper::getValue($files, 'files')) {
                 foreach ($files as $src) {
                     $storageFile = \skeeks\cms\models\StorageFile::find()->where(['src' => $src])->one();
                     if ($storageFile) {
                         if (!$model->getCmsContentElementFiles()->andWhere(['storage_file_id' => $storageFile->id])->one()) {
                             $model->link('files', $storageFile);
                         }
                     }
                 }
             }
         }
     }
 }
Пример #3
0
 public function actionTree()
 {
     return $this->render($this->action->id, ['models' => CmsTree::findRoots()->joinWith('cmsSiteRelation')->orderBy([CmsSite::tableName() . ".priority" => SORT_ASC])->all()]);
 }
Пример #4
0
 /**
  * @return CmsTree[]
  */
 public function getSections()
 {
     $value = $this->model->{$this->attribute};
     if (!$value) {
         return [];
     }
     $items = $value;
     if (is_string($value) || is_int($value)) {
         $items = [$value => $value];
     }
     return CmsTree::findAll(["id" => $items]);
 }
Пример #5
0
<?php

/* @var $this yii\web\View */
/* @var $model \skeeks\cms\models\CmsContentElement */
/* @var $relatedModel \skeeks\cms\relatedProperties\models\RelatedPropertiesModel */
echo $form->fieldSet(\Yii::t('skeeks/cms', 'Sections'));
?>
    <? if ($contentModel->root_tree_id) : ?>
        <? $rootTreeModels = \skeeks\cms\models\CmsTree::findAll($contentModel->root_tree_id); ?>
    <? else : ?>
        <? $rootTreeModels = \skeeks\cms\models\CmsTree::findRoots()->joinWith('cmsSiteRelation')->orderBy([\skeeks\cms\models\CmsSite::tableName() . ".priority" => SORT_ASC])->all(); ?>
    <? endif; ?>

    <? if ($contentModel->is_allow_change_tree == \skeeks\cms\components\Cms::BOOL_Y) : ?>
        <? if ($rootTreeModels) : ?>
            <div class="row">
                <div class="col-lg-8 col-md-12 col-sm-12">
                    <?php 
echo $form->field($model, 'tree_id')->widget(\skeeks\cms\widgets\formInputs\selectTree\SelectTreeInputWidget::class, ['multiple' => false, 'treeWidgetOptions' => ['models' => $rootTreeModels]]);
?>
                </div>
            </div>
        <? endif; ?>
    <? endif; ?>

    <? if ($rootTreeModels) : ?>
        <div class="row">
            <div class="col-lg-8 col-md-12 col-sm-12">
                <?php 
echo $form->field($model, 'treeIds')->widget(\skeeks\cms\widgets\formInputs\selectTree\SelectTreeInputWidget::class, ['multiple' => true, 'treeWidgetOptions' => ['models' => $rootTreeModels]]);
?>