Code Duplication    Length = 176-183 lines in 10 locations

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('enrollment_mobile::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('enrollment_mobile::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('enrollment_mobile::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

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

src/Http/Controllers/FamiliesController.php 1 location

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

src/Http/Controllers/ModulesController.php 1 location

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

src/Http/Controllers/SubmodulesController.php 1 location

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

src/Http/Controllers/SubmoduleTypesController.php 1 location

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

src/Http/Controllers/EnrollmentsController.php 1 location

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

src/Http/Controllers/PeopleController.php 1 location

@@ 15-197 (lines=183) @@
12
use Scool\EnrollmentMobile\Validators\PersonValidator;
13
14
15
class PeopleController extends Controller
16
{
17
18
    /**
19
     * @var PersonRepository
20
     */
21
    protected $repository;
22
23
    /**
24
     * @var PersonValidator
25
     */
26
    protected $validator;
27
28
    public function __construct(PersonRepository $repository, PersonValidator $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
        $people = $this->repository->all();
44
45
        if (request()->wantsJson()) {
46
47
            return response()->json([
48
                'data' => $people,
49
            ]);
50
        }
51
52
        return view('people.index', compact('people'));
53
    }
54
55
    /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @param  PersonCreateRequest $request
59
     *
60
     * @return \Illuminate\Http\Response
61
     */
62
    public function store(PersonCreateRequest $request)
63
    {
64
65
        try {
66
67
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
68
69
            $person = $this->repository->create($request->all());
70
71
            $response = [
72
                'message' => 'Person created.',
73
                'data'    => $person->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
        $person = $this->repository->find($id);
105
106
        if (request()->wantsJson()) {
107
108
            return response()->json([
109
                'data' => $person,
110
            ]);
111
        }
112
113
        return view('people.show', compact('person'));
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
        $person = $this->repository->find($id);
128
129
        return view('people.edit', compact('person'));
130
    }
131
132
133
    /**
134
     * Update the specified resource in storage.
135
     *
136
     * @param  PersonUpdateRequest $request
137
     * @param  string            $id
138
     *
139
     * @return Response
140
     */
141
    public function update(PersonUpdateRequest $request, $id)
142
    {
143
144
        try {
145
146
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
147
148
            $person = $this->repository->update($request->all(), $id);
149
150
            $response = [
151
                'message' => 'Person updated.',
152
                'data'    => $person->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' => 'Person deleted.',
191
                'deleted' => $deleted,
192
            ]);
193
        }
194
195
        return redirect()->back()->with('message', 'Person deleted.');
196
    }
197
}
198