예제 #1
0
 public function actionRequestAccess($data)
 {
     if (Yii::$app->request->isAjax && !Yii::$app->user->isGuest) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $object = json_decode($data);
         if (AuthAssignment::getAssignment(Yii::$app->user->identity->id) === 'parent') {
             $request = new RequestDataAccess();
             if (!RequestDataAccess::find()->where(['user_id' => Yii::$app->user->identity->id])->andWhere(['student_id' => $object->sid])->exists()) {
                 $request->request_text = $object->sid;
                 $request->user_id = Yii::$app->user->identity->id;
                 $request->save();
                 $data = array('sent' => true, 'saved' => true);
             } else {
                 $data = array('sent' => true, 'saved' => false);
             }
             return $data;
         }
     }
 }
 /**
  * Displays a single StudentForm model.
  * @param string $id
  * @return mixed
  */
 public function actionView($id)
 {
     if (!Yii::$app->user->isGuest && \app\rbac\models\AuthAssignment::getAssignment(Yii::$app->user->identity->id) === 'parent') {
         $request = RequestDataAccess::find()->where(['user_id' => Yii::$app->user->identity->id])->andWhere(['request_status' => 2])->one();
         if (!empty($request)) {
             return $this->render('view', ['model' => $this->findModel($id)]);
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     } else {
         return $this->render('view', ['model' => $this->findModel($id)]);
     }
 }