Beispiel #1
0
 public function actionCategory($id)
 {
     /**
      * Define default member group code
      */
     //get code id with max sum value
     $memberGroupCode = MembersCodesComponent::getMemberGroupCode();
     $memberAnswersCodes = MembersCodesComponent::getMemberCodesSqlFilter();
     $recipesQuery = CmsRecipes::find()->where(['is_active' => 1]);
     //add default group to exclude codes array
     if (!empty($memberGroupCode)) {
         $memberAnswersCodes['exclude'][] = ['not like', 'no_code_id', "[{$memberGroupCode}]"];
     }
     //add conditions to the where instance if exclude codes array not empty
     if (count($memberAnswersCodes['exclude']) > 0) {
         $recipesQuery->andWhere(array_merge(['and'], $memberAnswersCodes['exclude']))->orWhere(['no_code_id' => NULL]);
     }
     //add default group to include codes array
     if (!empty($memberGroupCode)) {
         $memberAnswersCodes['include'][] = ['like', 'code_id', "[{$memberGroupCode}]"];
     }
     //add conditions to the where instance if include codes array not empty
     if (count($memberAnswersCodes['include']) > 0) {
         $recipesQuery->andWhere(array_merge(['or'], $memberAnswersCodes['include']))->orWhere(['code_id' => '']);
     }
     $recipesQuery->andWhere(['like', 'category_id', "[{$id}]"]);
     $dataProvider = new ActiveDataProvider(['query' => $recipesQuery, 'sort' => ['defaultOrder' => ['sort_order' => SORT_ASC]]]);
     $category = CmsRecipesCategories::find($id)->one();
     return $this->render('index', ['dataProvider' => $dataProvider, 'category' => $category]);
 }