Inheritance: extends skeeks\cms\relatedProperties\models\RelatedPropertyModel
 public function init()
 {
     $this->name = "Управление свойствами";
     $this->modelShowAttribute = "name";
     $this->modelClassName = CmsContentProperty::className();
     parent::init();
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentProperties()
 {
     return $this->hasMany(CmsContentProperty::className(), ['id' => 'property_id'])->via('cmsContentElementProperties');
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsContentProperties()
 {
     return $this->hasMany(CmsContentProperty::className(), ['content_id' => 'id'])->orderBy(['priority' => SORT_ASC]);
 }
Exemplo n.º 4
0
/* @var $this yii\web\View */
/* @var $model \yii\db\ActiveRecord */
$form = ActiveForm::begin();
?>

    <?php 
if ($form_id = \Yii::$app->request->get('property_id')) {
    ?>
        <?php 
    echo $form->field($model, 'property_id')->hiddenInput(['value' => $form_id])->label(false);
    ?>
    <?php 
} else {
    ?>
        <?php 
    echo $form->field($model, 'property_id')->widget(\skeeks\widget\chosen\Chosen::className(), ['items' => \yii\helpers\ArrayHelper::map(\skeeks\cms\models\CmsContentProperty::find()->all(), "id", "name")]);
    ?>
    <?php 
}
?>

    <?php 
echo $form->field($model, 'value')->textInput(['maxlength' => 255]);
?>
    <?php 
echo $form->field($model, 'code')->textInput(['maxlength' => 32]);
?>

    <?php 
echo $form->buttonsCreateOrUpdate($model);
?>
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProperty()
 {
     return $this->hasOne(CmsContentProperty::className(), ['id' => 'property_id']);
 }
 /**
  *
  * Получение доступных опций для свойства
  * @param CmsContentProperty $property
  * @return $this|array|\yii\db\ActiveRecord[]
  */
 public function getOfferRelatedPropertyOptions($property)
 {
     if (isset($this->_offerOptions[$property->code])) {
         return $this->_offerOptions[$property->code];
     }
     if ($property->property_type == \skeeks\cms\relatedProperties\PropertyType::CODE_ELEMENT) {
         $propertyType = $property->handler;
         $availables = [];
         if ($this->childrenElementIds) {
             $availables = \skeeks\cms\models\CmsContentElementProperty::find()->select(['value_enum'])->indexBy('value_enum')->andWhere(['element_id' => $this->childrenElementIds])->andWhere(['property_id' => $property->id])->asArray()->all();
             $availables = array_keys($availables);
         }
         if ($this->onlyExistsFilters && !$availables) {
             return [];
         }
         $options = \skeeks\cms\models\CmsContentElement::find()->active()->andWhere(['content_id' => $propertyType->content_id]);
         if ($this->childrenElementIds) {
             $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']);
         $availables = [];
         if ($this->childrenElementIds) {
             $availables = \skeeks\cms\models\CmsContentElementProperty::find()->select(['value_enum'])->indexBy('value_enum')->andWhere(['element_id' => $this->childrenElementIds])->andWhere(['property_id' => $property->id])->asArray()->all();
             $availables = array_keys($availables);
             $options->andWhere(['id' => $availables]);
         }
         if ($this->onlyExistsFilters && !$availables) {
             return [];
         }
         $options = $options->asArray()->all();
         $options = \yii\helpers\ArrayHelper::map($options, 'id', 'value');
     }
     $this->_offerOptions[$property->code] = $options;
     return $options;
 }
Exemplo n.º 7
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;
 }