public function run()
 {
     $params = array();
     $criteria = new CDbCriteria();
     //        $criteria->select = array('id,username,fullname,phone,address,status');
     $criteria->select = '*';
     if (isset($this->course_id) and $this->course_id != '') {
         $criteria->addCondition('course_id=' . $this->course_id);
     }
     $criteria->addCondition('status=1');
     $criteria->params = $params;
     $total = WCourseTrainee::model()->count($criteria);
     $offset = $this->limit * ($this->page - 1);
     $criteria->limit = $this->limit;
     $criteria->offset = $offset;
     $data = WCourseTrainee::model()->findAll($criteria);
     $listTrainee = array();
     if (!empty($data)) {
         foreach ($data as $item) {
             $listTrainee[] = CJSON::decode(CJSON::encode($item->pls_user));
         }
     }
     $data = $listTrainee;
     $pages = new CPagination($total);
     $pages->pageSize = $this->limit;
     $pages->applyLimit($criteria);
     $this->render($this->view, array('data' => $data, 'pages' => $pages));
 }
 public function actionIndex111()
 {
     // đây là action ra listcourse
     $countCourse = WCourseTrainee::model()->findAll();
     //var_dump(COUNT($countCourse));die;
     $total_pages = ceil(count($countCourse) / Params::$coursePerPage);
     $this->render('index111', array('total_pages' => $total_pages));
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionTraineeViewCourse($id)
 {
     if (empty(Yii::app()->user->id)) {
         $this->redirect(Yii::app()->createUrl(''));
     }
     $dataCourseLecture = array();
     $listTrainee = array();
     $db = Yii::app()->db;
     if (!empty($id)) {
         $data = WCourseLecture::model()->findAll('course_id=' . $id . ' ORDER BY start_date ASC');
         $data = CJSON::decode(CJSON::encode($data));
         $course_data = WCourse::getDetailCourse($id);
         if (!empty($data)) {
             foreach ($data as $key => $item) {
                 if (!empty($item["lecture_id"])) {
                     $lectureDetails = WLecture::model()->find('id=' . $item['lecture_id']);
                     if (!empty($lectureDetails)) {
                         $category = $lectureDetails->category;
                         $lectureDetails = CJSON::decode(CJSON::encode($lectureDetails));
                         $dataCourseLecture[$item['id']] = $item;
                         $dataCourseLecture[$item['id']]['details'] = $lectureDetails;
                         $dataCourseLecture[$item['id']]['cat_name'] = $category->cat_name;
                         $dataCourseLecture[$item['id']]['PreTest'] = FALSE;
                         if (strtotime($course_data["end_date"]) < strtotime($item["end_date"])) {
                             $dataCourseLecture[$item['id']]['end_date'] = $course_data["end_date"];
                         }
                         if (!empty($item['pre_test_id'])) {
                             $comm = $db->createCommand()->select('t.*')->from('pls_user_test t')->where('course_id=' . $item['course_id'] . ' AND success = 2 AND lecture_id=' . $item['lecture_id'] . ' AND test_id=' . $item['pre_test_id'] . ' AND user_id=' . Yii::app()->user->id);
                             $preTest = $comm->queryRow();
                             $comm->reset();
                             if (!empty($preTest)) {
                                 $dataCourseLecture[$item['id']]['PreTest'] = TRUE;
                             }
                         }
                         $dataCourseLecture[$item['id']]['Test'] = FALSE;
                         if (!empty($item['test_id'])) {
                             $comm = $db->createCommand()->select('t.*')->from('pls_user_test t')->where('course_id=' . $item['course_id'] . ' AND success=2 AND lecture_id=' . $item['lecture_id'] . ' AND test_id=' . $item['test_id'] . ' AND user_id=' . Yii::app()->user->id);
                             $Test = $comm->queryRow();
                             $comm->reset();
                             if (!empty($Test)) {
                                 $dataCourseLecture[$item['id']]['Test'] = TRUE;
                             }
                         }
                     }
                 }
                 // Info Pre-Test
             }
         }
         $dataTrainee = WCourseTrainee::model()->findAll('course_id=' . $id);
         $dataTrainee = CJSON::decode(CJSON::encode($dataTrainee));
         if (!empty($dataTrainee)) {
             foreach ($dataTrainee as $item) {
                 $traineeDetails = WUser::model()->find('id=' . $item['trainee_id']);
                 if (!empty($traineeDetails)) {
                     $traineeDetails = CJSON::decode(CJSON::encode($traineeDetails));
                     $listTrainee[$traineeDetails['id']]['id'] = $traineeDetails['id'];
                     $listTrainee[$traineeDetails['id']]['course_id'] = $id;
                     $listTrainee[$traineeDetails['id']]['fullname'] = $traineeDetails['fullname'];
                     $listTrainee[$traineeDetails['id']]['username'] = $traineeDetails['username'];
                 }
             }
         }
     }
     $this->render('trainee/view', array('model' => $this->loadModel($id), 'dataCourseLecture' => $dataCourseLecture, 'listTrainee' => $listTrainee));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return WCourseTrainee the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = WCourseTrainee::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #5
0
 public static function listTest($course_id)
 {
     $criteria = new CDbCriteria();
     $criteria->alias = 'ct';
     $criteria->select = 'ct.*';
     $criteria->condition = 'ct.course_id=:course_id';
     $criteria->params = array(':course_id' => $course_id);
     $criteria->order = '';
     $rs = WCourseTrainee::model()->findAll($criteria);
     if ($rs) {
         return $rs;
     } else {
     }
 }
Пример #6
0
 public static function getInfoCourseLectureComment($idcomment, $dataId, $dataType)
 {
     $db = Yii::app()->db;
     $dataNew = array();
     $group_id = Yii::app()->session["group_id"];
     if ($dataType == "course") {
         $comm = $db->createCommand()->select('t.*')->from('pls_course t')->where("t.id IS NOT NULL AND t.id=" . $dataId);
         $data = $comm->queryRow();
         if (!empty($data)) {
             $dataNew[$idcomment]["name"] = 'Course: ' . $data["course_name"];
             $url = Yii::app()->createUrl("wCourse/view", array("id" => $data["id"]));
             switch ($group_id) {
                 case 1:
                     $url = Yii::app()->createUrl("wCourse/view", array("id" => $data["id"], "row" => "comment_row_" . $idcomment));
                     break;
                 case 2:
                     $url = Yii::app()->createUrl("wCourse/TraineeViewCourse", array("id" => $data["id"], "row" => "comment_row_" . $idcomment));
                     break;
                 case 3:
                     $url = Yii::app()->createUrl("wCourse/view", array("id" => $data["id"], "row" => "comment_row_" . $idcomment));
                     break;
             }
             $dataNew[$idcomment]["url"] = $url;
         }
     } elseif ($dataType == "courselecture") {
         $comm = $db->createCommand()->select('t.*')->from('pls_lecture t')->where("t.id IS NOT NULL AND t.id=" . $dataId);
         $data = $comm->queryRow();
         if (!empty($data)) {
             $url = NULL;
             switch ($group_id) {
                 case 1:
                 case 3:
                     $url = Yii::app()->createUrl("wLecture/View", array("id" => $data["id"], "row" => "comment_row_" . $idcomment));
                     break;
                 case 2:
                     $datacourselecture = WCourseLecture::model()->findAll("lecture_id=" . $dataId);
                     $course_lecture_id = NULL;
                     if (!empty($datacourselecture)) {
                         foreach ($datacourselecture as $itemcourelecture) {
                             $modelCourseTrainee = WCourseTrainee::model()->find("course_id=" . $itemcourelecture->course_id . ' AND trainee_id=' . Yii::app()->user->id);
                             if (!empty($modelCourseTrainee)) {
                                 $course_lecture_id = $itemcourelecture->id;
                             }
                         }
                     }
                     if (!empty($course_lecture_id)) {
                         $url = Yii::app()->createUrl("wLecture/LectureView", array("course_lecture_id" => $course_lecture_id, "row" => "comment_row_" . $idcomment));
                     } else {
                         $url = "javascript:;";
                     }
                     break;
                     /*case 3:
                       $url = Yii::app()->createUrl("wSuperLecture/LectureView",array("course_lecture_id" => $data["id"]));;
                       break;*/
             }
             $dataNew[$idcomment]["name"] = 'Lecture: ' . $data["lecture_name"];
             $dataNew[$idcomment]["url"] = $url;
         }
     }
     return $dataNew;
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionViewCourse($id)
 {
     if (empty(Yii::app()->user->id)) {
         $this->redirect(Yii::app()->createUrl(''));
     }
     $dataCourseLecture = array();
     $listTrainee = array();
     if (!empty($id)) {
         $data = WCourseLecture::model()->findAll('course_id=' . $id);
         $data = CJSON::decode(CJSON::encode($data));
         if (!empty($data)) {
             foreach ($data as $key => $item) {
                 $lectureDetails = WLecture::model()->find('id=' . $item['lecture_id']);
                 if (!empty($lectureDetails)) {
                     $category = $lectureDetails->category;
                     $lectureDetails = CJSON::decode(CJSON::encode($lectureDetails));
                     $dataCourseLecture[$item['id']] = $item;
                     $dataCourseLecture[$item['id']]['details'] = $lectureDetails;
                     $dataCourseLecture[$item['id']]['cat_name'] = $category->cat_name;
                 }
             }
         }
         $dataTrainee = WCourseTrainee::model()->findAll('course_id=' . $id);
         $dataTrainee = CJSON::decode(CJSON::encode($dataTrainee));
         if (!empty($dataTrainee)) {
             foreach ($dataTrainee as $item) {
                 $traineeDetails = WUser::model()->find('id=' . $item['trainee_id']);
                 if (!empty($traineeDetails)) {
                     $traineeDetails = CJSON::decode(CJSON::encode($traineeDetails));
                     $listTrainee[$traineeDetails['id']]['id'] = $traineeDetails['id'];
                     $listTrainee[$traineeDetails['id']]['course_id'] = $id;
                     $listTrainee[$traineeDetails['id']]['fullname'] = $traineeDetails['fullname'];
                     $listTrainee[$traineeDetails['id']]['username'] = $traineeDetails['username'];
                 }
             }
         }
     }
     $this->render('supervisor/view', array('model' => $this->loadModel($id), 'dataCourseLecture' => $dataCourseLecture, 'listTrainee' => $listTrainee));
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     WCourseTrainee::model()->deleteAll(array('trainee_id' => $id));
     WCourseLecture::model()->deleteAll(array('trainee_id' => $id));
     WUserTest::model()->deleteAll(array('user_id' => $id));
     $this->loadModel($id)->delete();
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
     }
 }
Пример #9
0
 public function actionRegisterCourse()
 {
     $trainee_id = $_POST['trainee_id'];
     $course_id = $_POST['course_id'];
     $model = WCourseTrainee::model()->find('trainee_id = ' . $trainee_id . ' AND course_id=' . $course_id);
     if (empty($model)) {
         $model = new WCourseTrainee();
         $model->trainee_id = $trainee_id;
         $model->course_id = $course_id;
         $model->register_date = date('Y-m-d H:i');
         $model->status = 0;
         if ($model->save()) {
             echo json_encode(array('status' => 'true', 'mess' => 'You have successfully registered. Waiting for activation'));
         } else {
             echo json_encode(array('status' => 'false', 'mess' => ''));
         }
     } else {
         echo json_encode(array('status' => 'exists', 'mess' => 'Waiting... for activation'));
     }
 }