public function run() { // Get list category of module question $model = \app\modules\category\models\Category::getCategory('question', '- '); // Get question quan tam nhieu nhat $concernedQuestion = Question::find()->where(['status' => 1])->andWhere(['stats.comment_count' => ['$gt' => 0]])->orderBy(['stats.comment_count' => -1])->limit(5)->all(); return $this->render('sidebar', ['model' => $model, 'concernedQuestion' => $concernedQuestion]); }
public function actionDoctor($id) { $query = Question::find(); $query->orderBy('_id ASC'); $query->where(['category' => $id, 'need_answer' => 1]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); return $this->render('doctor', ['model' => $dataProvider]); }
/** * 通过ID获取指定问题 */ protected function findQuestion($id, \Closure $callback = null) { $query = Question::find(); $callback !== null && $callback($query); if (($model = $query->andWhere(['id' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'pid' => $this->pid, 'author_id' => $this->author_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'favorite_count' => $this->favorite_count, 'like_count' => $this->like_count, 'hate_count' => $this->hate_count, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
public function run() { switch ($this->type) { case '': $questions = Question::find()->where(['category' => $this->cat_id])->limit(10)->orderBy('rand()')->all(); break; case 'comment': $questions = Question::find()->where(['count_comment' => ['$gt' => 0]])->limit(10)->orderBy('rand()')->all(); break; case 'cat': $questions = Category::find()->where(['lft' => ['$gt' => 1], 'module' => 'question'])->limit(4)->orderBy('rand()')->all(); default: break; } $assign = ['questions' => $questions, 'name' => $this->name]; return $this->render($this->view, $assign); }