Exemplo n.º 1
0
 /**
  * Finds the Note model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Note the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Note::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Get note or raise 404
  *
  * @param integer $id note id
  * @return Note
  * @throws \yii\web\HttpException
  */
 private function getNote($id)
 {
     $note = Note::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->getId()]);
     if (!$note) {
         throw new \yii\web\HttpException(404, 'Not Found');
     }
     return $note;
 }
Exemplo n.º 3
0
 public function actionEdit()
 {
     if (\Yii::$app->request->getIsPost()) {
         $id = $_POST['id'];
         $note = Note::findOne($id);
         $note->title = $_POST['title'];
         $note->text = $_POST['text'];
         $note->save();
         $this->redirect(['/notes']);
     } else {
         $id = $_GET['id'];
         $note = Note::findOne($id);
         return $this->render('edit', ['note' => $note]);
     }
 }
Exemplo n.º 4
0
 /**
  * Creates a new Access model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param $id
  * @return string|\yii\web\Response
  * @throws ForbiddenHttpException
  */
 public function actionCreate($id)
 {
     $note = Note::findOne($id);
     if ($note->creator == Yii::$app->user->id) {
         $model = new Access();
         $model->load(Yii::$app->request->post());
         $model->note_id = $id;
         if ($model->validate() && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
     throw new ForbiddenHttpException("Not allowed share notes other people!");
 }
Exemplo n.º 5
0
 /**
  * Creates a new Access model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param $id
  * @return string|\yii\web\Response
  * @throws BadRequestHttpException
  * @throws ForbiddenHttpException
  */
 public function actionCreate($id)
 {
     $note = Note::findOne($id);
     if (!$note) {
         throw new BadRequestHttpException("Not exists note!");
     }
     if ($note->creator == Yii::$app->user->id) {
         $model = new Access();
         $usersForAutocomplete = User::find()->selectForAutocomplite()->notCurrent()->asArray()->all();
         $model->load(Yii::$app->request->post());
         $model->note_id = $id;
         if ($model->validate() && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model, 'usersForAutocomplete' => $usersForAutocomplete]);
         }
     }
     throw new ForbiddenHttpException("Not allowed share notes other people!");
 }
Exemplo n.º 6
0
 public function actionDeleteNote()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->request->isGet) {
         $id = Yii::$app->request->get('Note')['id'];
         if ($id) {
             $model = Note::findOne(['id' => $id]);
             /** @var Note $model */
             if ($model) {
                 if ($model->delete()) {
                     return ['status' => 1, 'message' => 'message deleted successfully'];
                 } else {
                     return ['status' => 0, 'message' => 'errors : ' . print_r($model->getErrors())];
                 }
             } else {
                 return ['status' => 0, 'message' => 'note not found'];
             }
         } else {
             return ['status' => 0, 'message' => 'wrong request!'];
         }
     }
     return ['status' => 0, 'message' => 'request error'];
 }
Exemplo n.º 7
0
 private function findNote($id)
 {
     if ($note = Note::findOne($id)) {
         return $note;
     } else {
         throw new NotFoundHttpException('Заметка не найдена');
     }
 }