repository = $calendar; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Cleancrm\Advancedcrm\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(\Cleancrm\Advancedcrm\Repositories\Presenter\CalendarPresenter::class) ->$function(); } $calendars = $this->repository->paginate(); return $this->response->setMetaTitle(trans('advancedcrm::calendar.names')) ->view('advancedcrm::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 = 'advancedcrm::calendar.show'; } else { $view = 'advancedcrm::calendar.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('advancedcrm::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('advancedcrm::calendar.name')) ->view('advancedcrm::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('advancedcrm::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('advancedcrm/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/advancedcrm/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('advancedcrm::calendar.name')) ->view('advancedcrm::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('advancedcrm::calendar.name')])) ->code(204) ->status('success') ->url(guard_url('advancedcrm/calendar/' . $calendar->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('advancedcrm/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('advancedcrm::calendar.name')])) ->code(202) ->status('success') ->url(guard_url('advancedcrm/calendar/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('advancedcrm/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('advancedcrm::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('advancedcrm/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/advancedcrm/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('advancedcrm::calendar.name')])) ->status("success") ->code(202) ->url(guard_url('/advancedcrm/calendar')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/advancedcrm/calendar/')) ->redirect(); } } }