Inheritance: extends skeeks\cms\relatedProperties\models\RelatedElementModel, use trait skeeks\cms\models\behaviors\traits\HasRelatedPropertiesTrait, use trait skeeks\cms\models\behaviors\traits\HasTreesTrait, use trait skeeks\cms\models\behaviors\traits\HasUrlTrait
コード例 #1
0
 /**
  * @param $id
  * @return string
  * @throws InvalidConfigException
  * @throws \yii\web\HttpException
  */
 public function run($id)
 {
     $this->model = CmsContentElement::findOne(['id' => $id]);
     //Пробуем рендерить view для текущего типа страницы
     if ($this->model) {
         $cmsContent = $this->model->cmsContent;
         if ($cmsContent) {
             if ($cmsContent->viewFile) {
                 $this->view = $cmsContent->viewFile;
             } else {
                 $this->view = $cmsContent->code;
             }
             if ($cmsContent->access_check_element == 'Y') {
                 /**
                  * @var $filter CmsAccessControl
                  */
                 $filter = \Yii::createObject(['class' => CmsAccessControl::className(), 'only' => [$this->id], 'rules' => [['allow' => true, 'matchCallback' => function ($rule, $action) {
                     //Если такая привилегия заведена, нужно ее проверять.
                     if ($permission = \Yii::$app->authManager->getPermission($this->model->permissionName)) {
                         if (!\Yii::$app->user->can($permission->name)) {
                             return false;
                         }
                     }
                     return true;
                 }]]]);
                 $result = $filter->beforeAction($this);
             }
         }
     }
     return $this->_go();
 }
コード例 #2
0
 public function init()
 {
     $this->name = \Yii::t('skeeks/shop/app', 'Stocks');
     $this->modelShowAttribute = "name";
     $this->modelClassName = CmsContentElement::className();
     parent::init();
 }
コード例 #3
0
 public function init()
 {
     $this->name = \skeeks\cms\shop\Module::t('app', 'Elements');
     $this->modelShowAttribute = "name";
     $this->modelClassName = CmsContentElement::className();
     parent::init();
 }
コード例 #4
0
ファイル: PropertyTypeElement.php プロジェクト: 3737002/cms
 /**
  * @return \yii\widgets\ActiveField
  */
 public function renderForActiveForm()
 {
     $field = parent::renderForActiveForm();
     $find = CmsContentElement::find()->active();
     if ($this->content_id) {
         $find->andWhere(['content_id' => $this->content_id]);
     }
     if ($this->fieldElement == self::FIELD_ELEMENT_SELECT) {
         $field = $this->activeForm->fieldSelect($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
     } else {
         if ($this->fieldElement == self::FIELD_ELEMENT_SELECT_MULTI) {
             $field = $this->activeForm->fieldSelectMulti($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
         } else {
             if ($this->fieldElement == self::FIELD_ELEMENT_RADIO_LIST) {
                 $field = parent::renderForActiveForm();
                 $field->radioList(ArrayHelper::map($find->all(), 'id', 'name'));
             } else {
                 if ($this->fieldElement == self::FIELD_ELEMENT_CHECKBOX_LIST) {
                     $field = parent::renderForActiveForm();
                     $field->checkboxList(ArrayHelper::map($find->all(), 'id', 'name'));
                 }
             }
         }
     }
     if (!$field) {
         return '';
     }
     return $field;
 }
コード例 #5
0
ファイル: SeoController.php プロジェクト: Liv1020/cms
 /**
  * Стандартный sitemap
  */
 public function actionSitemap()
 {
     ini_set("memory_limit", "512M");
     $trees = Tree::find()->where(['site_code' => \Yii::$app->cms->site->code])->orderBy(['level' => SORT_ASC, 'priority' => SORT_ASC])->all();
     if ($trees) {
         /**
          * @var Tree $tree
          */
         foreach ($trees as $tree) {
             if (!$tree->redirect) {
                 $result[] = ["loc" => $tree->url, "lastmod" => $this->_lastMod($tree), "priority" => $this->_calculatePriority($tree), "changefreq" => "daily"];
             }
         }
     }
     $elements = CmsContentElement::find()->joinWith('cmsTree')->andWhere([Tree::tableName() . '.site_code' => \Yii::$app->cms->site->code])->orderBy(['updated_at' => SORT_DESC, 'priority' => SORT_ASC])->all();
     //Добавление элементов в карту
     if ($elements) {
         /**
          * @var CmsContentElement $model
          */
         foreach ($elements as $model) {
             $result[] = ["loc" => $model->absoluteUrl, "lastmod" => $this->_lastMod($model), "priority" => "0.3", "changefreq" => "daily"];
         }
     }
     \Yii::$app->response->format = Response::FORMAT_XML;
     $this->layout = false;
     //Генерация sitemap вручную, не используем XmlResponseFormatter
     \Yii::$app->response->content = $this->render($this->action->id, ['data' => $result]);
     return;
     /*return $this->render($this->action->id, [
           'data' => $result
       ]);;*/
 }
コード例 #6
0
 /**
  * @param ActiveDataProvider $activeDataProvider
  */
 public function search(ActiveDataProvider $activeDataProvider, $tableName = 'cms_content_element')
 {
     $classSearch = $this->propertyElementClassName;
     /**
      * @var $activeQuery ActiveQuery
      */
     $activeQuery = $activeDataProvider->query;
     $elementIdsGlobal = [];
     $applyFilters = false;
     foreach ($this->toArray() as $propertyCode => $value) {
         //TODO: add to validator related properties
         if ($propertyCode == 'properties') {
             continue;
         }
         if ($property = $this->getProperty($propertyCode)) {
             if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_NUMBER) {
                 $elementIds = [];
                 $query = $classSearch::find()->select(['element_id'])->where(["property_id" => $property->id])->indexBy('element_id');
                 if ($fromValue = $this->{$this->getAttributeNameRangeFrom($propertyCode)}) {
                     $applyFilters = true;
                     $query->andWhere(['>=', 'value_num', (double) $fromValue]);
                 }
                 if ($toValue = $this->{$this->getAttributeNameRangeTo($propertyCode)}) {
                     $applyFilters = true;
                     $query->andWhere(['<=', 'value_num', (double) $toValue]);
                 }
                 if (!$fromValue && !$toValue) {
                     continue;
                 }
                 $elementIds = $query->all();
             } else {
                 if (!$value) {
                     continue;
                 }
                 $applyFilters = true;
                 $elementIds = $classSearch::find()->select(['element_id'])->where(["value" => $value, "property_id" => $property->id])->indexBy('element_id')->all();
             }
             $elementIds = array_keys($elementIds);
             if ($elementIds) {
                 $realElements = CmsContentElement::find()->where(['id' => $elementIds])->select(['id', 'parent_content_element_id'])->indexBy('parent_content_element_id')->groupBy(['parent_content_element_id'])->asArray()->all();
                 $elementIds = array_keys($realElements);
             }
             if (!$elementIds) {
                 $elementIdsGlobal = [];
             }
             if ($elementIdsGlobal) {
                 $elementIdsGlobal = array_intersect($elementIds, $elementIdsGlobal);
             } else {
                 $elementIdsGlobal = $elementIds;
             }
         }
     }
     if ($applyFilters) {
         //$activeQuery->andWhere(['cms_content_element.id' => $elementIdsGlobal]);
         $activeQuery->andWhere([$tableName . '.id' => $elementIdsGlobal]);
     }
 }
コード例 #7
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 = CmsContentElement::findOne(['id' => $id]);
     return $this->_model;
 }
コード例 #8
0
 /**
  * @param $id
  * @return string
  * @throws InvalidConfigException
  * @throws \yii\web\HttpException
  */
 public function run($id)
 {
     $this->model = CmsContentElement::findOne(['id' => $id]);
     //Пробуем рендерить view для текущего типа страницы
     if ($this->model) {
         if ($this->model->cmsContent) {
             if ($this->model->cmsContent->viewFile) {
                 $this->view = $this->model->cmsContent->viewFile;
             } else {
                 $this->view = $this->model->cmsContent->code;
             }
         }
     }
     return $this->_go();
 }
コード例 #9
0
ファイル: PropertyTypeElement.php プロジェクト: Liv1020/cms
 /**
  * @return \yii\widgets\ActiveField
  */
 public function renderForActiveForm()
 {
     $field = parent::renderForActiveForm();
     $find = CmsContentElement::find()->active();
     if ($this->content_id) {
         $find->andWhere(['content_id' => $this->content_id]);
     }
     if ($this->multiple == Cms::BOOL_N) {
         $field = $this->activeForm->fieldSelect($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
     } else {
         if ($this->multiple == Cms::BOOL_Y) {
             $field = $this->activeForm->fieldSelectMulti($this->model->relatedPropertiesModel, $this->property->code, ArrayHelper::map($find->all(), 'id', 'name'), []);
         }
     }
     return $field;
 }
コード例 #10
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param string $route
  * @param array $params
  * @return bool|string
  */
 public function createUrl($manager, $route, $params)
 {
     if ($route == 'cms/content-element/view') {
         $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
         $id = (int) ArrayHelper::getValue($params, 'id');
         $contentElement = ArrayHelper::getValue($params, 'model');
         if (!$id && !$contentElement) {
             return false;
         }
         if ($contentElement && $contentElement instanceof CmsContentElement) {
             self::$models[$contentElement->id] = $contentElement;
         } else {
             /**
              * @var $contentElement CmsContentElement
              */
             if (!($contentElement = ArrayHelper::getValue(self::$models, $id))) {
                 $contentElement = CmsContentElement::findOne(['id' => $id]);
                 self::$models[$id] = $contentElement;
             }
         }
         if (!$contentElement) {
             return false;
         }
         $url = '';
         $cmsTree = ArrayHelper::getValue($params, 'cmsTree');
         //We need to build on what that particular section of the settings
         if (!$cmsTree) {
             $cmsTree = $contentElement->cmsTree;
         }
         if ($cmsTree) {
             $url = $cmsTree->dir . "/";
         }
         //$url .= $contentElement->id . '-' . $contentElement->code . ((bool) \Yii::$app->seo->useLastDelimetrContentElements ? DIRECTORY_SEPARATOR : "");
         $url .= $contentElement->id . '-' . $contentElement->code . $suffix;
         ArrayHelper::remove($params, 'id');
         ArrayHelper::remove($params, 'code');
         ArrayHelper::remove($params, 'model');
         if (!empty($params) && ($query = http_build_query($params)) !== '') {
             $url .= '?' . $query;
         }
         return $url;
     }
     return false;
 }
コード例 #11
0
 public function safeUp()
 {
     if ($models = \skeeks\cms\models\CmsContentElement::find()->all()) {
         /**
          * @var $model \skeeks\cms\models\CmsContentElement
          */
         foreach ($models as $model) {
             if (!method_exists($model, 'getMainImageSrc')) {
                 continue;
             }
             //$user->getFiles()
             $imageSrc = $model->getMainImageSrcOld();
             if ($imageSrc) {
                 $storageFile = \skeeks\cms\models\CmsStorageFile::find()->where(['src' => $imageSrc])->one();
                 if ($storageFile) {
                     $model->image_id = $storageFile->id;
                     $model->image_full_id = $storageFile->id;
                     $model->save(false);
                 }
             }
         }
     }
 }
コード例 #12
0
ファイル: UrlRuleContentElement.php プロジェクト: Liv1020/cms
 /**
  * @param \yii\web\UrlManager $manager
  * @param string $route
  * @param array $params
  * @return bool|string
  */
 public function createUrl($manager, $route, $params)
 {
     if ($route == 'cms/content-element/view') {
         $id = (int) ArrayHelper::getValue($params, 'id');
         $contentElement = ArrayHelper::getValue($params, 'model');
         if (!$id && !$contentElement) {
             return false;
         }
         if ($contentElement && $contentElement instanceof CmsContentElement) {
             self::$models[$contentElement->id] = $contentElement;
         } else {
             /**
              * @var $contentElement CmsContentElement
              */
             if (!($contentElement = ArrayHelper::getValue(self::$models, $id))) {
                 $contentElement = CmsContentElement::findOne(['id' => $id]);
                 self::$models[$id] = $contentElement;
             }
         }
         if (!$contentElement) {
             return false;
         }
         $url = '';
         if ($contentElement->cmsTree) {
             $url = $contentElement->cmsTree->dir . DIRECTORY_SEPARATOR;
         }
         $url .= $contentElement->id . '-' . $contentElement->code . ((bool) \Yii::$app->seo->useLastDelimetrContentElements ? DIRECTORY_SEPARATOR : "");
         ArrayHelper::remove($params, 'id');
         ArrayHelper::remove($params, 'code');
         ArrayHelper::remove($params, 'model');
         if (!empty($params) && ($query = http_build_query($params)) !== '') {
             $url .= '?' . $query;
         }
         return $url;
     }
     return false;
 }
コード例 #13
0
ファイル: CmsContent.php プロジェクト: dextercool/cms
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentElements()
 {
     return $this->hasMany(CmsContentElement::className(), ['content_id' => 'id']);
 }
コード例 #14
0
 /**
  * @return string
  */
 public function getStringValue()
 {
     $value = $this->property->relatedPropertiesModel->getAttribute($this->property->code);
     if ($this->isMultiple) {
         $data = ArrayHelper::map(CmsContentElement::find()->where(['id' => $value])->all(), 'id', 'name');
         return implode(', ', $data);
     } else {
         if ($element = CmsContentElement::find()->where(['id' => $value])->one()) {
             return $element->name;
         }
         return "";
     }
 }
コード例 #15
0
 public function initDataProvider()
 {
     $this->search = new Search(CmsContentElement::className());
     $this->dataProvider = $this->search->getDataProvider();
     if ($this->enabledPaging == Cms::BOOL_Y) {
         $this->dataProvider->getPagination()->defaultPageSize = $this->pageSize;
         $this->dataProvider->getPagination()->pageParam = $this->pageParamName;
         $this->dataProvider->getPagination()->pageSizeLimit = [(int) $this->pageSizeLimitMin, (int) $this->pageSizeLimitMax];
     } else {
         $this->dataProvider->pagination = false;
     }
     if ($this->orderBy) {
         $this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order];
     }
     return $this;
 }
コード例 #16
0
 /**
  * @param CmsContentElement $model
  * @param $action
  * @return bool
  */
 public function eachMultiChangeTrees($model, $action)
 {
     try {
         $formData = [];
         parse_str(\Yii::$app->request->post('formData'), $formData);
         $tmpModel = new CmsContentElement();
         $tmpModel->load($formData);
         if (ArrayHelper::getValue($formData, 'removeCurrent')) {
             $model->treeIds = [];
         }
         if ($tmpModel->treeIds) {
             $model->treeIds = array_merge($model->treeIds, $tmpModel->treeIds);
             $model->treeIds = array_unique($model->treeIds);
         }
         return $model->save(false);
     } catch (\Exception $e) {
         return false;
     }
 }
コード例 #17
0
ファイル: select-cms-element.php プロジェクト: dextercool/cms
     }];
 }
 $searchRelatedPropertiesModel = new \skeeks\cms\models\searchs\SearchRelatedPropertiesModel();
 $searchRelatedPropertiesModel->initCmsContent($model->cmsContent);
 $searchRelatedPropertiesModel->load(\Yii::$app->request->get());
 $searchRelatedPropertiesModel->search($dataProvider);
 /**
  * @var $model \skeeks\cms\models\CmsContentElement
  */
 if ($model->relatedPropertiesModel) {
     foreach ($model->relatedPropertiesModel->attributeValues() as $name => $value) {
         $property = $model->relatedPropertiesModel->getRelatedProperty($name);
         $filter = '';
         if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_ELEMENT) {
             $propertyType = $property->createPropertyType();
             $options = \skeeks\cms\models\CmsContentElement::find()->active()->andWhere(['content_id' => $propertyType->content_id])->all();
             $items = \yii\helpers\ArrayHelper::merge(['' => ''], \yii\helpers\ArrayHelper::map($options, 'id', 'name'));
             $filter = \yii\helpers\Html::activeDropDownList($searchRelatedPropertiesModel, $name, $items, ['class' => 'form-control']);
         } else {
             if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_LIST) {
                 $items = \yii\helpers\ArrayHelper::merge(['' => ''], \yii\helpers\ArrayHelper::map($property->enums, 'id', 'value'));
                 $filter = \yii\helpers\Html::activeDropDownList($searchRelatedPropertiesModel, $name, $items, ['class' => 'form-control']);
             } else {
                 if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_STRING) {
                     $filter = \yii\helpers\Html::activeTextInput($searchRelatedPropertiesModel, $name, ['class' => 'form-control']);
                 } else {
                     if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_NUMBER) {
                         $filter = "<div class='row'><div class='col-md-6'>" . \yii\helpers\Html::activeTextInput($searchRelatedPropertiesModel, $searchRelatedPropertiesModel->getAttributeNameRangeFrom($name), ['class' => 'form-control', 'placeholder' => 'от']) . "</div><div class='col-md-6'>" . \yii\helpers\Html::activeTextInput($searchRelatedPropertiesModel, $searchRelatedPropertiesModel->getAttributeNameRangeTo($name), ['class' => 'form-control', 'placeholder' => 'до']) . "</div></div>";
                     }
                 }
             }
コード例 #18
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->on(self::EVENT_BEFORE_DELETE, [$this, "_deleteShops"]);
     $this->on(self::EVENT_AFTER_DELETE, [$this, "_updateParentAfterDelete"]);
 }
コード例 #19
0
 protected function _run()
 {
     $className = $this->contentElementClass;
     $cacheKey = $this->getCacheKey() . 'run';
     $dependency = new TagDependency(['tags' => [$this->className() . (string) $this->namespace, (new CmsContentElement())->getTableCacheTag()]]);
     $result = \Yii::$app->cache->get($cacheKey);
     if ($result === false || $this->enabledRunCache == Cms::BOOL_N) {
         $this->initDataProvider();
         if ($this->createdBy) {
             $this->dataProvider->query->andWhere([$className::tableName() . '.created_by' => $this->createdBy]);
         }
         if ($this->active) {
             $this->dataProvider->query->andWhere([$className::tableName() . '.active' => $this->active]);
         }
         if ($this->content_ids) {
             $this->dataProvider->query->andWhere([$className::tableName() . '.content_id' => $this->content_ids]);
         }
         if ($this->limit) {
             $this->dataProvider->query->limit($this->limit);
         }
         $treeIds = (array) $this->tree_ids;
         if ($this->enabledCurrentTree == Cms::BOOL_Y) {
             $tree = \Yii::$app->cms->currentTree;
             if ($tree) {
                 if ($this->enabledCurrentTreeChild == Cms::BOOL_Y) {
                     if ($this->enabledCurrentTreeChildAll == Cms::BOOL_Y) {
                         $treeIds = $tree->getDescendants()->select(['id'])->indexBy('id')->asArray()->all();
                         $treeIds = array_keys($treeIds);
                     } else {
                         if ($childrens = $tree->children) {
                             foreach ($childrens as $chidren) {
                                 $treeIds[] = $chidren->id;
                             }
                         }
                     }
                 }
                 $treeIds[] = $tree->id;
             }
         }
         if ($treeIds) {
             foreach ($treeIds as $key => $treeId) {
                 if (!$treeId) {
                     unset($treeIds[$key]);
                 }
             }
             if ($treeIds) {
                 /**
                  * @var $query ActiveQuery
                  */
                 $query = $this->dataProvider->query;
                 $query->joinWith('cmsContentElementTrees');
                 $query->andWhere(['or', [$className::tableName() . '.tree_id' => $treeIds], [CmsContentElementTree::tableName() . '.tree_id' => $treeIds]]);
             }
         }
         if ($this->enabledActiveTime == Cms::BOOL_Y) {
             $this->dataProvider->query->andWhere(["<=", $className::tableName() . '.published_at', \Yii::$app->formatter->asTimestamp(time())]);
             $this->dataProvider->query->andWhere(['or', [">=", $className::tableName() . '.published_to', \Yii::$app->formatter->asTimestamp(time())], [CmsContentElement::tableName() . '.published_to' => null]]);
         }
         /**
          *
          */
         if ($this->with) {
             $this->dataProvider->query->with($this->with);
         }
         $this->dataProvider->query->groupBy([$className::tableName() . '.id']);
         if ($this->activeQueryCallback && is_callable($this->activeQueryCallback)) {
             $callback = $this->activeQueryCallback;
             $callback($this->dataProvider->query);
         }
         if ($this->dataProviderCallback && is_callable($this->dataProviderCallback)) {
             $callback = $this->dataProviderCallback;
             $callback($this->dataProvider);
         }
         $result = parent::_run();
         \Yii::$app->cache->set($cacheKey, $result, (int) $this->runCacheDuration, $dependency);
     }
     return $result;
 }
コード例 #20
0
        $searchRelatedPropertiesModel->search($dataProvider);

         /**
         * @var $model \skeeks\cms\models\CmsContentElement
         */
        if ($model->relatedPropertiesModel)
        {
            foreach ($model->relatedPropertiesModel->toArray($model->relatedPropertiesModel->attributes()) as $name => $value) {

                $property = $model->relatedPropertiesModel->getRelatedProperty($name);
                $filter = '';

                if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_ELEMENT)
                {
                    $propertyType = $property->handler;
                        $options = \skeeks\cms\models\CmsContentElement::find()->active()->andWhere([
                            'content_id' => $propertyType->content_id
                        ])->all();

                        $items = \yii\helpers\ArrayHelper::merge(['' => ''], \yii\helpers\ArrayHelper::map(
                            $options, 'id', 'name'
                        ));

                    $filter = \yii\helpers\Html::activeDropDownList($searchRelatedPropertiesModel, $name, $items, ['class' => 'form-control']);

                } else if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_LIST)
                {
                    $items = \yii\helpers\ArrayHelper::merge(['' => ''], \yii\helpers\ArrayHelper::map(
                        $property->enums, 'id', 'value'
                    ));
コード例 #21
0
ファイル: ShopOrder.php プロジェクト: skeeks-cms/cms-shop
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getStore()
 {
     return $this->hasOne(CmsContentElement::className(), ['id' => 'store_id']);
 }
コード例 #22
0
 /**
  *
  * Получение доступных опций для свойства
  * @param CmsContentProperty $property
  * @return $this|array|\yii\db\ActiveRecord[]
  */
 public function getRelatedPropertyOptions($property)
 {
     $options = [];
     if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_ELEMENT) {
         $propertyType = $property->handler;
         if ($this->elementIds) {
             $availables = \skeeks\cms\models\CmsContentElementProperty::find()->select(['value_enum'])->indexBy('value_enum')->andWhere(['element_id' => $this->elementIds])->andWhere(['property_id' => $property->id])->asArray()->all();
             $availables = array_keys($availables);
         }
         $options = \skeeks\cms\models\CmsContentElement::find()->active()->andWhere(['content_id' => $propertyType->content_id]);
         if ($this->elementIds) {
             $options->andWhere(['id' => $availables]);
         }
         $options = $options->select(['id', 'name'])->asArray()->all();
         $options = \yii\helpers\ArrayHelper::map($options, 'id', 'name');
     } elseif ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_LIST) {
         $options = $property->getEnums()->select(['id', 'value']);
         if ($this->elementIds) {
             $availables = \skeeks\cms\models\CmsContentElementProperty::find()->select(['value_enum'])->indexBy('value_enum')->andWhere(['element_id' => $this->elementIds])->andWhere(['property_id' => $property->id])->asArray()->all();
             $availables = array_keys($availables);
             $options->andWhere(['id' => $availables]);
         }
         $options = $options->asArray()->all();
         $options = \yii\helpers\ArrayHelper::map($options, 'id', 'value');
     }
     return $options;
 }
コード例 #23
0
 /**
  * @param $name
  * @return array|mixed|string
  */
 public function getSmartAttribute($name)
 {
     /**
      * @var $property RelatedPropertyModel
      */
     $value = $this->getAttribute($name);
     $property = $this->getRelatedProperty($name);
     if ($property->property_type == PropertyType::CODE_LIST) {
         if ($property->multiple == Cms::BOOL_Y) {
             if ($property->enums) {
                 $result = [];
                 foreach ($property->enums as $enum) {
                     if (in_array($enum->id, $value)) {
                         $result[$enum->code] = $enum->value;
                     }
                 }
                 return $result;
             }
         } else {
             if ($property->enums) {
                 $enum = array_shift($property->enums);
                 foreach ($property->enums as $enum) {
                     if ($enum->id == $value) {
                         return $enum->value;
                     }
                 }
             }
             return "";
         }
     } else {
         if ($property->property_type == PropertyType::CODE_ELEMENT) {
             if ($property->multiple == Cms::BOOL_Y) {
                 return ArrayHelper::map(CmsContentElement::find()->where(['id' => $value])->all(), 'id', 'name');
             } else {
                 if ($element = CmsContentElement::find()->where(['id' => $value])->one()) {
                     return $element->name;
                 }
                 return "";
             }
         } else {
             return $value;
         }
     }
 }
コード例 #24
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContentElement()
 {
     return $this->hasOne(CmsContentElement::className(), ['id' => 'content_element_id']);
 }
コード例 #25
0
 /**
  * @param CmsContent $cmsContent
  * @return array
  */
 public static function getColumnsByContent($cmsContent = null, $dataProvider = null)
 {
     $autoColumns = [];
     if (!$cmsContent) {
         return [];
     }
     $model = CmsContentElement::find()->where(['content_id' => $cmsContent->id])->one();
     if (!$model) {
         $model = new CmsContentElement(['content_id' => $cmsContent->id]);
     }
     if (is_array($model) || is_object($model)) {
         foreach ($model as $name => $value) {
             $autoColumns[] = ['attribute' => $name, 'visible' => false, 'format' => 'raw', 'class' => \yii\grid\DataColumn::className(), 'value' => function ($model, $key, $index) use($name) {
                 if (is_array($model->{$name})) {
                     return implode(",", $model->{$name});
                 } else {
                     return $model->{$name};
                 }
             }];
         }
         $searchRelatedPropertiesModel = new \skeeks\cms\models\searchs\SearchRelatedPropertiesModel();
         $searchRelatedPropertiesModel->initProperties($cmsContent->cmsContentProperties);
         $searchRelatedPropertiesModel->load(\Yii::$app->request->get());
         if ($dataProvider) {
             $searchRelatedPropertiesModel->search($dataProvider);
         }
         /**
          * @var $model \skeeks\cms\models\CmsContentElement
          */
         if ($model->relatedPropertiesModel) {
             $autoColumns = ArrayHelper::merge($autoColumns, GridViewStandart::getColumnsByRelatedPropertiesModel($model->relatedPropertiesModel, $searchRelatedPropertiesModel));
         }
     }
     return $autoColumns;
 }
コード例 #26
0
 /**
  * @return CmsContentElement
  */
 public function getCmsContentElement()
 {
     if ($id = $this->model->{$this->attribute}) {
         return CmsContentElement::findOne($id);
     }
 }
コード例 #27
0
 /**
  * Returns the list of attribute names.
  * By default, this method returns all public non-static properties of the class.
  * You may override this method to change the default behavior.
  * @return array list of attribute names.
  */
 public function attributes()
 {
     $class = new \ReflectionClass($this);
     $names = [];
     foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
         if (!$property->isStatic()) {
             $names[] = $property->getName();
         }
     }
     return ArrayHelper::merge(parent::attributes(), $names);
 }
コード例 #28
0
 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);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #29
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentElement()
 {
     return $this->hasOne(CmsContentElement::className(), ['id' => 'shop_product_id']);
 }
コード例 #30
0
ファイル: User.php プロジェクト: skeeks-cms/cms
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFavoriteCmsContentElements()
 {
     return $this->hasMany(CmsContentElement::className(), ['id' => 'cms_content_element_id'])->via('cmsContentElement2cmsUsers');
 }