/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Resource::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]); $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, 'type' => $this->type, 'class' => $this->class, 'course' => $this->course, 'status' => $this->status, 'views' => $this->views, 'downtime' => $this->downtime, 'star' => $this->star, 'pinglunnum' => $this->pinglunnum, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
public function actionIndex() { $type = Yii::$app->request->get('type'); $class = Yii::$app->request->get('class'); $course = Yii::$app->request->get('course'); $key = Yii::$app->request->get('key'); $sort = Yii::$app->request->get('sort'); //条件 $where[] = 'and'; $where[] = 'status>' . Status::STATUS_INACTIVE; if (!is_null($class)) { $where[] = ['class' => $class]; } if (!is_null($course)) { $where[] = ['course' => $course]; } if (!is_null($key)) { $where[] = ['like', 'title', $key]; } //排序 $sort = ['created_at' => SORT_DESC]; if ($sort == 'star') { $sort = ['star' => SORT_DESC]; } //课程类型 if ($type == 0) { $query = Video::find()->where($where); //查询4条推荐信息 $where[1] = 'status=' . Status::STATUS_REC; $infoRec = Video::find()->where($where)->limit(4)->all(); } else { $where[] = ['type' => $type]; $query = Resource::find()->where($where); //查询4条推荐信息 $where[1] = 'status=' . Status::STATUS_REC; $infoRec = Resource::find()->where($where)->limit(4)->all(); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => $sort], 'pagination' => ['pageSize' => 15]]); return $this->render('index', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'type' => $type, 'class' => $class, 'course' => $course, 'key' => $key, 'infoRec' => $infoRec]); }
public function actionIndex() { //轮播图 $slider = Slider::find()->where(['place' => 0])->orderBy(['ord' => SORT_ASC])->all(); //微课 $weike = \common\models\Video::find()->where(['and', ['status' => \common\models\Status::STATUS_REC]])->limit(6)->all(); //教案 $jiaoan = \common\models\Resource::find()->where(['and', ['type' => 0], ['status' => \common\models\Status::STATUS_REC]])->limit(3)->all(); //课件 $kejian = \common\models\Resource::find()->where(['and', ['type' => 1], ['status' => \common\models\Status::STATUS_REC]])->limit(3)->all(); //试题 $shiti = \common\models\Resource::find()->where(['and', ['type' => 2], ['status' => \common\models\Status::STATUS_REC]])->limit(3)->all(); //新闻公告 $news = \common\models\News::find()->where(['and', 'status>' . \common\models\Status::STATUS_INACTIVE])->orderBy(['id' => SORT_DESC])->limit(3)->all(); //推荐下载 $recdown = \common\models\Resource::find()->where(['and', ['status' => \common\models\Status::STATUS_REC]])->orderBy(['id' => SORT_DESC])->limit(4)->all(); //最新评价 $pinglun = \common\models\Pinglun::find()->where(['and', 'status>' . \common\models\Status::STATUS_INACTIVE])->orderBy(['id' => SORT_DESC])->limit(6)->all(); //学霸必备 $xueba = \common\models\Resource::find()->where(['and', 'status>' . \common\models\Status::STATUS_REC])->orderBy(['rand()' => SORT_DESC])->limit(10)->all(); //友情链接 $friendLink = \common\models\Friendlink::find()->where(['isshow' => \common\models\YesNo::YES])->orderBy(['ord' => SORT_ASC])->all(); return $this->render('index', ['slider' => $slider, 'weike' => $weike, 'jiaoan' => $jiaoan, 'kejian' => $kejian, 'shiti' => $shiti, 'news' => $news, 'recdown' => $recdown, 'pinglun' => $pinglun, 'xueba' => $xueba, 'friendlink' => $friendLink]); }
public function getResource($type, $rid) { return Resource::find()->where(['and', ['id' => $rid], ['type' => $type]])->one(); }
/** * @return \yii\db\ActiveQuery */ public function getResources() { return $this->hasMany(Resource::className(), ['collection_id' => 'id']); }
private function _initScreeningForm($subject_model) { $questions = \yii::$app->screeningquestion->getQuestions($this->getScreeningSession('screening_form_id')); $resource_model = Resource::findOne(['id' => $this->getScreeningSession('resource_id')]); $screening_form_model = ScreeningForm::findOne(['id' => $this->getScreeningSession('screening_form_id')]); $screening_entry_model = new \common\models\ScreeningEntry(); $screening_entry_model->screening_form_id = $this->getScreeningSession('screening_form_id'); $screening_entry_model->project_id = $this->getScreeningSession('project_id'); $screening_entry_model->subject_id = $subject_model->id; $screening_entry_model->researcher_id = \Yii::$app->user->identity->id; $screening_entry_model->screening_form_title = $screening_form_model->title; $screening_entry_model->resource_id = $this->getScreeningSession('resource_id'); $screening_entry_model->resource_title = $resource_model->title; if ($screening_entry_model->save() == false) { throw new \yii\web\HttpException(500, yii::t('app', 'An error occured.')); } $this->setScreeningSession('screening_hash', $screening_entry_model->hash); foreach ($questions as $q) { $model = new \common\models\ScreeningResponse(); $model->screening_question_id = $q['screening_question_id']; $model->screening_entry_id = $screening_entry_model->id; $model->subject_id = $subject_model->id; $model->save(); } return true; }
/** * @return \yii\db\ActiveQuery */ public function getResource() { return $this->hasOne(Resource::className(), ['id' => 'resource_id']); }
echo $v->intro; ?> </div> </div> </li> <?php } ?> </ul> </div> <div class="tuijian-down margin-bottom25"> <div class="tuijian-down-tit">推荐下载</div> <div class="tuijian-down-img"><img src="/statics/images/img_78.jpg" width="259" height="116" alt=""/></div> <ul class="tuijian-down-nr"> <?php $recdown = \common\models\Resource::find()->where(['and', ['status' => \common\models\Status::STATUS_REC]])->orderBy(['id' => SORT_DESC])->limit(6)->all(); foreach ($recdown as $k => $v) { ?> <li><a href="<?php echo Yii::$app->urlManager->createUrl(['resource/show', 'u' => $v->url]); ?> "><?php echo $v->title; ?> </a></li> <?php } ?> </ul> </div>
/** * Finds the Resource model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Resource the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Resource::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('您访问的页面不存在'); } }