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]); }
public function afterFind() { parent::afterFind(); $this->code_id = preg_split('/[\\[\\],]/i', $this->code_id, -1, PREG_SPLIT_NO_EMPTY); //explode(',', $this->code_id); $this->no_code_id = preg_split('/[\\[\\],]/i', $this->no_code_id, -1, PREG_SPLIT_NO_EMPTY); //explode(',', $this->no_code_id); $this->content = MembersCodesComponent::filterOffMemberCodes($this->content); }