-
Notifications
You must be signed in to change notification settings - Fork 11
/
CourseRegistered.php
81 lines (61 loc) · 1.91 KB
/
CourseRegistered.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CourseRegistered extends Model
{
//
protected $table = 'courses_registered';
protected $fillable = ['student_id', 'semester', 'year', 'courses', 'staff_id'];
public function createNew($data)
{
$existingData = $this->where('student_id', '=', $data['student_id'])
->where('semester', '=' , $data['semester'])
->where('year', '=' , $data['year'])->first();
if ($existingData === null){
$data['courses'] = json_encode($data['courses']);
return $this->create($data);
}
return false;
}
public function deleteRegistration($data)
{
$data['staff_id'] = auth()->id();
return $this->delete($data);
}
public function view(Array $requests)
{
foreach ($requests as $request)
{
$results[] = $this->where('id', $request)->get();
}
return $results;
}
public function viewSelected($data)
{
$results = $this->where('semester', $data['semester'])
->where('year', $data['year'])
->get();
return $results;
}
public function viewSelectedForStudent($data)
{
$results = $this->where('semester', $data['semester'])
->where('year', $data['year'])
->where('student_id', $data['student_id'])
->get();
return $results;
}
public function updateRegistration($data)
{
$data['staff_id'] = auth()->id();
return $this->where('student_id', $data['student_id'])
->where('semester', $data['semester'])
->where('year', $data['year'])
->update(['courses' => $data['courses'],]);
}
public function viewAll()
{
$result = $this->all();
return $result;
}
}