public function actionNew() { $note = new Note(); $note->title = $_POST['title']; $note->text = $_POST['text']; $note->save(); $this->redirect(['/notes']); }
/** * Creates a new Note model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Note(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Note::find()->where(['user_id' => \Yii::$app->user->id])->orderBy('id DESC')]); $model = new Note(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->refresh(); } return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); }
public function actionCreate() { $note = new Note(); $note->visibility = Note::VIS_PUBLIC_LISTED; if ($note->load(Yii::$app->request->post()) && $note->validate()) { if (Yii::$app->user->isGuest) { $note->save(false); } else { $note->link('user', Yii::$app->user->identity); } return $this->redirect(['view', 'id' => $note->id]); } return $this->render('create', ['note' => $note]); }
public function store(Request $request, Response $response) { $rules = ['name' => 'required', 'text' => 'required', 'pad' => 'required|exists:pads,id']; $validator = app('validation')->make($request->all(), $rules); if ($validator->fails()) { $request->session->add(['errors' => $validator->errors()->all()]); return app('twig')->render('notes/create.htm', ['oldInputs' => $request->all()]); } $note = new Note(); $note->name = $request->input('name'); $note->text = $request->input('text'); $note->user_id = $request->user()->id; $note->pad_id = $request->input('pad'); $note->save(); $request->session->add(['success' => 'Note saved successfuly.']); return $response->redirect("/notes/{$note->id}/update"); }
public function actionCreate() { $note = new Note(); if ($note->load(Yii::$app->request->post()) && $note->save()) { // get 5 latest notes $notes = Note::find()->where(['belong_to' => $this->data_post['belong_to'], 'type_area' => $this->data_post['type_area']])->orderBy('id DESC')->limit(5)->all(); // merge returned data $res_data = array_merge($this->data_post, ['notes' => $notes, 'disViewMore' => false]); return ['errors' => '', 'data' => $this->renderPartial('@widget/views/notes/_list', $res_data)]; } else { // get 5 latest notes $notes = Note::find()->where(['belong_to' => $this->data_post['belong_to'], 'type_area' => $this->data_post['type_area']])->orderBy('id DESC')->limit(5)->all(); // merge returned data $res_data = array_merge($this->data_post, ['notes' => $notes, 'disViewMore' => false]); return ['errors' => $note->getErrors(), 'data' => $this->renderPartial('@widget/views/notes/_list', $res_data)]; } }
/** * Creates a new Note model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Note(); $ajax = Yii::$app->request->isAjax; if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->session->setFlash('success', 'Data berhasil disimpan.'); $model = new Note(); } else { Yii::$app->session->setFlash('error', 'Data gagal disimpan.'); } if ($ajax) { return $this->renderAjax('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } } else { if ($ajax) { return $this->renderAjax('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } } }
/** * Updates Note into database * * @param Note $note * @param array $input * * @return Note */ public function update($note, $input) { $note->fill($input); $note->save(); return $note; }
public function actionAddNote() { Yii::$app->response->format = Response::FORMAT_JSON; if (Yii::$app->request->isGet) { $model = new Note(); $model->user_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->get()) && $model->save()) { Note::updateAll(['status' => 'update'], ['id' => $model->parent_id]); if ($model->parent_id == '') { return ['status' => 1, 'message' => 'done', 'new_id' => $model->id]; } else { return ['status' => 1, 'message' => 'done']; } } else { return ['status' => 0, 'message' => $model->errors]; } } return ['status' => 0, 'message' => 'request error']; }
public function doDistribuer($id, $input) { $return = true; try { $tp = $this->model->findOrFail($id); if (isset($input['distribue'])) { //distribue les classes $classes = $tp->classes()->wherein('classe_id', $input['distribue'])->get(); foreach ($classes as $classe) { //TODO mettre toute la création dans une transaction Note::forClasse($classe->id)->forTP($tp->id)->delete(); //efface les notes déjà distribuées pour ce TP/Classe $etudiants = $classe->etudiants; $questions = $tp->questions()->orderBy('ordre')->get(); foreach ($etudiants as $etudiant) { $i = 1; foreach ($questions as $question) { $note = new Note(); $note->classe_id = $classe->id; $note->tp_id = $tp->id; $note->question_id = $question->id; $note->etudiant_id = $etudiant->id; $note->ordre = $i++; $note->save(); } } //distribue une copie au prof pour qu'il puisse l'essayer $i = 1; foreach ($questions as $question) { $note = new Note(); $note->classe_id = $classe->id; $note->tp_id = $tp->id; $note->question_id = $question->id; $note->etudiant_id = Auth::user()->id; $note->ordre = $i++; $note->save(); } //set le flag pour indiquer que c'est distribué $classe->pivot->distribue = true; $classe->pivot->save(); } } //retire les classes if (isset($input['retire'])) { $classes = $tp->classes()->wherein('classe_id', $input['retire'])->get(); foreach ($classes as $classe) { Note::forClasse($classe->id)->forTP($tp->id)->delete(); //efface les notes déjà distribuées pour ce TP/Classe //reset le flag pour indiquer que c'est pas distribué $classe->pivot->distribue = false; $classe->pivot->save(); } } } catch (Exception $e) { $return = false; } return $return; }
public function store() { $note = new Note(); $note->save(); return $note; }