예제 #1
0
 /**
  * @taken tasks
  */
 public function actionTaken()
 {
     $searchModel = new GivenTaskSearch();
     $query = GivenTask::find()->where(['student_id' => Yii::$app->user->identity->student->id])->orderBy('status');
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
     return $this->render('taken_tasks_list', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
 }
예제 #2
0
 /**
  * @taken tasks
  */
 public function actionTaken($id = NULL)
 {
     if (Yii::$app->request->isAjax) {
         $takenTask = GivenTask::find($id)->one();
         if (isset(Yii::$app->request->post()['close'])) {
             return $this->render('taken_task', ['takenTask' => $takenTask, 'openform' => false]);
         } elseif (isset(Yii::$app->request->post()['submit'])) {
             $cEx = new \common\models\CompleteExercise();
             $cEx->text = Yii::$app->request->post()['textarea'];
             $cEx->save();
             return $this->render('taken_task', ['takenTask' => $takenTask, 'complete' => true]);
         } else {
             return $this->render('taken_task', ['takenTask' => $takenTask, 'openform' => true]);
         }
     }
     if ($id == NULL || !GivenTask::findOne($id)) {
         $searchModel = new GivenTaskSearch();
         $query = GivenTask::find()->where(['student_id' => Yii::$app->user->identity->student->id]);
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $query);
         return $this->render('taken_tasks_list', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
     } else {
         $takenTask = GivenTask::findOne($id);
         if ($takenTask->student_id != Yii::$app->user->identity->student->id) {
             throw new ForbiddenHttpException('У вас нет доступа к этому заданию.');
         }
         return $this->render('taken_task', ['takenTask' => $takenTask]);
     }
 }