/**
*
* Получение доступных опций для свойства
* @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;
}