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 __construct(Currency $currencyModel, Note $noteModel) { $notes = $noteModel->getLastNote(); if (count($notes) < 1) { $notes = false; } //GLOBAL SETTINGS $this->_glob = array('_note' => $notes, '_curr' => $currencyModel->getRate(), '_baseCurrency' => 'RUB', '_precision' => 2, '_countProductsOfPage' => Auth::User() ? Auth::User()->count_products : 100, '_maxCountProductsOfPage' => 500, '_alerts' => AbsentController::shortView()); View::share('_glob', $this->_glob); }
public function actionCreate() { $note = new Note(); # to make value in dropdown selected, strange yii2 behavior $note->pad_id = Yii::$app->request->get('pad'); if ($note->load(Yii::$app->request->post()) && $note->validate()) { Yii::$app->user->identity->link('notes', $note); Yii::$app->session->setFlash('success', 'Note is successfully created.'); return $this->redirect('note/list'); } return $this->render('create', ['note' => $note]); }
public function search($params, $whereParams = null) { $query = Note::find()->joinWith(User::tableName()); $isAdminPanel = $this->getScenario() === 'admin'; if ($whereParams) { $query->where($whereParams); } if ($this->load($params) && $this->validate()) { $query->andFilterWhere(['like', 'note.name', $this->name])->andFilterWhere(['like', 'user.name', $this['user.name']]); if ($isAdminPanel) { $query->andFilterWhere(['note.id' => $this->id])->andFilterWhere(['visibility' => $this->visibility]); if (preg_match('/[\\d]{2}-[\\d]{2}-[\\d]{4}/', $this->created_at)) { $query->andFilterWhere(['AND', ['>', 'note.created_at', \DateTime::createFromFormat('d-m-Y H:i:s', $this->created_at . ' 00:00:00')->getTimestamp()], ['<', 'note.created_at', \DateTime::createFromFormat('d-m-Y H:i:s', $this->created_at . ' 23:59:59')->getTimestamp()]]); } } else { $query->andFilterWhere(['like', 'description', $this->description]); } } $noteSortAttributes = ['name' => ['asc' => ['note.name' => SORT_ASC], 'desc' => ['note.name' => SORT_DESC], 'label' => $this->getAttributeLabel('name')], 'created_at' => ['default' => SORT_DESC, 'label' => $this->getAttributeLabel('created_at')]]; if ($isAdminPanel) { array_push($noteSortAttributes, 'id', 'user.name', 'visibility'); } else { $noteSortAttributes['description'] = ['label' => $this->getAttributeLabel('description')]; } $noteProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => $noteSortAttributes, 'defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => $isAdminPanel ? 10 : 9, 'defaultPageSize' => $isAdminPanel ? 10 : 9]]); return $noteProvider; }
public function movie($id) { $movie = Movie::find($id); $notes = Note::where('movie_id', $movie->_id)->orderBy('note', 'DESC')->get(); $data = ['movie' => $movie, 'notes' => $notes]; return view('movie', $data); }
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"); }
/** * 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.'); } }
/** * 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; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request, Note $noteModel, History $historyModel) { if (right('AddNewPublicNote')) { if (strlen($_POST['notification']) > 0) { $noteModel->addNote($_POST['notification']); $historyModel->saveHistory('create_note'); Session::flash('message', GetMessages("ADD_NEW_NOTE_MESSAGE")); return redirect()->route('note.index'); } else { Session::flash('message', GetMessages("EMPTY_NOTE_MESSAGE")); return redirect()->route('note.index'); } } else { Session::flash('message', GetMessages("NO_RIGHTS")); return redirect($_SERVER['HTTP_REFERER']); } }
public function store(Request $request, $id) { $this->validate($request, ['note' => 'required', 'status' => '', 'fk_lead_id' => '', 'fk_user_id' => '']); $input = $request = array_merge($request->all(), ['fk_lead_id' => $id, 'fk_user_id' => \Auth::id(), 'status' => 0]); Note::create($input); Session::flash('flash_message', 'Note successfully added!'); //Snippet in Master.blade.php return redirect()->back(); }
public function run() { $disViewMore = false; $notes = Note::find()->where(['type_area' => $this->type_area, 'belong_to' => $this->belong_to])->orderBy('id DESC'); if (count($notes->all()) <= 5) { $notes = $notes->all(); $disViewMore = true; } else { $notes = $notes->limit(5)->all(); } return $this->render('notes/index', ['type_area' => $this->type_area, 'belong_to' => $this->belong_to, 'disViewMore' => $disViewMore, 'notes' => $notes]); }
public function addMdiff($movieA, $movieB) { foreach ($this->users as $user) { $noteA = Note::where("movie_id", $movieA->id)->where("user_id", $user->id)->first(); $noteB = Note::where("movie_id", $movieB->id)->where("user_id", $user->id)->first(); if ($noteA && $noteB) { $diff = $noteA->note - $noteB->note; $data = ["movieA_id" => $noteA->movie_id, "movieB_id" => $noteB->movie_id, "diff" => $diff]; Mdiff::create($data); $this->qtdDiffs++; } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Note::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function nota() { $notes = Note::where("movie_id", $this->_id)->get(); $qtd = $notes->count(); if (empty($qtd)) { return 0; } $total = 0; $notes->each(function ($note, $index) use(&$total) { $total += $note->note; }); $media = $total / $qtd; return number_format($media, 1, ',', '.'); }
/** * 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!"); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Note::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith(['access']); $dataProvider->sort->attributes['access'] = ['asc' => ['evrnt_access.user_id' => SORT_ASC], 'desc' => ['evrnt_access.user_id' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['evrnt_note.id' => $this->id, 'evrnt_note.creator' => $this->creator, 'evrnt_note.date_create' => $this->date_create, 'evrnt_access.user_id' => $this->access['user_id']]); $query->andFilterWhere(['like', 'evrnt_note.text', $this->text]); return $dataProvider; }
/** * Deletes single note from persistent storage * @return Array ( deleted => true|false ) */ public function actionDeleteNote() { # Accept only POST requests if (!Yii::$app->request->getIsPost()) { throw new NoteControllerInvalidCallException('Invalid call... ' . __METHOD__ . ' takes in only POST requests.'); } $this->_setJsonResponse(); $data = Json::decode(Yii::$app->request->getPost('note')); $note = Note::find($data['id']); # If note by given ID is not stored in persistent storage we can safely return true... $status = true; if (!is_null($note)) { $status = $note->delete(); } return array('deleted' => $status); }
public static function doAction($qtdProjetosAvaliar) { $users = User::all(); $movies = Movie::all(); $notesMaker = new MakeNotes($users->all(), $movies->all()); $rangeNotes = ["MIN" => 3, "MAX" => 10]; $avaliacoes = $notesMaker->makeNotes($rangeNotes, $qtdProjetosAvaliar); DB::collection('notes')->delete(); $notes = []; foreach ($avaliacoes as $avaliacoesUsuario) { foreach ($avaliacoesUsuario as $avaliacoaUsuario) { array_push($notes, Note::create($avaliacoaUsuario)); } } return count($notes); }
/** * 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!"); }
public function actionHome($viewType = null) { if ($viewType) { Yii::$app->response->cookies->add(new Cookie(['name' => 'viewType', 'value' => $viewType])); } else { if ($cookie = Yii::$app->request->cookies->get('viewType')) { $viewType = $cookie->value; } else { $viewType = 'panel'; Yii::$app->response->cookies->add(new Cookie(['name' => 'viewType', 'value' => $viewType])); } } $query = Note::find(); $noteSearch = new NoteSearch(); $noteSearch->setScenario('own'); $noteProvider = $noteSearch->search(Yii::$app->request->queryParams, ['user_id' => Yii::$app->user->identity->id]); $curDate = getdate(); $beginOfCurDay = \DateTime::createFromFormat('Y-n-j H:i:s', $curDate['year'] . '-' . $curDate['mon'] . '-' . $curDate['mday'] . ' 00:00:00')->getTimestamp(); $beginOfCurMonth = \DateTime::createFromFormat('Y-n-j H:i:s', $curDate['year'] . '-' . $curDate['mon'] . '-1 00:00:00')->getTimestamp(); return $this->render('/notes', ['cur' => 'own', 'viewType' => $viewType, 'notes' => $noteProvider->getModels(), 'pagination' => $noteProvider->pagination, 'sort' => $noteProvider->sort, 'noteSearch' => $noteSearch, 'notesCountDay' => $query->where(['>=', 'created_at', $beginOfCurDay])->andWhere(['user_id' => Yii::$app->user->identity->id])->count(), 'notesCountMonth' => $query->where(['>=', 'created_at', $beginOfCurMonth])->andWhere(['user_id' => Yii::$app->user->identity->id])->count()]); }
public function actionDel() { $id = $_GET['id']; Note::deleteAll(['id' => $id]); $this->redirect(['/notes']); }
/** * 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 qtdAvaliacoes() { return Note::where("user_id", $this->_id)->count(); }
/** * @return \yii\db\ActiveQuery */ public function getNote() { return $this->hasOne(Note::className(), ['id' => 'note_id']); }
<?php use app\models\Note; ?> <ul class="media-list"> <?php // by default value of disViewMore is false $disViewMore = false; $allNotes = Note::find()->where(['type_area' => $type_area, 'belong_to' => $belong_to])->orderBy('id DESC')->all(); if (count($allNotes) <= count($notes)) { $disViewMore = true; } if (!empty($notes)) { foreach ($notes as $key => $note) { ?> <li class="media clearfix"> <a href="page_ready_user_profile.php" class="pull-left"> <img src="/web/upload/avatar/<?php echo $note->user->avatar; ?> " width="64" height="64" alt="Avatar" class="img-circle"> </a> <div class="media-body"> <span class="text-muted text-right pull-right link-hover"> <small> <?php if (strtotime($note->updated_at) > 0) { ?> <em><?php echo $note->timeAgo(strtotime($note->updated_at)); ?>
/** * Get notes */ public function getNotes() { return $this->hasMany(Note::className(), ['user_id' => 'id']); }
function getNotes($id) { $notes = Note::where('doctor_id', '=', $id)->get(); return $notes; }
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']; }
private function findNote($id) { if ($note = Note::findOne($id)) { return $note; } else { throw new NotFoundHttpException('Заметка не найдена'); } }
public function destroy($id) { $question = $this->model->findOrFail($id); $question->tps()->detach(); //TODO: resynch l'ordre $question->delete(); // Détruit les notes associées à cette question $notes = Note::where('question_id', '=', $id)->get(); foreach ($notes as $note) { $note->delete(); } return true; }