/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'campaign_id' => $this->campaign_id, 'qType' => $this->qType, 'required' => $this->required, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'question', $this->question]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::find(); if (!isset($params['QuestionSearch']['parent_id']) || is_null($params['QuestionSearch']['parent_id'])) { $query->where(['parent_id' => null]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'voutes' => $this->voutes, 'parent_id' => $this->parent_id, 'is_active' => $this->is_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'position' => $this->position, 'is_multipart' => $this->is_multipart, 'is_float' => $this->is_float, 'mark' => $this->mark]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * 获取调查问题 * @param unknown $survey_id * @return multitype: */ public function FindAllQuestionsOptions($survey_id) { $model_Question = new Question(); $model_QuestionOptions = new QuestionOptions(); $condition['table_id'] = $survey_id; $a_Question = $model_Question->find()->where($condition)->orderBy(['question_id' => SORT_ASC])->all(); $a_QuestionOptions = $model_QuestionOptions->find()->where($condition)->orderBy(['question_id' => SORT_ASC, 'qo_id' => SORT_ASC])->all(); $a_Question ? null : ($a_Question = []); $a_QuestionOptions ? null : ($a_QuestionOptions = []); $a_options = []; $question_total_count = 0; $question_total_score = 0; $question_total_min_score = 0; //没有问题就没有选项 if (!isset($a_Question[0])) { $a_QuestionOptions = []; } else { foreach ($a_Question as $key => &$row) { $question_total_count++; //问题最大分数 $question_max_score = 0; $question_min_score = null; foreach ($a_QuestionOptions as $key2 => &$row2) { if ($row->question_id == $row2->question_id) { $a_options[$key][] = $row2; //获取问题最大得分 $question_max_score = max($row2->option_score, $question_max_score); $question_min_score = $question_min_score == null ? $row2->option_score : min($question_min_score, $row2->option_score); // echo $row2->option_score,'=',$question_total_score,'<br/>'; } } //设置问题总分数 $question_total_score += $question_max_score; $question_total_min_score += $question_min_score; // isset($a_Question[$key]['options'][0])? null :$a_Question[$key]['options']=[]; } } $data['questions'] = $a_Question; $data['options'] = $a_options; $data['question_total_count'] = $question_total_count; $data['question_total_score'] = $question_total_score; $data['question_total_min_score'] = $question_total_min_score; return $data; }
/** * Get question block * @param \common\models\Question|bool|false $question * @param int $id * @return array Data */ public static function getQuestionBlockTitle($question = false, $id = NULL) { if (isset($id)) { $question = Question::find()->where(['id' => $id])->orderBy(['created_at' => SORT_DESC])->one(); } else { if (!$question) { $question = Question::find()->where(['is_active' => 1])->orderBy(['created_at' => SORT_DESC])->one(); } } if (!isset($question)) { $question = Question::find()->where(['parent_id' => null])->orderBy(['created_at' => SORT_DESC])->one(); } $uid = isset(Yii::$app->user->id) ? Yii::$app->user->id : 0; $userVote = QuestionVote::find()->where(['question_id' => $question->id, 'user_id' => $uid])->one(); if (isset($userVote->id) || !$question->is_active) { $block = true; } else { $block = false; } $answers = Question::find()->where(['parent_id' => $question->id])->orderBy(['id' => SORT_ASC])->all(); if (!isset($id)) { if ($block) { $view = $question->is_float ? 'blocks/question_float_block_title' : 'blocks/question_block_title'; } else { $view = $question->is_float ? 'forms/question_float_form' : 'forms/question_form'; } } else { if ($block) { $view = $question->is_float ? 'blocks/question_float_block' : 'blocks/question_block'; } else { $view = $question->is_float ? 'forms/question_float_form' : 'forms/question_form'; } } $block = ['view' => '@frontend/views/' . $view, 'data' => compact('question', 'answers')]; return $block; }
/** * Url: /inquirers * @return mixed */ public function actionInquirers() { $query = Question::find()->where(['parent_id' => null])->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 12]]); return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Все опросы', 'columnFirst' => ['inquirers' => ['view' => '@frontend/views/site/inquirers', 'data' => compact('dataProvider')]], 'columnSecond' => ['short_news' => SiteBlock::getShortNews()]]); }