예제 #1
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);
 }
예제 #2
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']]);