repository = $activity; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepci\Okr\Repositories\Criteria\ActivityResourceCriteria::class); } /** * Display a list of activity. * * @return Response */ public function index(ActivityRequest $request) { return $this->repository ->setPresenter(\Litepci\Okr\Repositories\Presenter\ActivityPresenter::class) ->paginate(); } /** * Display activity. * * @param Request $request * @param Model $activity * * @return Response */ public function show(ActivityRequest $request, Activity $activity) { return $activity->setPresenter(\Litepci\Okr\Repositories\Presenter\ActivityListPresenter::class); ; } /** * Create new activity. * * @param Request $request * * @return Response */ public function store(ActivityRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('okr::activity.name')]); $code = 204; $status = 'success'; $url = guard_url('okr/activity/' . $activity->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('okr/activity'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the activity. * * @param Request $request * @param Model $activity * * @return Response */ public function update(ActivityRequest $request, Activity $activity) { try { $data = $request->all(); $activity->update($data); $message = trans('messages.success.updated', ['Module' => trans('okr::activity.name')]); $code = 204; $status = 'success'; $url = guard_url('okr/activity/' . $activity->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('okr/activity/' . $activity->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the activity. * * @param Model $activity * * @return Response */ public function destroy(ActivityRequest $request, Activity $activity) { try { $activity->delete(); $message = trans('messages.success.deleted', ['Module' => trans('okr::activity.name')]); $code = 202; $status = 'success'; $url = guard_url('okr/activity/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('okr/activity/' . $activity->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }