public function init() { parent::init(); if ($this->latestVideos === null) { $User = OvcUser::getCurrentUser(); $courseIds = OvcCourse::getUserCourseIds($User->id); $this->latestVideos = \app\models\Video::find()->where(['course_id' => $courseIds])->orderBy('id DESC')->limit(16)->all(); } }
/** * Displays a single Video model. * @param integer $id * @param integer $course_id * @return mixed */ public function actionView($id, $course_id) { $video = Video::findOne($id); if (!is_object($video)) { throw new NotFoundHttpException('Video not found.'); } $userCourseIds = OvcCourse::getUserCourseIds(); if (!in_array($video->course_id, $userCourseIds)) { throw new \yii\web\ForbiddenHttpException('Insufficient privileges to access this video.'); } $comments = \app\models\Comment::find()->where(['video_id' => $video->id])->orderBy('id DESC')->all(); return $this->render('view', ['model' => $this->findModel($id, $course_id), 'comments' => $comments]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function studentSearch($params) { $courseIds = \app\components\OvcCourse::getUserCourseIds(); $userIds = \app\components\OvcUser::getUserIdsByCourseIds($courseIds); $query = User::find()->joinWith('role')->where(['user.id' => $userIds, 'user.role_id' => \app\components\OvcRole::STUDENT]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['pageSize']]]); $this->load($params); /** * sortin related columns */ $dataProvider->sort->attributes['roleName'] = ['asc' => ['role.name' => SORT_ASC], 'desc' => ['role.name' => SORT_DESC]]; 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(['user.id' => $this->id, 'user.active' => $this->active, 'user.role_id' => $this->role_id, 'user.created_at' => $this->created_at, 'user.modified_at' => $this->modified_at]); $query->andFilterWhere(['like', 'user.first_name', $this->first_name])->andFilterWhere(['like', 'user.last_name', $this->last_name])->andFilterWhere(['like', 'user.username', $this->username])->andFilterWhere(['like', 'user.password', $this->password])->andFilterWhere(['like', 'user.email', $this->email])->andFilterWhere(['like', 'user.auth_key', $this->auth_key])->andFilterWhere(['like', 'user.access_token', $this->access_token])->andFilterWhere(['like', 'role.name', $this->roleName]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $paramss * * @return ActiveDataProvider */ public function search($params) { $userCourseIds = \app\components\OvcCourse::getUserCourseIds(); $commentCount = "(SELECT COUNT(*) AS nos FROM comment AS c WHERE c.video_id = video.id)"; $query = Video::find()->select("video.*, course.name, {$commentCount} as commentCount")->innerJoin('course', '`video`.`course_id` = `course`.`id`')->where(['video.course_id' => $userCourseIds]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['pageSize']]]); /** * additional columns to be sorted */ $dataProvider->sort->attributes['courseName'] = ['asc' => ['course.name' => SORT_ASC], 'desc' => ['course.name' => SORT_DESC]]; $dataProvider->sort->attributes['commentCount'] = ['asc' => ['commentCount' => SORT_ASC], 'desc' => ['commentCount' => 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(['video.id' => $this->id, 'video.course_id' => $this->course_id, 'video.user_id' => $this->user_id, 'video.created_at' => $this->created_at, 'video.modified_at' => $this->modified_at, $commentCount => $this->commentCount]); $query->andFilterWhere(['like', 'video.title', $this->title])->andFilterWhere(['like', 'video.description', $this->description])->andFilterWhere(['like', 'video.path', $this->path])->andFilterWhere(['like', 'course.name', $this->courseName]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use app\models\Course; use dosamigos\tinymce\TinyMce; /* @var $this yii\web\View */ /* @var $model app\models\Video */ /* @var $form yii\widgets\ActiveForm */ /** * user course id; */ $courseIds = \app\components\OvcCourse::getUserCourseIds(); ?> <div class="video-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'course_id')->dropdownList(Course::find()->select(['name', 'id'])->where(['id' => $courseIds])->indexBy('id')->column(), ['prompt' => 'Select Course']); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->widget(TinyMce::className(), ['options' => ['rows' => 6], 'clientOptions' => ['menubar' => 'false']]); ?>
/** * get unassigned course */ public function actionGetUnassignedCourse() { $userId = Yii::$app->request->post('user_id'); $userCourseIds = \app\components\OvcCourse::getUserCourseIds($userId); $items = \app\models\Course::find()->select(['CONCAT(code," ( ", name," )") as name', 'id'])->where(['not in', 'id', $userCourseIds])->indexBy('id')->column(); $items = array_merge(['' => 'Select Course'], $items); echo \yii\helpers\Html::dropDownList('UserHasCourse[course_id]', null, $items, ['id' => 'userhascourse-course_id', 'class' => 'form-control']); }
public function actionIndex() { $courseIds = \app\components\OvcCourse::getUserCourseIds(); $msg = \app\components\OvcUser::getUserIdsByCourseIds($courseIds); return $this->render('index', ['msg' => $msg]); }
/** * my courses * @param type $userid * @return type */ public function actionMyCourses() { $myCourses = \app\components\OvcCourse::getUserCourses(); return $this->render('my_courses', ['myCourses' => $myCourses]); }