Example #1
0
 public function actionIndex()
 {
     $request = Yii::$app->request;
     try {
         $query = $request->get('search-string', '');
         $query = HtmlPurifier::process($query);
         Yii::$app->view->title = 'Kết quả tìm kiếm cho ' . $query;
         Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Bluebee-UET.com - Kết quả tìm kiếm cho ' . $query]);
         Yii::$app->view->registerMetaTag(['property' => 'og:title', 'content' => 'Bluebee-UET.com - Kết quả tìm kiếm cho ' . $query]);
         Yii::$app->view->registerMetaTag(['property' => 'og:description', 'content' => 'Bluebee-UET.com - Kết quả tìm kiếm cho ' . $query]);
         Yii::$app->view->registerMetaTag(['property' => 'og:image', 'content' => 'http://bluebee-uet.com/img/logo.jpg']);
         $attr = $request->get('attr', '');
         switch ($attr) {
             case 'teacher':
                 $data = Teachers::searchTeachers(strtolower($query));
                 break;
             case 'document':
                 $data = Documents::searchDocuments(strtolower($query));
                 break;
             case 'subject':
                 $data = Subjects::searchSubjects(strtolower($query));
                 break;
             default:
                 $this->redirect('http://bluebee-uet.com');
                 break;
         }
         $data['attr'] = $attr;
         $data['query'] = $query;
         return $this->render('index', $data);
     } catch (Exception $ex) {
     }
 }
Example #2
0
 public static function getAllSubject()
 {
     $query = Subjects::find()->orderBy('id desc');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->defaultPageSize = 27;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['models' => $models, 'pages' => $pages];
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Subjects::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['SubjectId' => $this->SubjectId, 'CourseCode' => $this->CourseCode, 'CourseTitle' => $this->CourseTitle, 'Units' => $this->Units]);
     return $dataProvider;
 }
Example #4
0
 public static function getProgramByAttribute($args)
 {
     $programs = Program::find()->where($args)->all();
     $retVal = array();
     foreach ($programs as $program) {
         $itemArr = array();
         $itemArr['subject'] = Subjects::findOne(['id' => $program->subject])->name;
         $itemArr['semester'] = $program->semester;
         $itemArr['subject_id'] = $program->subject;
         $retVal[] = $itemArr;
     }
     return $retVal;
 }
Example #5
0
 public function actionDelete()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $request = \Yii::$app->request;
     $data = $request->post();
     $id = $data['id'];
     try {
         Subjects::findOne(['id' => $id])->delete();
         return ['status' => 1, 'message' => 'Thành công'];
     } catch (Exception $ex) {
         return ['status' => 0, 'message' => 'Có lỗi xảy ra'];
     }
 }
Example #6
0
 public function actionGetTeachersBySubject()
 {
     $request = Yii::$app->request;
     try {
         $subject = HtmlPurifier::process($request->get('id', ''));
         $teachers = Teachers::getTeachersBySubject($subject);
         $subject_name = Subjects::findOne(['id' => $subject])->name;
         Yii::$app->view->title = 'Giảng viên môn ' . $subject_name;
         Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Bluebee-UET.com - Giảng viên môn ' . $subject_name]);
         Yii::$app->view->registerMetaTag(['property' => 'og:title', 'content' => 'Bluebee-UET.com - Giảng viên môn ' . $subject_name]);
         Yii::$app->view->registerMetaTag(['property' => 'og:description', 'content' => 'Bluebee-UET.com - Giảng viên môn ' . $subject_name]);
         Yii::$app->view->registerMetaTag(['property' => 'og:image', 'content' => 'http://bluebee-uet.com/img/logo.jpg']);
         return $this->render('teachers', $teachers);
     } catch (Exception $ex) {
     }
 }
Example #7
0
 /**
  * Finds the Posts model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Posts the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subjects::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #8
0
                <tr>
                    <td><input type="checkbox" > </td>
                    <td><?php 
    echo $model->id;
    ?>
</td>
                    <td><?php 
    echo Deparment::findOne(['id' => $model->department_id])->name;
    ?>
</td>
                    <td><?php 
    echo $model->semester;
    ?>
</td>
                    <td><?php 
    echo Subjects::findOne(['id' => $model->subject])->name;
    ?>
</td>


                    <td>
                        <a class="btn btn-default">Edit</a>
                        <a class="btn btn-danger">Delete</a>
                    </td>
                </tr>
            <?php 
}
?>

        </tbody>
    </table>
Example #9
0
 public static function getDocumentsByWishlist($user)
 {
     $query = Documents::find()->join('JOIN', 'wishlist', '`wishlist`.`doc_id`=`documents`.`id`')->where(['wishlist.user_id' => $user])->orderBy('wishlist.created_at desc');
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->defaultPageSize = 27;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     if (!Yii::$app->cache->exists('subjects')) {
         $subjects = Subjects::find()->orderBy('name', 'desc')->all();
         Yii::$app->cache->add('subjects', $subjects, 3600);
     } else {
         $subjects = Yii::$app->cache->get('subjects');
     }
     return ['models' => $models, 'pages' => $pages, 'subjects' => $subjects];
 }
 public function postDeleteSubject(Request $request)
 {
     $subject_id = $request->input('subject_id');
     $input = ['subject_id' => $subject_id];
     $validator = validator::make($request->all(), ['subject_id' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         try {
             $subject = Subjects::findOrFail($subject_id);
             if (!$subject->delete()) {
                 throw new ErrorException();
             }
         } catch (ModelNotFoundException $e) {
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         } catch (ErrorException $e) {
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         }
         return ApiResponseClass::successResponse($subject, $input);
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
 }
Example #11
0
 public static function getSubjects()
 {
     if (!Yii::$app->cache->exists('subjects')) {
         $subjects = Subjects::find()->orderBy('name', 'desc')->all();
         Yii::$app->cache->add('subjects', $subjects, 3600);
     } else {
         $subjects = Yii::$app->cache->get('subjects');
     }
     return $subjects;
 }