public function show($notebookId, $noteId, $versionId) { $note = Note::with(array('users' => function ($query) { $query->where('note_user.user_id', '=', Auth::user()->id); }, 'notebook' => function ($query) use(&$notebookId) { $query->where('id', $notebookId > 0 ? '=' : '>', $notebookId > 0 ? $notebookId : '0'); }, 'version' => function ($query) { }))->where('id', '=', $noteId)->whereNull('deleted_at')->first(); $currentVersion = $note->version()->first(); if (is_null($currentVersion)) { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array()); } while (!is_null($currentVersion)) { if ($currentVersion->id == $versionId || $versionId == '0') { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $currentVersion); } $currentVersion = $currentVersion->previous()->first(); } return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array()); }
private function getNoteVersionsBrief($noteId) { $note = Note::with('version')->where('notes.id', '=', $noteId)->first(); $versionsObject = $note->version()->first(); if (is_null($versionsObject)) { return null; } $versionsArray = []; $tmp = $versionsObject; $isLatest = true; $versions = array(); while (!is_null($tmp)) { $versionsArray[] = $tmp; $user = $tmp->user()->first(); $versions[] = array('id' => $tmp->id, 'previous_id' => $tmp->previous_id, 'next_id' => $tmp->next_id, 'latest' => $isLatest, 'timestamp' => $tmp->created_at->getTimestamp(), 'username' => $user->firstname . ' ' . $user->lastname); $isLatest = false; $tmp = $tmp->previous()->first(); } return $versions; }
public function get($argv = array()) { //the version_id has to be included here or the eager load below will fail //also, all off the ids of the relationships have to be here also, or it will also fail $defaultNotesSelect = array('notes.id', 'notes.notebook_id', 'notes.created_at', 'notes.updated_at', 'notes.version_id'); $defaultVersionsSelect = array('versions.id', 'versions.title', 'versions.content_preview', 'versions.content', 'versions.user_id'); $defaultTagsSelect = array('tags.id', 'tags.visibility', 'tags.title'); $defaultUsersSelect = array('users.id', 'users.firstname', 'users.lastname'); $userId = $this->getArg($argv, 'userid'); $id = $this->getArg($argv, 'id'); $notebookId = $this->getArg($argv, 'notebookid'); $data = \Note::with(array('version' => function ($query) use(&$defaultVersionsSelect, &$defaultUsersSelect) { $query->select($defaultVersionsSelect)->with(array('user' => function ($query) use(&$defaultUsersSelect) { $query->select($defaultUsersSelect); })); }, 'tags' => function ($query) use(&$defaultTagsSelect, &$userId) { $query->select($defaultTagsSelect)->where('visibility', '=', 1)->orWhere('tags.user_id', '=', $userId); }, 'users' => function ($query) use(&$defaultUsersSelect) { $query->select($defaultUsersSelect)->wherePivot('umask', '=', \PaperworkHelpers::UMASK_OWNER); }))->join('note_user', function ($join) use(&$userId) { $join->on('note_user.note_id', '=', 'notes.id')->where('note_user.user_id', '=', $userId)->where('note_user.umask', '>', 0); })->select($defaultNotesSelect); $idCount = count($id); if ($idCount > 0) { $data->where('notes.id', '=', $argv['id'][0]); } if ($idCount > 1) { for ($i = 1; $i < $idCount; $i++) { $data->orWhere('notes.id', '=', $argv['id'][$i]); } } if (isset($notebookId) && $notebookId != \PaperworkDb::DB_ALL_ID) { $data->where('notes.notebook_id', '=', $notebookId); } $data->whereNull('deleted_at'); return $data->get(); }
public function index() { $loggedInUser = Auth::user()->id; $notes = Note::with('user')->where('user_id', '=', $loggedInUser)->orderBy('updated_at', 'desc')->paginate(10); return View::make('notes.index')->with('notes', $notes); }
public function showNotes() { $notes = Note::with('user')->where('public_or_private', '=', 'public')->orderBy('id', 'desc')->paginate(10); return View::make('feed.notes')->with('notes', $notes); }