Code Duplication    Length = 175-183 lines in 9 locations

src/Http/Controllers/EnrollmentsController.php 1 location

@@ 16-190 (lines=175) @@
13
 * Class EnrollmentsController
14
 * @package App\Http\Controllers
15
 */
16
class EnrollmentsController extends Controller
17
{
18
19
    /**
20
     * @var EnrollmentRepository
21
     */
22
    protected $repository;
23
24
    /**
25
     * @var EnrollmentValidator
26
     */
27
    protected $validator;
28
29
    /**
30
     * EnrollmentsController constructor.
31
     * @param EnrollmentRepository $repository
32
     * @param EnrollmentValidator $validator
33
     */
34
    public function __construct(EnrollmentRepository $repository, EnrollmentValidator $validator)
35
    {
36
        $this->repository = $repository;
37
        $this->validator  = $validator;
38
    }
39
40
41
    /**
42
     * Display a listing of the resource.
43
     *
44
     * @return \Illuminate\Http\Response
45
     */
46
    public function index()
47
    {
48
        $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
49
        $enrollments = $this->repository->all();
50
        if (request()->wantsJson()) {
51
            return response()->json([
52
                'data' => $enrollments,
53
            ]);
54
        }
55
56
        return view('enrollments.index', compact('enrollments'));
57
    }
58
59
    /**
60
     * Store a newly created resource in storage.
61
     *
62
     * @param  EnrollmentCreateRequest $request
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function store(EnrollmentCreateRequest $request)
67
    {
68
        try {
69
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
70
71
            $enrollment = $this->repository->create($request->all());
72
73
            $response = [
74
                'message' => 'Enrollment created.',
75
                'data'    => $enrollment->toArray(),
76
            ];
77
78
            if ($request->wantsJson()) {
79
                return response()->json($response);
80
            }
81
82
            return redirect()->back()->with('message', $response['message']);
83
        } catch (ValidatorException $e) {
84
            if ($request->wantsJson()) {
85
                return response()->json([
86
                    'error'   => true,
87
                    'message' => $e->getMessageBag()
88
                ]);
89
            }
90
91
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
92
        }
93
    }
94
95
96
    /**
97
     * Display the specified resource.
98
     *
99
     * @param  int $id
100
     *
101
     * @return \Illuminate\Http\Response
102
     */
103
    public function show($id)
104
    {
105
        $enrollment = $this->repository->find($id);
106
107
        if (request()->wantsJson()) {
108
            return response()->json([
109
                'data' => $enrollment,
110
            ]);
111
        }
112
113
        return view('enrollments.show', compact('enrollment'));
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
        $enrollment = $this->repository->find($id);
127
128
        return view('enrollments.edit', compact('enrollment'));
129
    }
130
131
132
    /**
133
     * Update the specified resource in storage.
134
     *
135
     * @param  EnrollmentUpdateRequest $request
136
     * @param  string            $id
137
     *
138
     * @return Response
139
     */
140
    public function update(EnrollmentUpdateRequest $request, $id)
141
    {
142
        try {
143
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
144
145
            $enrollment = $this->repository->update($id, $request->all());
146
147
            $response = [
148
                'message' => 'Enrollment updated.',
149
                'data'    => $enrollment->toArray(),
150
            ];
151
152
            if ($request->wantsJson()) {
153
                return response()->json($response);
154
            }
155
156
            return redirect()->back()->with('message', $response['message']);
157
        } catch (ValidatorException $e) {
158
            if ($request->wantsJson()) {
159
                return response()->json([
160
                    'error'   => true,
161
                    'message' => $e->getMessageBag()
162
                ]);
163
            }
164
165
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
166
        }
167
    }
168
169
170
    /**
171
     * Remove the specified resource from storage.
172
     *
173
     * @param  int $id
174
     *
175
     * @return \Illuminate\Http\Response
176
     */
177
    public function destroy($id)
178
    {
179
        $deleted = $this->repository->delete($id);
180
181
        if (request()->wantsJson()) {
182
            return response()->json([
183
                'message' => 'Enrollment deleted.',
184
                'deleted' => $deleted,
185
            ]);
186
        }
187
188
        return redirect()->back()->with('message', 'Enrollment deleted.');
189
    }
190
}
191
//mock del repository del create(crear nosalters lenrollment per fer el test).
192
//TODO: Fer testos de validació enrollment_mobile i todos_Backend.
193

src/Http/Controllers/ClassroomsController.php 1 location

@@ 15-197 (lines=183) @@
12
use Scool\EnrollmentMobile\Repositories\ClassroomRepository;
13
use Scool\EnrollmentMobile\Validators\ClassroomValidator;
14
15
class ClassroomsController extends Controller
16
{
17
18
    /**
19
     * @var ClassroomRepository
20
     */
21
    protected $repository;
22
23
    /**
24
     * @var ClassroomValidator
25
     */
26
    protected $validator;
27
28
    public function __construct(ClassroomRepository $repository, ClassroomValidator $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
        $classrooms = $this->repository->all();
44
45
        if (request()->wantsJson()) {
46
            return response()->json([
47
                'data' => $classrooms,
48
            ]);
49
        }
50
51
        return view('classrooms.index', compact('classrooms'));
52
    }
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param  ClassroomCreateRequest $request
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(ClassroomCreateRequest $request)
62
    {
63
        try {
64
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
65
66
            $classroom = $this->repository->create($request->all());
67
68
            $response = [
69
                'message' => 'Classroom created.',
70
                'data'    => $classroom->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
        $classroom = $this->repository->find($id);
101
102
        if (request()->wantsJson()) {
103
            return response()->json([
104
                'data' => $classroom,
105
            ]);
106
        }
107
108
        return view('classrooms.show', compact('classroom'));
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
        $classroom = $this->repository->find($id);
122
123
        return view('classrooms.edit', compact('classroom'));
124
    }
125
126
127
    /**
128
     * Update the specified resource in storage.
129
     *
130
     * @param  ClassroomUpdateRequest $request
131
     * @param  string            $id
132
     *
133
     * @return Response
134
     */
135
    public function update(ClassroomUpdateRequest $request, $id)
136
    {
137
        try {
138
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
139
140
            $classroom = $this->repository->update($id, $request->all());
141
142
            $response = [
143
                'message' => 'Classroom updated.',
144
                'data'    => $classroom->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' => 'Classroom deleted.',
179
                'deleted' => $deleted,
180
            ]);
181
        }
182
183
        return redirect()->back()->with('message', 'Classroom deleted.');
184
    }
185
}
186

src/Http/Controllers/CoursesController.php 1 location

@@ 15-197 (lines=183) @@
12
use Scool\EnrollmentMobile\Repositories\CourseRepository;
13
use Scool\EnrollmentMobile\Validators\CourseValidator;
14
15
class CoursesController extends Controller
16
{
17
18
    /**
19
     * @var CourseRepository
20
     */
21
    protected $repository;
22
23
    /**
24
     * @var CourseValidator
25
     */
26
    protected $validator;
27
28
    public function __construct(CourseRepository $repository, CourseValidator $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
        $courses = $this->repository->all();
44
45
        if (request()->wantsJson()) {
46
            return response()->json([
47
                'data' => $courses,
48
            ]);
49
        }
50
51
        return view('courses.index', compact('courses'));
52
    }
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param  CourseCreateRequest $request
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(CourseCreateRequest $request)
62
    {
63
        try {
64
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
65
66
            $course = $this->repository->create($request->all());
67
68
            $response = [
69
                'message' => 'Course created.',
70
                'data'    => $course->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
        $course = $this->repository->find($id);
101
102
        if (request()->wantsJson()) {
103
            return response()->json([
104
                'data' => $course,
105
            ]);
106
        }
107
108
        return view('courses.show', compact('course'));
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
        $course = $this->repository->find($id);
122
123
        return view('courses.edit', compact('course'));
124
    }
125
126
127
    /**
128
     * Update the specified resource in storage.
129
     *
130
     * @param  CourseUpdateRequest $request
131
     * @param  string            $id
132
     *
133
     * @return Response
134
     */
135
    public function update(CourseUpdateRequest $request, $id)
136
    {
137
        try {
138
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
139
140
            $course = $this->repository->update($id, $request->all());
141
142
            $response = [
143
                'message' => 'Course updated.',
144
                'data'    => $course->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' => 'Course deleted.',
179
                'deleted' => $deleted,
180
            ]);
181
        }
182
183
        return redirect()->back()->with('message', 'Course deleted.');
184
    }
185
}
186

src/Http/Controllers/EnrollmentStudySubmodulesController.php 1 location

@@ 15-197 (lines=183) @@
12
use Scool\EnrollmentMobile\Repositories\EnrollmentStudySubmoduleRepository;
13
use Scool\EnrollmentMobile\Validators\EnrollmentStudySubmoduleValidator;
14
15
class EnrollmentStudySubmodulesController extends Controller
16
{
17
18
    /**
19
     * @var EnrollmentStudySubmoduleRepository
20
     */
21
    protected $repository;
22
23
    /**
24
     * @var EnrollmentStudySubmoduleValidator
25
     */
26
    protected $validator;
27
28
    public function __construct(EnrollmentStudySubmoduleRepository $repository, EnrollmentStudySubmoduleValidator $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
        $enrollmentStudySubmodules = $this->repository->all();
44
45
        if (request()->wantsJson()) {
46
            return response()->json([
47
                'data' => $enrollmentStudySubmodules,
48
            ]);
49
        }
50
51
        return view('enrollmentStudySubmodules.index', compact('enrollmentStudySubmodules'));
52
    }
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param  EnrollmentStudySubmoduleCreateRequest $request
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(EnrollmentStudySubmoduleCreateRequest $request)
62
    {
63
        try {
64
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
65
66
            $enrollmentStudySubmodule = $this->repository->create($request->all());
67
68
            $response = [
69
                'message' => 'EnrollmentStudySubmodule created.',
70
                'data'    => $enrollmentStudySubmodule->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
        $enrollmentStudySubmodule = $this->repository->find($id);
101
102
        if (request()->wantsJson()) {
103
            return response()->json([
104
                'data' => $enrollmentStudySubmodule,
105
            ]);
106
        }
107
108
        return view('enrollmentStudySubmodules.show', compact('enrollmentStudySubmodule'));
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
        $enrollmentStudySubmodule = $this->repository->find($id);
122
123
        return view('enrollmentStudySubmodules.edit', compact('enrollmentStudySubmodule'));
124
    }
125
126
127
    /**
128
     * Update the specified resource in storage.
129
     *
130
     * @param  EnrollmentStudySubmoduleUpdateRequest $request
131
     * @param  string            $id
132
     *
133
     * @return Response
134
     */
135
    public function update(EnrollmentStudySubmoduleUpdateRequest $request, $id)
136
    {
137
        try {
138
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
139
140
            $enrollmentStudySubmodule = $this->repository->update($id, $request->all());
141
142
            $response = [
143
                'message' => 'EnrollmentStudySubmodule updated.',
144
                'data'    => $enrollmentStudySubmodule->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' => 'EnrollmentStudySubmodule deleted.',
179
                'deleted' => $deleted,
180
            ]);
181
        }
182
183
        return redirect()->back()->with('message', 'EnrollmentStudySubmodule deleted.');
184
    }
185
}
186

src/Http/Controllers/CyclesController.php 1 location

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

src/Http/Controllers/FamiliesController.php 1 location

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

src/Http/Controllers/ModulesController.php 1 location

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

src/Http/Controllers/SubmodulesController.php 1 location

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

src/Http/Controllers/SubmoduleTypesController.php 1 location

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