| @@ 13-185 (lines=173) @@ | ||
| 10 | use Scool\Timetables\Repositories\AttendanceRepository; |
|
| 11 | use Scool\Timetables\Validators\AttendanceValidator; |
|
| 12 | ||
| 13 | class AttendancesController extends Controller |
|
| 14 | { |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @var AttendanceRepository |
|
| 18 | */ |
|
| 19 | protected $repository; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var AttendanceValidator |
|
| 23 | */ |
|
| 24 | protected $validator; |
|
| 25 | ||
| 26 | public function __construct(AttendanceRepository $repository, AttendanceValidator $validator) |
|
| 27 | { |
|
| 28 | $this->repository = $repository; |
|
| 29 | $this->validator = $validator; |
|
| 30 | } |
|
| 31 | ||
| 32 | ||
| 33 | /** |
|
| 34 | * Display a listing of the resource. |
|
| 35 | * |
|
| 36 | * @return \Illuminate\Http\Response |
|
| 37 | */ |
|
| 38 | public function index() |
|
| 39 | { |
|
| 40 | $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria')); |
|
| 41 | $attendances = $this->repository->all(); |
|
| 42 | ||
| 43 | if (request()->wantsJson()) { |
|
| 44 | return response()->json([ |
|
| 45 | 'data' => $attendances, |
|
| 46 | ]); |
|
| 47 | } |
|
| 48 | ||
| 49 | return view('timetables::attendances.index', compact('attendances')); |
|
| 50 | } |
|
| 51 | ||
| 52 | //TODO : create |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Store a newly created resource in storage. |
|
| 56 | * |
|
| 57 | * @param AttendanceCreateRequest $request |
|
| 58 | * |
|
| 59 | * @return \Illuminate\Http\Response |
|
| 60 | */ |
|
| 61 | public function store(AttendanceCreateRequest $request) |
|
| 62 | { |
|
| 63 | try { |
|
| 64 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE); |
|
| 65 | ||
| 66 | $attendance = $this->repository->create($request->all()); |
|
| 67 | ||
| 68 | $response = [ |
|
| 69 | 'message' => 'Attendance created.', |
|
| 70 | 'data' => $attendance->toArray(), |
|
| 71 | ]; |
|
| 72 | ||
| 73 | if ($request->wantsJson()) { |
|
| 74 | return response()->json($response); |
|
| 75 | } |
|
| 76 | ||
| 77 | return redirect()->back()->with('message', $response['message']); |
|
| 78 | } catch (ValidatorException $e) { |
|
| 79 | if ($request->wantsJson()) { |
|
| 80 | return response()->json([ |
|
| 81 | 'error' => true, |
|
| 82 | 'message' => $e->getMessageBag() |
|
| 83 | ]); |
|
| 84 | } |
|
| 85 | ||
| 86 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||
| 90 | ||
| 91 | /** |
|
| 92 | * Display the specified resource. |
|
| 93 | * |
|
| 94 | * @param int $id |
|
| 95 | * |
|
| 96 | * @return \Illuminate\Http\Response |
|
| 97 | */ |
|
| 98 | public function show($id) |
|
| 99 | { |
|
| 100 | $attendance = $this->repository->find($id); |
|
| 101 | ||
| 102 | if (request()->wantsJson()) { |
|
| 103 | return response()->json([ |
|
| 104 | 'data' => $attendance, |
|
| 105 | ]); |
|
| 106 | } |
|
| 107 | ||
| 108 | return view('timetables::attendances.show', compact('attendance')); |
|
| 109 | } |
|
| 110 | ||
| 111 | ||
| 112 | /** |
|
| 113 | * Show the form for editing the specified resource. |
|
| 114 | * |
|
| 115 | * @param int $id |
|
| 116 | * |
|
| 117 | * @return \Illuminate\Http\Response |
|
| 118 | */ |
|
| 119 | public function edit($id) |
|
| 120 | { |
|
| 121 | $attendance = $this->repository->find($id); |
|
| 122 | ||
| 123 | return view('timetables::attendances.edit', compact('attendance')); |
|
| 124 | } |
|
| 125 | ||
| 126 | ||
| 127 | /** |
|
| 128 | * Update the specified resource in storage. |
|
| 129 | * |
|
| 130 | * @param AttendanceUpdateRequest $request |
|
| 131 | * @param string $id |
|
| 132 | * |
|
| 133 | * @return Response |
|
| 134 | */ |
|
| 135 | public function update(AttendanceUpdateRequest $request, $id) |
|
| 136 | { |
|
| 137 | try { |
|
| 138 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE); |
|
| 139 | ||
| 140 | $attendance = $this->repository->update( $request->all(),$id); |
|
| 141 | ||
| 142 | $response = [ |
|
| 143 | 'message' => 'Attendance updated.', |
|
| 144 | 'data' => $attendance->toArray(), |
|
| 145 | ]; |
|
| 146 | ||
| 147 | if ($request->wantsJson()) { |
|
| 148 | return response()->json($response); |
|
| 149 | } |
|
| 150 | ||
| 151 | return redirect()->back()->with('message', $response['message']); |
|
| 152 | } catch (ValidatorException $e) { |
|
| 153 | if ($request->wantsJson()) { |
|
| 154 | return response()->json([ |
|
| 155 | 'error' => true, |
|
| 156 | 'message' => $e->getMessageBag() |
|
| 157 | ]); |
|
| 158 | } |
|
| 159 | ||
| 160 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 161 | } |
|
| 162 | } |
|
| 163 | ||
| 164 | ||
| 165 | /** |
|
| 166 | * Remove the specified resource from storage. |
|
| 167 | * |
|
| 168 | * @param int $id |
|
| 169 | * |
|
| 170 | * @return \Illuminate\Http\Response |
|
| 171 | */ |
|
| 172 | public function destroy($id) |
|
| 173 | { |
|
| 174 | $deleted = $this->repository->delete($id); |
|
| 175 | ||
| 176 | if (request()->wantsJson()) { |
|
| 177 | return response()->json([ |
|
| 178 | 'message' => 'Attendance deleted.', |
|
| 179 | 'deleted' => $deleted, |
|
| 180 | ]); |
|
| 181 | } |
|
| 182 | ||
| 183 | return redirect()->back()->with('message', 'Attendance deleted.'); |
|
| 184 | } |
|
| 185 | } |
|
| 186 | ||
| @@ 15-197 (lines=183) @@ | ||
| 12 | use Scool\Timetables\Validators\DesiratumValidator; |
|
| 13 | ||
| 14 | ||
| 15 | class DesirataController extends Controller |
|
| 16 | { |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @var DesiratumRepository |
|
| 20 | */ |
|
| 21 | protected $repository; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @var DesiratumValidator |
|
| 25 | */ |
|
| 26 | protected $validator; |
|
| 27 | ||
| 28 | public function __construct(DesiratumRepository $repository, DesiratumValidator $validator) |
|
| 29 | { |
|
| 30 | $this->repository = $repository; |
|
| 31 | $this->validator = $validator; |
|
| 32 | } |
|
| 33 | ||
| 34 | ||
| 35 | /** |
|
| 36 | * Display a listing of the resource. |
|
| 37 | * |
|
| 38 | * @return \Illuminate\Http\Response |
|
| 39 | */ |
|
| 40 | public function index() |
|
| 41 | { |
|
| 42 | $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria')); |
|
| 43 | $desirata = $this->repository->all(); |
|
| 44 | ||
| 45 | if (request()->wantsJson()) { |
|
| 46 | ||
| 47 | return response()->json([ |
|
| 48 | 'data' => $desirata, |
|
| 49 | ]); |
|
| 50 | } |
|
| 51 | ||
| 52 | return view('desirata.index', compact('desirata')); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Store a newly created resource in storage. |
|
| 57 | * |
|
| 58 | * @param DesiratumCreateRequest $request |
|
| 59 | * |
|
| 60 | * @return \Illuminate\Http\Response |
|
| 61 | */ |
|
| 62 | public function store(DesiratumCreateRequest $request) |
|
| 63 | { |
|
| 64 | ||
| 65 | try { |
|
| 66 | ||
| 67 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE); |
|
| 68 | ||
| 69 | $desiratum = $this->repository->create($request->all()); |
|
| 70 | ||
| 71 | $response = [ |
|
| 72 | 'message' => 'Desiratum created.', |
|
| 73 | 'data' => $desiratum->toArray(), |
|
| 74 | ]; |
|
| 75 | ||
| 76 | if ($request->wantsJson()) { |
|
| 77 | ||
| 78 | return response()->json($response); |
|
| 79 | } |
|
| 80 | ||
| 81 | return redirect()->back()->with('message', $response['message']); |
|
| 82 | } catch (ValidatorException $e) { |
|
| 83 | if ($request->wantsJson()) { |
|
| 84 | return response()->json([ |
|
| 85 | 'error' => true, |
|
| 86 | 'message' => $e->getMessageBag() |
|
| 87 | ]); |
|
| 88 | } |
|
| 89 | ||
| 90 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 91 | } |
|
| 92 | } |
|
| 93 | ||
| 94 | ||
| 95 | /** |
|
| 96 | * Display the specified resource. |
|
| 97 | * |
|
| 98 | * @param int $id |
|
| 99 | * |
|
| 100 | * @return \Illuminate\Http\Response |
|
| 101 | */ |
|
| 102 | public function show($id) |
|
| 103 | { |
|
| 104 | $desiratum = $this->repository->find($id); |
|
| 105 | ||
| 106 | if (request()->wantsJson()) { |
|
| 107 | ||
| 108 | return response()->json([ |
|
| 109 | 'data' => $desiratum, |
|
| 110 | ]); |
|
| 111 | } |
|
| 112 | ||
| 113 | return view('desirata.show', compact('desiratum')); |
|
| 114 | } |
|
| 115 | ||
| 116 | ||
| 117 | /** |
|
| 118 | * Show the form for editing the specified resource. |
|
| 119 | * |
|
| 120 | * @param int $id |
|
| 121 | * |
|
| 122 | * @return \Illuminate\Http\Response |
|
| 123 | */ |
|
| 124 | public function edit($id) |
|
| 125 | { |
|
| 126 | ||
| 127 | $desiratum = $this->repository->find($id); |
|
| 128 | ||
| 129 | return view('desirata.edit', compact('desiratum')); |
|
| 130 | } |
|
| 131 | ||
| 132 | ||
| 133 | /** |
|
| 134 | * Update the specified resource in storage. |
|
| 135 | * |
|
| 136 | * @param DesiratumUpdateRequest $request |
|
| 137 | * @param string $id |
|
| 138 | * |
|
| 139 | * @return Response |
|
| 140 | */ |
|
| 141 | public function update(DesiratumUpdateRequest $request, $id) |
|
| 142 | { |
|
| 143 | ||
| 144 | try { |
|
| 145 | ||
| 146 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE); |
|
| 147 | ||
| 148 | $desiratum = $this->repository->update($request->all(), $id); |
|
| 149 | ||
| 150 | $response = [ |
|
| 151 | 'message' => 'Desiratum updated.', |
|
| 152 | 'data' => $desiratum->toArray(), |
|
| 153 | ]; |
|
| 154 | ||
| 155 | if ($request->wantsJson()) { |
|
| 156 | ||
| 157 | return response()->json($response); |
|
| 158 | } |
|
| 159 | ||
| 160 | return redirect()->back()->with('message', $response['message']); |
|
| 161 | } catch (ValidatorException $e) { |
|
| 162 | ||
| 163 | if ($request->wantsJson()) { |
|
| 164 | ||
| 165 | return response()->json([ |
|
| 166 | 'error' => true, |
|
| 167 | 'message' => $e->getMessageBag() |
|
| 168 | ]); |
|
| 169 | } |
|
| 170 | ||
| 171 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 172 | } |
|
| 173 | } |
|
| 174 | ||
| 175 | ||
| 176 | /** |
|
| 177 | * Remove the specified resource from storage. |
|
| 178 | * |
|
| 179 | * @param int $id |
|
| 180 | * |
|
| 181 | * @return \Illuminate\Http\Response |
|
| 182 | */ |
|
| 183 | public function destroy($id) |
|
| 184 | { |
|
| 185 | $deleted = $this->repository->delete($id); |
|
| 186 | ||
| 187 | if (request()->wantsJson()) { |
|
| 188 | ||
| 189 | return response()->json([ |
|
| 190 | 'message' => 'Desiratum deleted.', |
|
| 191 | 'deleted' => $deleted, |
|
| 192 | ]); |
|
| 193 | } |
|
| 194 | ||
| 195 | return redirect()->back()->with('message', 'Desiratum deleted.'); |
|
| 196 | } |
|
| 197 | } |
|
| 198 | ||
| @@ 12-204 (lines=193) @@ | ||
| 9 | use Scool\Timetables\Repositories\LessonRepository; |
|
| 10 | use Scool\Timetables\Validators\LessonValidator; |
|
| 11 | ||
| 12 | class LessonsController extends Controller |
|
| 13 | { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var LessonRepository |
|
| 17 | */ |
|
| 18 | protected $repository; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var LessonValidator |
|
| 22 | */ |
|
| 23 | protected $validator; |
|
| 24 | ||
| 25 | public function __construct(LessonRepository $repository, LessonValidator $validator) |
|
| 26 | { |
|
| 27 | $this->repository = $repository; |
|
| 28 | $this->validator = $validator; |
|
| 29 | } |
|
| 30 | ||
| 31 | ||
| 32 | /** |
|
| 33 | * Display a listing of the resource. |
|
| 34 | * |
|
| 35 | * @return \Illuminate\Http\Response |
|
| 36 | */ |
|
| 37 | public function index() |
|
| 38 | { |
|
| 39 | $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria')); |
|
| 40 | $lessons = $this->repository->all(); |
|
| 41 | ||
| 42 | if (request()->wantsJson()) { |
|
| 43 | ||
| 44 | return response()->json([ |
|
| 45 | 'data' => $lessons, |
|
| 46 | ]); |
|
| 47 | } |
|
| 48 | ||
| 49 | return view('lessons.index', compact('lessons')); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Show the form for creating the specified resource. |
|
| 54 | * |
|
| 55 | * @return \Illuminate\Http\Response |
|
| 56 | */ |
|
| 57 | public function create() |
|
| 58 | { |
|
| 59 | return view('lessons.create'); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Store a newly created resource in storage. |
|
| 64 | * |
|
| 65 | * @param LessonCreateRequest $request |
|
| 66 | * |
|
| 67 | * @return \Illuminate\Http\Response |
|
| 68 | */ |
|
| 69 | public function store(LessonCreateRequest $request) |
|
| 70 | { |
|
| 71 | ||
| 72 | try { |
|
| 73 | ||
| 74 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE); |
|
| 75 | ||
| 76 | $lesson = $this->repository->create($request->all()); |
|
| 77 | ||
| 78 | $response = [ |
|
| 79 | 'message' => 'Lesson created.', |
|
| 80 | 'data' => $lesson->toArray(), |
|
| 81 | ]; |
|
| 82 | ||
| 83 | if ($request->wantsJson()) { |
|
| 84 | ||
| 85 | return response()->json($response); |
|
| 86 | } |
|
| 87 | ||
| 88 | return redirect()->back()->with('message', $response['message']); |
|
| 89 | } catch (ValidatorException $e) { |
|
| 90 | if ($request->wantsJson()) { |
|
| 91 | return response()->json([ |
|
| 92 | 'error' => true, |
|
| 93 | 'message' => $e->getMessageBag() |
|
| 94 | ]); |
|
| 95 | } |
|
| 96 | ||
| 97 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 98 | } |
|
| 99 | } |
|
| 100 | ||
| 101 | ||
| 102 | /** |
|
| 103 | * Display the specified resource. |
|
| 104 | * |
|
| 105 | * @param int $id |
|
| 106 | * |
|
| 107 | * @return \Illuminate\Http\Response |
|
| 108 | */ |
|
| 109 | public function show($id) |
|
| 110 | { |
|
| 111 | $lesson = $this->repository->find($id); |
|
| 112 | ||
| 113 | if (request()->wantsJson()) { |
|
| 114 | ||
| 115 | return response()->json([ |
|
| 116 | 'data' => $lesson, |
|
| 117 | ]); |
|
| 118 | } |
|
| 119 | ||
| 120 | return view('lessons.show', compact('lesson')); |
|
| 121 | } |
|
| 122 | ||
| 123 | ||
| 124 | /** |
|
| 125 | * Show the form for editing the specified resource. |
|
| 126 | * |
|
| 127 | * @param int $id |
|
| 128 | * |
|
| 129 | * @return \Illuminate\Http\Response |
|
| 130 | */ |
|
| 131 | public function edit($id) |
|
| 132 | { |
|
| 133 | ||
| 134 | $lesson = $this->repository->find($id); |
|
| 135 | ||
| 136 | return view('lessons.edit', compact('lesson')); |
|
| 137 | } |
|
| 138 | ||
| 139 | ||
| 140 | /** |
|
| 141 | * Update the specified resource in storage. |
|
| 142 | * |
|
| 143 | * @param LessonUpdateRequest $request |
|
| 144 | * @param string $id |
|
| 145 | * |
|
| 146 | * @return Response |
|
| 147 | */ |
|
| 148 | public function update(LessonUpdateRequest $request, $id) |
|
| 149 | { |
|
| 150 | ||
| 151 | try { |
|
| 152 | ||
| 153 | $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE); |
|
| 154 | ||
| 155 | $lesson = $this->repository->update($request->all(), $id); |
|
| 156 | ||
| 157 | $response = [ |
|
| 158 | 'message' => 'Lesson updated.', |
|
| 159 | 'data' => $lesson->toArray(), |
|
| 160 | ]; |
|
| 161 | ||
| 162 | if ($request->wantsJson()) { |
|
| 163 | ||
| 164 | return response()->json($response); |
|
| 165 | } |
|
| 166 | ||
| 167 | return redirect()->back()->with('message', $response['message']); |
|
| 168 | } catch (ValidatorException $e) { |
|
| 169 | ||
| 170 | if ($request->wantsJson()) { |
|
| 171 | ||
| 172 | return response()->json([ |
|
| 173 | 'error' => true, |
|
| 174 | 'message' => $e->getMessageBag() |
|
| 175 | ]); |
|
| 176 | } |
|
| 177 | ||
| 178 | return redirect()->back()->withErrors($e->getMessageBag())->withInput(); |
|
| 179 | } |
|
| 180 | } |
|
| 181 | ||
| 182 | ||
| 183 | /** |
|
| 184 | * Remove the specified resource from storage. |
|
| 185 | * |
|
| 186 | * @param int $id |
|
| 187 | * |
|
| 188 | * @return \Illuminate\Http\Response |
|
| 189 | */ |
|
| 190 | public function destroy($id) |
|
| 191 | { |
|
| 192 | $deleted = $this->repository->delete($id); |
|
| 193 | ||
| 194 | if (request()->wantsJson()) { |
|
| 195 | ||
| 196 | return response()->json([ |
|
| 197 | 'message' => 'Lesson deleted.', |
|
| 198 | 'deleted' => $deleted, |
|
| 199 | ]); |
|
| 200 | } |
|
| 201 | ||
| 202 | return redirect()->back()->with('message', 'Lesson deleted.'); |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||