Пример #1
0
 public function search($q)
 {
     $sub = explode(' ', $q);
     /* get from catalog */
     $rows_query = (new \yii\db\Query())->select(["CONCAT('catalog') AS module", 'id' => 'id', 'text' => 'title'])->from(['t' => \app\modules\catalog\models\Catalog::tableName()]);
     foreach ($sub as $word) {
         $rows_query->andWhere(['or', ['like', 'title', $word], ['like', 'content', $word], ['exists', (new \yii\db\Query())->select(['id'])->from(['v' => \app\modules\catalog\models\CatalogValues::tableName()])->where('v.catalog_id = t.id')->andWhere(['like', 'value', $word])]]);
     }
     foreach ($rows_query->all() as $row) {
         $this->_results[] = ['url' => Url::to(['/catalog/position/view', 'id' => $row['id']]), 'text' => $row['text']];
     }
     return $this->_results;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->category_id) {
         throw new InvalidConfigException('The "category_id" property must be set.');
     }
     $query = Catalog::find()->select(['id', 'title', 'cost', 'category_id'])->where(['category_id' => $this->category_id]);
     $this->categoryAttributes = CatalogAttributes::find()->where(['category_id' => $this->category_id])->orderBy('id')->all();
     $query = (new \yii\db\Query())->select(['t.id', 't.title', 't.cost', 't.category_id'])->from(['t' => $query]);
     foreach ($this->categoryAttributes as $x) {
         $query->addSelect([$x->code . '.value as ' . $x->code]);
         $query->leftJoin([$x->code => (new \yii\db\Query())->from(CatalogValues::tableName())], $x->code . '.catalog_id = t.id and ' . $x->code . '.attribute_id = ' . $x->id);
         $query->addSelect(['categoryAttribute[' . $x->id . ']' => 'categoryAttribute[' . $x->id . '].value']);
         $query->leftJoin(['categoryAttribute[' . $x->id . ']' => (new \yii\db\Query())->from(CatalogValues::tableName())], ['categoryAttribute[' . $x->id . '].catalog_id' => 't.id', 'categoryAttribute[' . $x->id . '].attribute_id' => $x->id]);
     }
     $query = (new \yii\db\Query())->select(['t.*'])->from(['t' => $query]);
     $this->query = $query;
     parent::init();
 }
Пример #3
0
 public function __get($attribute)
 {
     if (!isset($this->__attributes) && isset($this->id)) {
         $atts = $this->allCategoryAttributes;
         if (is_array($atts)) {
             foreach ($atts as $att) {
                 $this->__attributes[$att->code] = CatalogValues::find()->where(['catalog_id' => $this->id, 'attribute_id' => $att->id])->one();
             }
         }
     }
     if (isset($this->__attributes[$attribute])) {
         return $this->__attributes[$attribute]->value;
     }
     return parent::__get($attribute);
 }
Пример #4
0
                                         'min' => (int)CatalogValues::find()->where(['attribute_id'=> $value->categoryAttribute->id])->min('FLOOR(CAST(value AS DECIMAL(16,4)))'),
                                         'max' => (int)CatalogValues::find()->where(['attribute_id'=> $value->categoryAttribute->id])->max('CEIL(CAST(value AS DECIMAL(16,4)))'),
                                         'step' => pow(10,($delta >= 0 ? strlen(floor($delta)) : -strlen(floor(1/$delta))) -2),
                                         'ticks' => $ticks,
                                         'ticks_labels' => $ticks_labels,
                                  ]
                              ]);
                              break;*/
         case CatalogAttributes::FILTER_TYPE_CHECKBOX:
             echo $form->field($searchModel, 'attributeValues[' . $key . '][value]')->checkboxList(ArrayHelper::map(CatalogValues::find()->where(['attribute_id' => $value->categoryAttribute->id])->distinct('value')->all(), 'value', 'value'), ['multiple' => true])->label($value->categoryAttribute->title . ($value->categoryAttribute->measure ? ', ' . $value->categoryAttribute->measure : ''));
             break;
         case CatalogAttributes::FILTER_TYPE_BOOLEAN:
             echo $form->field($searchModel, 'attributeValues[' . $key . '][value]')->checkbox()->label($value->categoryAttribute->title . ($value->categoryAttribute->measure ? ', ' . $value->categoryAttribute->measure : ''));
             break;
         default:
             echo $form->field($searchModel, 'attributeValues[' . $key . '][value]')->widget(Select2::classname(), ['data' => \yii\helpers\ArrayHelper::map(\app\modules\catalog\models\CatalogValues::find()->filterWhere(['attribute_id' => $value->attribute_id])->all(), 'value', 'value'), 'options' => ['placeholder' => \Yii::t('app', 'Select a {field}', ['field' => $value->categoryAttribute->title])], 'pluginOptions' => ['allowClear' => true]])->label($value->categoryAttribute->title . ($value->categoryAttribute->measure ? ', ' . $value->categoryAttribute->measure : ''));
     }
 }
 $delta = (int) $searchModel::find()->where(['category_id' => $searchModel->category->id])->max('cost') - (int) $searchModel::find()->where(['category_id' => $searchModel->category->id])->min('cost');
 $q = $delta >= 0 ? strlen(floor($delta)) : -strlen(floor(1 / $delta));
 $step = pow(10, $q - 2);
 $ticks = [(double) $searchModel::find()->where(['category_id' => $searchModel->category->id])->min('cost')];
 for ($x = 1; $x < 4; $x++) {
     $ticks[] = round($delta / 4 * $x + (int) $searchModel::find()->where(['category_id' => $searchModel->category->id])->min('cost'), -($q - 2));
 }
 $ticks[] = (double) $searchModel::find()->where(['category_id' => $searchModel->category->id])->max('cost');
 foreach ($ticks as $key => $val) {
     $ticks_labels[$key] = $val . ' р.';
 }
 echo '<div class="form-group">';
 echo $form->field($searchModel, 'cost', ['template' => '{beginLabel}{labelTitle}{endLabel}', 'options' => ['class' => 'list-inline']]);