Inheritance: extends skeeks\cms\relatedProperties\models\RelatedElementPropertyModel
Example #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentElementProperties()
 {
     return $this->hasMany(CmsContentElementProperty::className(), ['element_id' => 'id']);
 }
Example #2
0
                            <div class="col-md-6">
                                <?php 
echo $form->field($widget->searchOfferRelatedPropertiesModel, $widget->searchOfferRelatedPropertiesModel->getAttributeNameRangeFrom($property->code))->textInput(['placeholder' => 'от'])->label($property->name . "");
?>
                            </div>
                            <div class="col-md-6">
                                <?php 
echo $form->field($widget->searchOfferRelatedPropertiesModel, $widget->searchOfferRelatedPropertiesModel->getAttributeNameRangeTo($property->code))->textInput(['placeholder' => 'до'])->label("&nbsp;");
?>
                            </div>
                        </div>
                    </div>

                <? else : ?>

                    <? $propertiesValues = \skeeks\cms\models\CmsContentElementProperty::find()->select(['value'])->where([
                        'property_id' => $property->id,
                        'element_id'  => $widget->elementIds
                    ])->all(); ?>

                    <? if ($propertiesValues) : ?>
                        <div class="form-group">
                            <div class="row">
                                <div class="col-md-12">

                                <?php 
echo $form->field($widget->searchOfferRelatedPropertiesModel, $property->code)->dropDownList(\yii\helpers\ArrayHelper::merge(['' => ''], \yii\helpers\ArrayHelper::map($propertiesValues, 'value', 'value')));
?>

                                </div>
                            </div>
 /**
  *
  * Получение доступных опций для свойства
  * @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;
 }
 /**
  * @param ActiveDataProvider $activeDataProvider
  */
 public function search(ActiveDataProvider $activeDataProvider)
 {
     /**
      * @var $activeQuery ActiveQuery
      */
     $activeQuery = $activeDataProvider->query;
     //$activeQuery->leftJoin('cms_content_element_property', '`cms_content_element_property`.`element_id` = `cms_content_element`.`id`');
     $elementIdsGlobal = [];
     $applyFilters = false;
     foreach ($this->toArray() as $propertyCode => $value) {
         if ($property = $this->getProperty($propertyCode)) {
             if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_NUMBER) {
                 $elementIds = [];
                 $query = (new \yii\db\Query())->from(CmsContentElementProperty::tableName())->select(['element_id'])->where(["property_id" => $property->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 = (new \yii\db\Query())->from(CmsContentElementProperty::tableName())->select(['element_id'])->where(["value" => $value, "property_id" => $property->id])->all();
             }
             $elementIds = \yii\helpers\ArrayHelper::map($elementIds, "element_id", "element_id");
             if (!$elementIds) {
                 $elementIdsGlobal = [];
             }
             if ($elementIdsGlobal) {
                 $elementIdsGlobal = array_intersect_assoc($elementIds, $elementIdsGlobal);
             } else {
                 $elementIdsGlobal = $elementIds;
             }
         }
     }
     if ($applyFilters) {
         $activeQuery->andWhere(['cms_content_element.id' => $elementIdsGlobal]);
     }
 }
Example #5
0
 /**
  * Конфигурирование объекта запроса поиска по элементам.
  *
  * @param \yii\db\ActiveQuery $activeQuery
  * @param null $modelClassName
  * @return $this
  */
 public function buildElementsQuery(\yii\db\ActiveQuery $activeQuery)
 {
     $where = [];
     //Нужно учитывать связанные дополнительные данные
     if ($this->enabledElementProperties == Cms::BOOL_Y) {
         $activeQuery->joinWith('cmsContentElementProperties');
         //Нужно учитывать настройки связанные дополнительные данных
         if ($this->enabledElementPropertiesSearchable == Cms::BOOL_Y) {
             $activeQuery->joinWith('cmsContentElementProperties.property');
             $where[] = ['and', ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false], [CmsContentProperty::tableName() . ".searchable" => Cms::BOOL_Y]];
         } else {
             $where[] = ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false];
         }
     }
     //Поиск по основному набору полей
     if ($this->searchElementFields) {
         foreach ($this->searchElementFields as $fieldName) {
             $where[] = ['like', CmsContentElement::tableName() . "." . $fieldName, '%' . $this->searchQuery . '%', false];
         }
     }
     if ($where) {
         $where = array_merge(['or'], $where);
         $activeQuery->andWhere($where);
     }
     //Отфильтровать только конкретный тип
     if ($this->searchElementContentIds) {
         $activeQuery->andWhere([CmsContentElement::tableName() . ".content_id" => (array) $this->searchElementContentIds]);
     }
     return $this;
 }