Example #1
0
 public static function getFeaturesCategories($feature_id)
 {
     $categories = self::find()->select("id, name as `text`, parent_id")->indexBy('id')->asArray()->all();
     $features_categories = FeaturesCatergories::find()->where(['feature_id' => $feature_id])->asArray()->all();
     foreach ($features_categories as $feature_category) {
         $cat_id = $feature_category['category_id'];
         $categories[$cat_id]['state'] = ['selected' => true];
     }
     $tree_array = self::buildTree($categories);
     return $tree_array;
 }
Example #2
0
 /**
  * Получение фич по категории. Выбираются только те фичи, у которых есть
  * актуальные значения в существующих объявлениях
  * @param int $category_id
  * @return array
  */
 public static function getByCategoryIdWithValues($category_id)
 {
     $sql = 'SELECT f.id, f.name, f.feature_type ' . ' FROM ' . self::tableName() . ' f ' . ' JOIN ' . FeaturesCatergories::tableName() . ' fc ' . ' ON f.id = fc.feature_id ' . ' WHERE fc.category_id = :category_id';
     $features = self::findBySql($sql, [':category_id' => $category_id])->indexBy('id')->asArray()->all();
     $possible_values = FeaturesValues::getPossibleMarketsValues($category_id, array_keys($features));
     foreach ($possible_values as $value) {
         $features[$value['feature_id']]['values'][] = $value;
     }
     $features_with_values = [];
     foreach ($features as $feature) {
         if (isset($feature['values'])) {
             $features_with_values[] = $feature;
         }
     }
     \yii\helpers\VarDumper::dump($features_with_values, 11, 1);
     return $features_with_values;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFeaturesCatergories()
 {
     return $this->hasMany(FeaturesCatergories::className(), ['feature_id' => 'id']);
 }
Example #4
0
 public function actionDelFeatureCategoryRelation()
 {
     $category_id = Yii::$app->request->post('category_id');
     $feature_id = Yii::$app->request->post('feature_id');
     if (Yii::$app->getRequest()->isAjax && $category_id && $feature_id) {
         return FeaturesCatergories::deleteAll(['category_id' => $category_id, 'feature_id' => $feature_id]);
     }
 }