/** * Update a specific note. Besides notes id, the user_id has to match, if it * doesn't, throw not found exception * * @param array request input * @param int note's id * * @return App\Model\Note */ public function update($input, $id) { $user = $this->container->get('currentUser'); $note = Note::where('id', $id)->where('user_id', $user->userId)->firstOrFail(); $note->body = $input['body']; $note->save(); return $note; }
/** * Delete a single note if specified its id or delete all if no id is * passed in the request * * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request * @param \Psr\Http\Message\ResponseInterface $response PSR7 response * @param callable $next Next middleware * * @return \Psr\Http\Message\ResponseInterface */ public function dispatch(Request $request, Response $response, $args) { $user = $this->container->get('currentUser'); $id = isset($args['id']) ? (int) $args['id'] : null; if ($id) { Note::destroy($id); } else { Note::where('user_id', $user->userId)->delete(); } $response = $response->withStatus(204); return $response; }
public function dispatch(Request $request, Response $response, $args) { $user = $this->container->get('currentUser'); $id = isset($args['id']) ? (int) $args['id'] : null; $notes = []; if ($id) { $note = Note::where('id', $id)->where('user_id', $user->userId)->firstOrFail(); $notes = [$note]; } else { $notes = User::findOrFail($user->userId)->notes; } return $response->write(json_encode(['message' => 'List of Notes', 'data' => $notes])); }
public function searchMainNote() { if (Request::ajax()) { $searchNoteName = Input::get('searchNoteName'); $searchType = Input::get('searchType'); $searchCommType = Input::get('searchCommType'); if ($searchCommType == "" && $searchNoteName == "" && $searchType == "") { return Response::json(['result' => 'error', 'message' => "You have to select one item on the select box."]); } else { $peopleId = Input::get('peopleId'); $query = NoteModel::where('peopleId', '=', $peopleId); if ($searchNoteName != "") { $querySearchNoteName = '%' . $searchNoteName . '%'; $query->where('notes', 'like', $querySearchNoteName); } if ($searchType != "") { $query->where('notesTypeId', '=', $searchType); } if ($searchCommType != "") { $query->where('notesCommTypeId', '=', $searchCommType); } $note = $query->get(); if (count($note) > 0) { $list = ''; $list .= '<div class="row">'; for ($i = 0; $i < count($note); $i++) { $list .= '<div class="col-md-10 col-md-offset-1 margin-bottom-20 forest-change-note-header">'; if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") { $list .= '<div class="panel panel-blue margin-bottom-20">'; } else { if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") { $list .= '<div class="panel panel-green margin-bottom-20">'; } } $list .= '<div class="panel-heading forest-panel-heading-note">'; $list .= '<h3 class="panel-title forest-panel-title-note">'; if (strtoupper($note[$i]->noteCommType->noteCommType) == "PHONE") { $list .= '<img src="/images/Modern-Phone-icon.jpg" style="width:30px; height:30px;">'; } else { if (strtoupper($note[$i]->noteCommType->noteCommType) == "EMAIL") { $list .= '<img src="/images/Email.png" style="width:30px; height:30px;">'; } } $list .= '<a href = "javascript:void(0)" onclick = "onEditNoteChangeModal(' . $note[$i]->id . ')">Edit</a>'; $list .= '<span>(' . ucfirst($note[$i]->noteType->notesType) . ')</span>'; $list .= '<span>(' . substr($note[$i]->updated_at, 0, 16) . ')</span>'; $list .= '<span>(' . ucfirst($note[$i]->noteStatus->notesStatus) . ')</span>'; $list .= ' </h3> </div> <div class="panel-body">'; $list .= $note[$i]->notes; $list .= ' </div> </div> </div>'; } $list .= '</div>'; return Response::json(['result' => 'success', 'list' => $list, 'countList' => count($note)]); } else { return Response::json(['result' => 'empty', 'message' => "This contact don't have note for your request."]); } } } else { } }