/**
  * @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();
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CatalogAttributes::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'disabled' => $this->disabled]);
     $query->joinWith(['category' => function ($query) {
         $query->from(['category' => '{{%catalog_categories}}']);
     }]);
     $dataProvider->sort->attributes['category.title'] = ['asc' => ['category.title' => SORT_ASC], 'desc' => ['category.title' => SORT_DESC]];
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'category.title', $this->getAttribute('category.title')]);
     return $dataProvider;
 }
Example #3
0
 public function getAllCategoryAttributes()
 {
     return $this->hasMany(CatalogAttributes::className(), ['category_id' => 'category_id']);
 }
Example #4
0
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 50]);
?>

    <?php 
echo $form->field($model, 'code')->textInput();
?>

    <?php 
echo $form->field($model, 'data_type')->dropDownList(CatalogAttributes::datatypeList());
?>

    <?php 
echo $form->field($model, 'filter_type')->dropDownList(CatalogAttributes::filterList());
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\app\modules\catalog\models\CatalogCategoriesSearch::find()->all(), 'id', 'title'), ['prompt' => ' -- ' . \Yii::t('app', 'Select Category') . ' -- ', 'disabled' => !$model->isNewRecord]);
?>

    <?php 
echo $form->field($model, 'measure')->textInput();
?>

    <?php 
echo $form->field($model, 'ordering')->textInput();
?>

    <?php 
 /**
  * Finds the CatalogAttributes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CatalogAttributes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CatalogAttributes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function getCategoryAttributes()
 {
     return $this->hasMany(CatalogAttributes::className(), array('category_id' => 'id'));
 }
Example #7
0
 public function getCategoryAttribute()
 {
     return $this->hasOne(CatalogAttributes::className(), array('id' => 'attribute_id'));
 }