repository = $calendar; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Calendar\Repositories\Criteria\CalendarResourceCriteria::class); } /** * Display a list of calendar. * * @return Response */ public function index(CalendarRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litepie\Calendar\Repositories\Presenter\CalendarPresenter::class) ->$function(); } $calendars = $this->repository->paginate(); return $this->response->setMetaTitle(trans('calendar::calendar.names')) ->view('calendar::calendar.index', true) ->data(compact('calendars', 'view')) ->output(); } /** * Display calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function show(CalendarRequest $request, Calendar $calendar) { if ($calendar->exists) { $view = 'calendar::calendar.show'; } else { $view = 'calendar::calendar.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('calendar::calendar.name')) ->data(compact('calendar')) ->view($view, true) ->output(); } /** * Show the form for creating a new calendar. * * @param Request $request * * @return Response */ public function create(CalendarRequest $request) { $calendar = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('calendar::calendar.name')) ->view('calendar::calendar.create', true) ->data(compact('calendar')) ->output(); } /** * Create new calendar. * * @param Request $request * * @return Response */ public function store(CalendarRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $calendar = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('calendar::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('calendar/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/calendar/calendar')) ->redirect(); } } /** * Show calendar for editing. * * @param Request $request * @param Model $calendar * * @return Response */ public function edit(CalendarRequest $request, Calendar $calendar) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('calendar::calendar.name')) ->view('calendar::calendar.edit', true) ->data(compact('calendar')) ->output(); } /** * Update the calendar. * * @param Request $request * @param Model $calendar * * @return Response */ public function update(CalendarRequest $request, Calendar $calendar) { try { $attributes = $request->all(); $calendar->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('calendar::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('calendar/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('calendar/calendar/' . $calendar->getRouteKey())) ->redirect(); } } /** * Remove the calendar. * * @param Model $calendar * * @return Response */ public function destroy(CalendarRequest $request, Calendar $calendar) { try { $calendar->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('calendar::calendar.name')])) ->code(202) ->status('success') ->url(guard_url('calendar/calendar/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('calendar/calendar/' . $calendar->getRouteKey())) ->redirect(); } } /** * Remove multiple calendar. * * @param Model $calendar * * @return Response */ public function delete(CalendarRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('calendar::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('calendar/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/calendar/calendar')) ->redirect(); } } /** * Restore deleted calendars. * * @param Model $calendar * * @return Response */ public function restore(CalendarRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('calendar::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('/calendar/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/calendar/calendar/')) ->redirect(); } } }