public function actionIndex($category_id = null) { $searchModel = new Category(); $searchModel->active = 1; $params = Yii::$app->request->get(); $dataProvider = $searchModel->search($params); $selectedCategory = null; if ($category_id !== null) { $selectedCategory = Category::findById($category_id); } if ($selectedCategory !== null) { if (Yii::$app->request->isPost === true) { $newProperty = isset($_GET['add_property_id']) ? Property::findById($_GET['add_property_id']) : null; if ($newProperty !== null) { $filterSet = new FilterSets(); $filterSet->category_id = $selectedCategory->id; $filterSet->property_id = $newProperty->id; $filterSet->sort_order = 65535; $filterSet->save(); } } } $groups = PropertyGroup::getForObjectId(Object::getForClass(Product::className())->id, false); $propertiesDropdownItems = []; foreach ($groups as $group) { $item = ['label' => $group->name, 'url' => '#', 'items' => []]; $properties = Property::getForGroupId($group->id); foreach ($properties as $prop) { $item['items'][] = ['label' => $prop->name, 'url' => '?category_id=' . $category_id . '&add_property_id=' . $prop->id, 'linkOptions' => ['class' => 'add-property-to-filter-set', 'data-property-id' => $prop->id, 'data-action' => 'post']]; } $propertiesDropdownItems[] = $item; } return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'selectedCategory' => $selectedCategory, 'propertiesDropdownItems' => $propertiesDropdownItems]); }
/** * Renders the widget. * * @return string */ public function run() { if ($this->type == 'list') { $items = []; foreach ($this->model->options as $option) { $items[] = $option->name; } return $this->render($this->listView, ['items' => $items, 'model' => $this->model]); } else { $propertyGroup = Json::decode($this->model->option_generate)['group']; $items = []; $optionsJson = []; foreach ($this->model->options as $option) { $optionProperties = $option->getPropertyGroups()[$propertyGroup]; $itemsJson = []; foreach ($optionProperties as $key => $property) { foreach ($property->values as $name => $propValue) { if (!isset($items[$key])) { $items[$key] = ['name' => Property::findById($propValue['property_id'])->name]; } if (!isset($firstOption)) { $firstOption[$key] = $propValue['psv_id']; } $items[$key]['values'][$propValue['psv_id']] = $propValue['name']; $itemsJson[$key] = $propValue['psv_id']; } } $optionsJson[] = ['id' => $option->id, 'values' => $itemsJson, 'price' => $option->convertedPrice(), 'old_price' => $option->convertedPrice(null, true)]; } return $this->render($this->formView, ['model' => $this->model, 'items' => $items, 'optionsJson' => $optionsJson]); } }
/** * @inheritdoc */ public function getNextPart($full_url, $next_part, &$previous_parts) { $property = Property::findById($this->property_id); if (is_null($property)) { return false; } if ($property->has_static_values && $property->has_slugs_in_values) { $cacheTags = []; $static_values = PropertyStaticValues::getValuesForPropertyId($this->property_id); $slugs = explode('/', $next_part); foreach ($static_values as $value) { if ($slugs[0] === $value['slug']) { $this->parameters = ['properties' => [$this->property_id => [$value['id']]]]; if (!empty($value['title_append'])) { $this->parameters['title_append'] = [$value['title_append']]; } $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $value['id']); $part = new self(['gathered_part' => $value['slug'], 'rest_part' => mb_substr($next_part, mb_strlen($value['slug'])), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]); return $part; } } return false; } else { return false; } }
/** * @param null $property_id * @param null $handler_action * @param null $model_id * @return mixed */ public function run($property_id = null, $handler_action = null, $model_id = null) { if (null === $handler_action || null === $property_id || null === $model_id) { return ''; } $property = Property::findById($property_id); if (null === $property) { return ''; } $actionParams = ['model_name' => $this->modelName, 'model_id' => $model_id, 'object_id' => $this->objectId, 'property' => $property]; $propertyHandler = PropertyHandlers::createHandler($property->handler); return $propertyHandler->runAction($handler_action, $actionParams); }
/** * Get property group id by property id * @param int $id property id * @return int property group id */ private function getGroupIdBypropertyId($id) { foreach ($this->property_id_to_group_id as $groupId => $propertyIds) { if (in_array($id, $propertyIds)) { return $groupId; } } $property = Property::findById($id); if (!array_key_exists($property->property_group_id, $this->property_id_to_group_id)) { $this->property_id_to_group_id[$property->property_group_id] = [$id]; } else { $this->property_id_to_group_id[$property->property_group_id][] = $id; } return intval($property->property_group_id); }
/** * @inheritdoc */ public function getNextPart($full_url, $next_part, &$previous_parts) { $property = Property::findById($this->property_id); if (is_null($property)) { return false; } if ($property->has_static_values && $property->has_slugs_in_values) { $cacheTags = []; $static_values = PropertyStaticValues::getValuesForPropertyId($this->property_id); $slugs = explode('/', $next_part); $currentSlug = 0; $slugsCount = count($slugs); $appliedParts = []; foreach ($static_values as $value) { if ($slugs[$currentSlug] === $value['slug']) { $appliedParts[] = $value['slug']; if (isset($this->parameters['properties'][$this->property_id])) { $this->parameters['properties'][$this->property_id][] = $value['id']; } else { $this->parameters = ['properties' => [$this->property_id => [$value['id']]]]; } if (!empty($value['title_append'])) { if ($value["title_prepend"] == 1) { $this->addParam("title_prepend", $value["title_append"]); } else { $this->addParam("title_append", $value["title_append"]); } } $cacheTags[] = ActiveRecordHelper::getObjectTag(PropertyStaticValues::className(), $value['id']); $currentSlug++; if ($currentSlug == $slugsCount) { break; } } } if ($currentSlug > 0) { $appliedPartsString = implode('/', $appliedParts); $part = new self(['gathered_part' => $appliedPartsString, 'rest_part' => mb_substr($next_part, mb_strlen($appliedPartsString)), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]); return $part; } return false; } else { return false; } }
public function filter(ActiveQuery $query, &$cacheKeyAppend) { $get = Yii::$app->request->post(); if (isset($get['changeValue']) && is_array($get['changeValue'])) { foreach ($get['changeValue'] as $propertyId => $isActive) { if ($isActive && isset($get[$this->minValueAttribute][$propertyId]) && isset($get[$this->maxValueAttribute][$propertyId]) && is_numeric($get[$this->minValueAttribute][$propertyId]) && is_numeric($get[$this->maxValueAttribute][$propertyId])) { $property = Property::findById($propertyId); if ($property->has_static_values) { $query->innerJoin('{{%object_static_values}} as osvf' . $propertyId, '{{%product}}.id=osvf' . $propertyId . '.object_model_id'); $query->innerJoin('{{%property_static_values}} as psvf' . $propertyId, 'psvf' . $propertyId . '.id=osvf' . $propertyId . '.property_static_value_id'); $query->andWhere('psvf' . $propertyId . '.value >= :minData ')->andWhere('psvf' . $propertyId . '.value <= :maxData ')->andWhere(['psvf' . $propertyId . '.property_id' => $propertyId])->addParams([':minData' => (int) $get[$this->minValueAttribute][$propertyId], ':maxData' => (int) $get[$this->maxValueAttribute][$propertyId]]); } elseif ($property->is_eav) { $query->innerJoin('{{%product_eav}} as peav' . $propertyId, '{{%product}}.id=peav' . $propertyId . '.object_model_id'); $query->andWhere(['peav' . $propertyId . '.property_group_id' => $property->property_group_id, 'peav' . $propertyId . '.key' => $property->key]); $query->andWhere(['>=', 'peav' . $propertyId . '.value', (int) $get[$this->minValueAttribute][$propertyId]]); $query->andWhere(['<=', 'peav' . $propertyId . '.value', (int) $get[$this->maxValueAttribute][$propertyId]]); } $cacheKeyAppend .= 'FilterRangeProperty:propertyId' . $propertyId . ':[min:' . (int) $get[$this->minValueAttribute][$propertyId] . ':max' . (int) $get[$this->maxValueAttribute][$propertyId] . ']'; } } } return $query; }
public function actionEditProperty($property_group_id, $id = null) { if ($id === null) { $model = new Property(); $model->handler_additional_params = '[]'; } else { $model = Property::findById($id); } $object = Object::getForClass(Property::className()); $model->property_group_id = $property_group_id; if ($model->load(\Yii::$app->request->post()) && $model->validate()) { $propertyHandler = PropertyHandlers::createHandler($model->handler); if (!$propertyHandler->changePropertyType($model)) { if ($model->is_column_type_stored) { if ($model->isNewRecord) { $object = Object::findById($model->group->object_id); Yii::$app->db->createCommand()->addColumn($object->column_properties_table_name, $model->key, "TINYTEXT")->execute(); if ($object->object_class == Form::className()) { $submissionObject = Object::getForClass(Submission::className()); $col_type = $this->getColumnType($model->value_type); Yii::$app->db->createCommand()->addColumn($submissionObject->column_properties_table_name, $model->key, $col_type)->execute(); } } else { if ($model->key != $model->getOldAttribute('key')) { $object = Object::findById($model->group->object_id); Yii::$app->db->createCommand()->renameColumn($object->column_properties_table_name, $model->getOldAttribute('key'), $model->key)->execute(); if ($object->object_class == Form::className()) { $submissionObject = Object::getForClass(Submission::className()); Yii::$app->db->createCommand()->renameColumn($submissionObject->column_properties_table_name, $model->getOldAttribute('key'), $model->key)->execute(); } } if ($model->value_type != $model->getOldAttribute('value_type')) { $object = Object::findById($model->group->object_id); $new_type = $this->getColumnType($model->value_type); Yii::$app->db->createCommand()->alterColumn($object->column_properties_table_name, $model->getOldAttribute('key'), $new_type)->execute(); if ($object->object_class == Form::className()) { $submissionObject = Object::getForClass(Submission::className()); Yii::$app->db->createCommand()->renameColumn($submissionObject->column_properties_table_name, $model->getOldAttribute('key'), $new_type)->execute(); } } } } } $save_result = $model->save(); if ($save_result) { $this->runAction('save-info'); Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved')); $returnUrl = Yii::$app->request->get('returnUrl', ['/backend/properties/group', 'id' => $property_group_id]); switch (Yii::$app->request->post('action', 'save')) { case 'next': return $this->redirect(['/backend/properties/edit-property', 'property_group_id' => $property_group_id, 'returnUrl' => $returnUrl]); case 'back': return $this->redirect($returnUrl); default: return $this->redirect(Url::toRoute(['/backend/properties/edit-property', 'id' => $model->id, 'property_group_id' => $model->property_group_id, 'returnUrl' => $returnUrl])); } } else { Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data')); } } $searchModel = new PropertyStaticValues(); $searchModel->property_id = $model->id; $dataProvider = $searchModel->search($_GET); return $this->render('edit-property', ['model' => $model, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'fieldinterpretParentId' => 0, 'object' => $object]); }
public function updateValues($new_values, $object_id, $object_model_id) { $column_type_updates = ['object_model_id' => $object_model_id]; $osv_psv_ids = []; $new_eav_values = []; $eav_ids_to_delete = []; foreach ($new_values as $key => $values) { $property = Property::findById($values->property_id); if ($property->captcha == 1) { continue; } if (!isset($this->values_by_property_key[$key])) { // нужно добавить if ($property->is_column_type_stored) { $column_type_updates[$key] = (string) $values; } elseif ($property->has_static_values) { foreach ($values->values as $val) { $osv_psv_ids[] = $val['value']; } } elseif ($property->is_eav) { $new_eav_values[$key] = $values; } } else { if ($property->is_column_type_stored) { $column_type_updates[$key] = (string) $values; } elseif ($property->has_static_values) { foreach ($values->values as $val) { $osv_psv_ids[] = $val['value']; } } elseif ($property->is_eav) { // добавим новые foreach ($values->values as $val) { $exist_in_old = false; foreach ($this->values_by_property_key[$key]->values as $old_val) { if ($old_val['value'] == $val['value']) { $exist_in_old = true; break; } } if ($exist_in_old == false) { $new_eav_values[] = [$object_model_id, $values->property_group_id, $key, $val['value'], 0]; } } // теперь добавим на удаление foreach ($this->values_by_property_key[$key]->values as $old_val) { $exist_in_new = false; foreach ($values->values as $new_val) { if ($old_val['value'] == $new_val['value']) { $exist_in_new = true; break; } } if ($exist_in_new == false) { // @todo find why sometimes it isn't exist if (isset($old_val['eav_id'])) { $eav_ids_to_delete[] = $old_val['eav_id']; } } } } } } $osv_psv_ids_to_delete = []; foreach ($this->values_by_property_key as $key => $values) { $property = Property::findById($values->property_id); if (in_array($key, array_keys($new_values)) === false) { // if in incoming array there was no specification for this property - skip it continue; } if ($property->has_static_values) { foreach ($values->values as $val) { if (in_array($val['psv_id'], $osv_psv_ids) === false) { // в новых значениях нет $osv_psv_ids_to_delete[] = $val['psv_id']; } else { // удалим, чтобы заново не добавлять unset($osv_psv_ids[array_search($val['psv_id'], $osv_psv_ids)]); } } } } if (count($osv_psv_ids_to_delete) > 0) { ObjectStaticValues::deleteAll(['and', '`object_id` = :objectId', ['and', '`object_model_id` = :objectModelId', ['in', '`property_static_value_id`', $osv_psv_ids_to_delete]]], [':objectId' => $object_id, ':objectModelId' => $object_model_id]); } if (count($osv_psv_ids) > 0) { $rows = []; foreach ($osv_psv_ids as $psv_id) { // 0 - Not Selected Field. Такие значения в базу не сохраняем if ($psv_id == 0) { continue; } $rows[] = [$object_id, $object_model_id, $psv_id]; } if (!empty($rows)) { Yii::$app->db->createCommand()->batchInsert(ObjectStaticValues::tableName(), ['object_id', 'object_model_id', 'property_static_value_id'], $rows)->execute(); } } Yii::$app->cache->delete("PSV:" . $object_id . ":" . $object_model_id); if (count($column_type_updates) > 1) { $table_name = Object::findById($object_id)->column_properties_table_name; $exists = Yii::$app->db->createCommand('select object_model_id from ' . $table_name . ' where object_model_id=:object_model_id')->bindValue(':object_model_id', $object_model_id)->queryScalar(); if ($exists) { Yii::$app->db->createCommand()->update($table_name, $column_type_updates, 'object_model_id = :object_model_id', [':object_model_id' => $object_model_id])->execute(); } else { Yii::$app->db->createCommand()->insert($table_name, $column_type_updates)->execute(); } } if (count($new_eav_values) > 0) { $table_name = Object::findById($object_id)->eav_table_name; Yii::$app->db->createCommand()->batchInsert($table_name, ['object_model_id', 'property_group_id', 'key', 'value', 'sort_order'], $new_eav_values)->execute(); } if (count($eav_ids_to_delete) > 0) { $table_name = Object::findById($object_id)->eav_table_name; Yii::$app->db->createCommand()->delete($table_name, ['in', 'id', $eav_ids_to_delete])->execute(); } Yii::$app->cache->delete("TIR:" . $object_id . ':' . $object_model_id); $this->values_by_property_key = $new_values; }
</td> <td> <?php echo Yii::t('app', 'Actions'); ?> </td> </tr> </thead> <tbody class="properties-body"> <?php foreach ($sets as $filterSet) { ?> <?php /** @var \app\modules\shop\models\FilterSets $filterSet */ $rowClass = $filterSet->category_id === $selectedCategory->id ? $filterSet->delegate_to_children === 1 ? 'success' : '' : 'info'; $property = \app\models\Property::findById($filterSet->property_id); ?> <tr class="<?php echo $rowClass; ?> " property-id="<?php echo $property->id; ?> " filterset-id="<?php echo $filterSet->id; ?> "> <td class="td-no-padding"> <span class="sort-handle"> <?php echo Icon::show('arrows-v');
public function beforeDelete() { if (null !== ($parent = Property::findById($this->property_id))) { $parent->invalidateModelCache(); } return parent::beforeDelete(); }
/** * Добавляет к запросу фильтры по свойствам * @param $object Object * @param $query ActiveQuery * @param $values_by_property_id array * @param array $dynamic_values_by_property_id array * @throws \Exception */ public static function appendPropertiesFilters($object, &$query, $values_by_property_id, $dynamic_values_by_property_id = []) { /** @avr $object Object */ // сначала сгруппируем свойства по типу хранения $by_storage = ['eav' => [], 'table_inheritance' => [], 'static_values' => []]; $dynamic_by_storage = ['eav' => [], 'table_inheritance' => []]; foreach ($values_by_property_id as $property_id => $values) { // values может быть просто строкой(одно значение), а может уже прийти массивом $values = (array) $values; $property = Property::findById($property_id); if ($property === null) { continue; } if ($property->is_eav) { $by_storage['eav'][] = ['property' => $property, 'values' => $values]; } elseif ($property->is_column_type_stored) { $by_storage['table_inheritance'][] = ['property' => $property, 'values' => $values]; } elseif ($property->has_static_values) { $by_storage['static_values'][] = ['property' => $property, 'values' => $values]; } else { throw new \Exception("Wrong property type for " . $property->id); } } foreach ($dynamic_values_by_property_id as $property_id => $values) { $property = Property::findById($property_id); if ($property) { if ($property->is_eav) { $dynamic_by_storage['eav'][] = ['property' => $property, 'values' => $values]; } elseif ($property->is_column_type_stored) { $dynamic_by_storage['table_inheritance'][] = ['property' => $property, 'values' => $values]; } else { throw new \Exception("Wrong property type for " . $property->id); } } } $join_counter = 1; $ti_clauses = []; $join_table_name = "PropertiesJoinTable" . $join_counter++; foreach ($by_storage['table_inheritance'] as $item) { $property = $item['property']; $or_clauses = []; foreach ($item['values'] as $val) { $or_clauses[] = "{$join_table_name}." . Yii::$app->db->quoteColumnName($property->key) . " = " . Yii::$app->db->quoteValue($val); } $ti_clauses[] = implode(" OR ", $or_clauses); } foreach ($dynamic_by_storage['table_inheritance'] as $item) { $property = $item['property']; $clauses = []; if (isset($item['values']['min']) && strlen($item['values']['min'])) { $clauses[] = "{$join_table_name}." . Yii::$app->db->quoteColumnName($property->key) . " >= " . Yii::$app->db->quoteValue((double) $item['values']['min']); } if (isset($item['values']['max']) && strlen($item['values']['max'])) { $clauses[] = "{$join_table_name}." . Yii::$app->db->quoteColumnName($property->key) . " <= " . Yii::$app->db->quoteValue((double) $item['values']['max']); } if (!empty($clauses)) { $ti_clauses[] = '(' . implode(" AND ", $clauses) . ')'; } } if (count($ti_clauses) > 0) { $ti_clauses = implode(" AND ", $ti_clauses); $query = $query->innerJoin($object->column_properties_table_name . " {$join_table_name}", "{$join_table_name}.object_model_id = " . Yii::$app->db->quoteTableName($object->object_table_name) . ".id " . " AND " . $ti_clauses); } if (count($by_storage['static_values'])) { foreach ($by_storage['static_values'] as $item) { $joinTableName = 'OSVJoinTable' . $item['property']->id; if (count($item['values']) > 0) { $query = $query->innerJoin(ObjectStaticValues::tableName() . " " . $joinTableName, "{$joinTableName}.object_id = " . intval($object->id) . " AND {$joinTableName}.object_model_id = " . Yii::$app->db->quoteTableName($object->object_table_name) . ".id "); $query = $query->andWhere(new Expression('`' . $joinTableName . '`.`property_static_value_id` in (' . implode(', ', array_map('intval', $item['values'])) . ')')); } } } if (count($by_storage['eav'])) { foreach ($by_storage['eav'] as $item) { $joinTableName = 'EAVJoinTable' . $item['property']->id; if (count($item['values']) > 0) { $query = $query->innerJoin($object->eav_table_name . " " . $joinTableName, "{$joinTableName}.object_model_id = " . Yii::$app->db->quoteTableName($object->object_table_name) . ".id "); $query = $query->andWhere(new Expression('`' . $joinTableName . '`.`value` in (' . implode(', ', array_map('intval', $item['values'])) . ') AND `' . $joinTableName . '`.`key` = "' . $item['property']->key . '"')); } } } }
} } $checkboxes = []; foreach ($select as $value) { if ($hide_others) { if ($dont_hide_value_id != $value['id']) { continue; } } $options = ['class' => 'filter-select ']; $params = [$route]; $params += $current_selections; $params['category_group_id'] = $category_group_id; foreach ($possible_selections as $u_group_id => $u_item) { foreach ($u_item['static_selections'] as $u_property_id => $select) { if (Property::findById($u_property_id)->depends_on_property_id == $property_id) { unset($params['properties'][$u_property_id]); } } } $active = false; if (isset($params['properties'][$property_id]) && is_array($params['properties'][$property_id])) { if (in_array($value['id'], $params['properties'][$property_id])) { $options['class'] .= 'active'; $active = true; } } $params['properties'][$property_id] = [$value['id']]; $disabled = in_array($value['id'], $disabled_ids); $disabled_array = $disabled ? ['disabled' => 'disabled'] : []; $label = $value['name'];
public function columns($baseModelColumns) { $columns = $baseModelColumns; foreach ($this->propertyGroups as $groupId => $properties) { foreach ($properties as $key => $propertyValue) { /** @var PropertyValue $propertyValue */ $prop = Property::findById($propertyValue->property_id); if ($prop->has_static_values) { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }, 'filter' => PropertyStaticValues::getSelectForPropertyId($propertyValue->property_id)]; } elseif ($prop->property_handler_id === 3) { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }, 'filter' => [0 => Yii::t('app', 'No'), 1 => Yii::t('app', 'Yes')]]; } else { $column = ['value' => function ($model) use($prop) { return $model->property($prop->key); }]; } $column = ArrayHelper::merge($column, ['header' => $prop->name, 'attribute' => $prop->key, 'enableSorting' => true]); $columns[] = $column; } } return $columns; }
<?php foreach ($availablePropertyGroups as $id => $properties) { ?> <?php $propertyGroup = \app\models\PropertyGroup::findById($id); ?> <fieldset class="property-group"> <legend><?php echo Html::encode($propertyGroup->name); ?> </legend> <?php foreach ($properties as $key => $propertyValue) { echo '<div class="well well-sm well-light"><b>' . \app\models\Property::findById($propertyValue->property_id)->name . ' (<small>' . $key . '</small>)' . '</b>'; $prefix = 'fields[property][' . $propertyValue->property_id . ']['; echo $form->field($model, $prefix . 'enabled]')->checkbox(['label' => Yii::t('app', 'Process')]); $property = \app\models\Property::findById($propertyValue->property_id); if ($property->has_static_values) { echo $form->field($model, $prefix . 'processValuesAs]')->dropDownList(['text' => Yii::t('app', 'Text representation'), 'id' => 'id ' . Yii::t('app', '(static value record id)'), 'value' => Yii::t('app', 'Value representation')])->label(Yii::t('app', 'Process values as:')); } echo Html::activeHiddenInput($model, $prefix . 'key]', ['value' => $key]); echo '</div><br>'; } ?> </fieldset> <?php } ?> </fieldset>
/** * @param $exportFields * @param array $conditions * @param int $batchSize * @return bool * @throws \Exception */ public function processExport($exportFields = [], $conditions = [], $batchSize = 100) { $fields = $this->getAllFields($exportFields); $class = $this->object->object_class; /** @var $select ActiveQuery */ $select = $class::find(); $representationConversions = ['text' => 'name', 'value' => 'value', 'id' => 'psv_id']; if (isset($conditions['category']) && is_array($conditions['category']) && $this->object->id == Object::getForClass(Product::className())->id) { foreach ($conditions['category'] as $condition) { $joinTableName = 'Category' . $condition['value']; $select->innerJoin("{{%product_category}} " . $joinTableName, "{$joinTableName}.object_model_id = product.id"); $select->andWhere(new Expression('`' . $joinTableName . '`.`category_id` = "' . $condition['value'] . '"')); } } if (isset($conditions['field']) && is_array($conditions['field'])) { foreach ($conditions['field'] as $condition) { $conditionOptions = [$condition['operators'], $condition['value'], $condition['option']]; if ($condition['comparison'] == 'AND') { $select->andWhere($conditionOptions); } elseif ($condition['comparison'] == 'OR') { $select->orWhere($conditionOptions); } } } if (isset($conditions['property']) && is_array($conditions['property'])) { foreach ($conditions['property'] as $condition) { $property = Property::findById($condition['value']); if ($property && isset($condition['option']) && !empty($condition['option'])) { if ($property->is_eav) { $joinTableName = 'EAVJoinTable' . $property->id; $select->innerJoin($this->object->eav_table_name . " " . $joinTableName, "{$joinTableName}.object_model_id = " . Yii::$app->db->quoteTableName($this->object->object_table_name) . ".id "); $select->andWhere(new Expression('`' . $joinTableName . '`.`value` ' . $condition['operators'] . ' "' . $condition['option'] . '" AND `' . $joinTableName . '`.`key` = "' . $property->key . '"')); } elseif ($property->has_static_values) { $joinTableName = 'OSVJoinTable' . $property->id; $propertyStaticValue = PropertyStaticValues::find()->where(['value' => $condition['option']])->one(); if ($propertyStaticValue) { $select->innerJoin(ObjectStaticValues::tableName() . " " . $joinTableName, "{$joinTableName}.object_id = " . intval($this->object->id) . " AND {$joinTableName}.object_model_id = " . Yii::$app->db->quoteTableName($this->object->object_table_name) . ".id "); $select->andWhere(new Expression('`' . $joinTableName . '`.`property_static_value_id` ="' . $propertyStaticValue->id . '"')); } } else { throw new \Exception("Wrong property type for " . $property->id); } } } } $data = []; $batchSize = intval($batchSize) <= 0 ? 100 : intval($batchSize); foreach ($select->each($batchSize) as $object) { $row = []; foreach ($fields['fields_object'] as $field) { if ('internal_id' === $field) { $row[] = $object->id; } else { $row[] = isset($object->{$field}) ? $object->{$field} : ''; } } foreach ($fields['fields_property'] as $field_id => $field) { $value = $object->getPropertyValuesByPropertyId($field_id); if (!is_object($value)) { $value = ''; } elseif (count($value->values) > 1 && isset($fields_property[$field_id])) { if (isset($fields_property[$field_id]['processValuesAs'])) { $attributeToGet = $representationConversions[$fields_property[$field_id]['processValuesAs']]; $newValues = []; foreach ($value->values as $val) { $newValues[] = $val[$attributeToGet]; } $value = implode($this->multipleValuesDelimiter, $newValues); } } else { $value = (string) $value; } $row[] = $value; } if (!empty($fields['fields_additional']) && $object->hasMethod('getAdditionalFields')) { $fieldsFromModel = $object->getAdditionalFields($fields['fields_additional']); foreach ($fields['fields_additional'] as $key => $configuration) { if (!isset($fieldsFromModel[$key])) { $fieldsFromModel[$key] = ''; } if (!empty($fieldsFromModel[$key])) { $value = (array) $fieldsFromModel[$key]; $row[] = implode($this->multipleValuesDelimiter, $value); } else { $row[] = ''; } } } $data[] = $row; } unset($value, $row, $object, $select, $class); return $this->getData($fields['fields_header'], $data); }
* @var $form \yii\widgets\ActiveForm * @var $label string * @var $model \app\properties\AbstractModel * @var $multiple boolean * @var $property_id integer * @var $property_key string * @var $this \app\properties\handlers\Handler * @var $values array */ use app\models\Property; use kartik\helpers\Html; use yii\helpers\Url; ?> <dl> <?php if (count($values->values) == 0) { return; } $property = Property::findById($property_id); echo Html::tag('dt', $property->name); foreach ($values->values as $val) { if (isset($val['value'])) { if ($model->getOwnerModel()->className() === \app\modules\shop\models\Order::className()) { echo Html::tag('dd', Html::a($val['value'], 'http://' . Yii::$app->getModule('core')->serverName . Url::to(['/shop/backend-order/download-file', 'key' => $val['key'], 'orderId' => $values->object_model_id]))); } else { echo Html::tag('dd', Html::a($val['value'], 'http://' . Yii::$app->getModule('core')->serverName . Url::to(['/backend/form/download', 'key' => $val['key'], 'submissionId' => $values->object_model_id]))); } } } ?> </dl>
/** * @return Property */ public function getProperty() { return Property::findById($this->property_id); }