/** * @inheritdoc */ public function getKey() { if ($key = parent::getKey()) { return $key; } else { return ($this->lower_bound ?: '*') . '-' . ($this->upper_bound ?: '*'); } }
/** * @inheritdoc */ public function attributeLabels() { return array_merge(parent::attributeLabels(), ['term' => Module::t('facet-value', 'Term')]); }
/** * Gets facet values from data array. * * @param array $data * @param string $formName * @return FacetValue[] */ protected function getValuesFromData($data, $formName = null) { if ($formName === null) { $formName = 'FacetValues'; } $values = []; if (!empty($data[$formName])) { $pks = []; $existingValues = []; foreach ($data[$formName] as $valueData) { if (!empty($valueData['id'])) { $pks[] = $valueData['id']; } } if ($pks) { $existingValues = FacetValue::find(['id' => $pks])->indexBy('id')->all(); } /** @var \im\search\components\SearchManager $searchManager */ $searchManager = Yii::$app->get('searchManager'); foreach ($data[$formName] as $key => $valueData) { if (!empty($valueData['id']) && isset($existingValues[$valueData['id']])) { $values[$key] = $existingValues[$valueData['id']]; } else { $values[$key] = isset($valueData['type']) ? $searchManager->getFacetValueInstance($valueData['type']) : new FacetValue(); } } } return $values; }
/** * @inheritdoc */ public function attributeLabels() { return array_merge(parent::attributeLabels(), ['lower_bound' => Module::t('facet-value', 'Lower bound'), 'upper_bound' => Module::t('facet-value', 'Upper bound'), 'include_lower_bound' => Module::t('facet-value', 'Include lower bound'), 'include_upper_bound' => Module::t('facet-value', 'Include upper bound')]); }