/**
  * Finds the group model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return group the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Group::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * @param string $url
  * @return string
  */
 public function actionIndex($url)
 {
     $model = Group::findOne(['url' => $url]);
     if (!$model) {
         Alert::add(Yii::t('msg', 'Page not found.'), Alert::TYPE_ERROR);
         return $this->goHome();
     }
     return $this->render('index', ['model' => $model]);
 }
Exemplo n.º 3
0
 public function actionNodeDrop($id)
 {
     $model = Group::findOne($id);
     $model->attributes = Yii::$app->request->get();
     if (Yii::$app->request->get('movetype') == 'inner') {
     }
     if ($model->save()) {
         return $this->ok('转移成功');
     } else {
         return $this->error('转移失败');
     }
 }
Exemplo n.º 4
0
 public function saveGroup()
 {
     $cleanUrl = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $this->name);
     $cleanUrl = strtolower(trim($cleanUrl, '-'));
     $cleanUrl = preg_replace("/[\\/_|+ -]+/", '-', $cleanUrl);
     $this->url = $cleanUrl;
     $urlExists = Group::findOne(['url' => $cleanUrl]);
     if ($urlExists) {
         if ($this->isNewRecord) {
             $lastGroup = Group::find()->orderBy(['id' => SORT_DESC])->one();
             $this->url = $lastGroup->id++ . '-' . $this->url;
         } else {
             if ($urlExists->id !== $this->id) {
                 $this->url = $this->id . '-' . $this->url;
             }
         }
     }
     if (!$this->save()) {
         return false;
     }
     $tags = explode(',', str_replace(['[', ']', '\''], ['', '', ''], $this->tag));
     foreach ($tags as $tag) {
         $newTag = Tag::findOne(['name' => strtolower($tag)]);
         if (!$newTag) {
             $newTag = new Tag();
             $newTag->name = strtolower($tag);
             if ($newTag->save()) {
                 $tagToGroup = new TagToGroup();
                 $tagToGroup->tag_id = $newTag->id;
                 $tagToGroup->group_id = $this->id;
                 $tagToGroup->save();
             }
         } else {
             $tagToGroup = new TagToGroup();
             $tagToGroup->tag_id = $newTag->id;
             $tagToGroup->group_id = $this->id;
             $tagToGroup->save();
         }
     }
     $userToGroup = new UserToGroup();
     $userToGroup->user_id = Yii::$app->user->getIdentity()->id;
     $userToGroup->group_id = $this->id;
     $userToGroup->can_edit = 1;
     $userToGroup->group_admin = 1;
     if ($userToGroup->save()) {
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
 public static function getLessonsList($arr)
 {
     $group = isset($arr['group']) ? $arr['group'] : null;
     $teacher = isset($arr['teacher']) ? $arr['teacher'] : null;
     if ($group !== null) {
         if (!isset($arr['semester'])) {
             $semester = Group::findOne($group)->currentSemester;
         } else {
             $semester = GroupSemesters::find()->where(['group_id' => $arr['group'], 'semester_number' => $arr['semester']])->one();
         }
         if (!$semester) {
             return false;
         }
         $lessons = Lesson::find()->joinWith('groupHasDiscipline', true, "INNER JOIN")->where(['group_has_discipline.group_id' => $group])->andWhere(['group_has_discipline.semester_number' => $semester->semester_number])->orderBy('week ASC, day ASC, time ASC')->all();
         return $lessons;
     } elseif ($teacher !== null) {
         $lessons = Lesson::find()->select('lesson.*')->innerJoin("teacher_has_discipline thd", "`thd`.`id` = `lesson`.`thd_id`")->innerJoin("group_has_discipline ghd", '`ghd`.`id` = `lesson`.`ghd_id`')->innerJoin("group g", '`g`.`id` = `ghd`.`group_id`')->innerJoin("group_semesters gs", '`gs`.`group_id` = `g`.`id` AND `ghd`.`semester_number`  = `gs`.`semester_number`')->where(['<=', 'gs.begin_date', date('U')])->andWhere(['>=', 'gs.end_date', date('U')])->andWhere(['thd.teacher_id' => $teacher])->orderBy('week ASC, day ASC, time ASC, id ASC')->all();
         return $lessons;
     }
 }
Exemplo n.º 6
0
 public function actionTermCreateGroup($group = null, $discipline = null)
 {
     if ($group && $discipline && Yii::$app->user->can('teacher')) {
         if (Yii::$app->user->identity->teacher->isTeacherHasDiscipline($discipline)) {
             $groupModel = Group::findOne($group);
             $disciplineModel = \common\models\GroupHasDiscipline::findOne($discipline);
             $errors = false;
             foreach ($groupModel->students as $student) {
                 $model = new Work();
                 $model->scenario = Work::SCENARIO_TERM;
                 $model->ghd_id = $disciplineModel->discipline_id;
                 $model->student_id = $student->id;
                 $model->teacher_id = Yii::$app->user->identity->teacher->id;
                 $model->work_type_id = Work::TYPE_TERM;
                 if ($model->validate()) {
                     $model->save();
                     $model->id = $model->getPrimaryKey();
                 } else {
                     $errors = true;
                 }
             }
             if (!$errors) {
                 return 'Создано';
             } else {
                 return 'Произошла ошибка';
             }
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 7
0
 public function actionGetAllGroupList($q = null, $id = null)
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if (!is_null($q)) {
         $data = Group::find()->andWhere(['like', 'group_id', $q])->all();
         foreach ($data as $v) {
             $out['results'][] = ['id' => $v->id_group, 'text' => $v->group_id];
         }
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Group::findOne($id)->group_id];
     }
     return $out;
 }