|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
class Institution_shift extends Base_Model { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The database table used by the model. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $table = 'institution_shifts'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Attributes that should be mass-assignable. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $fillable = ['start_time', 'end_time', 'academic_period_id', 'institution_id', 'location_institution_id', 'shift_option_id', 'previous_shift_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes excluded from the model's JSON form. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $hidden = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The attributes that should be casted to native types. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $casts = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The attributes that should be mutated to dates. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $dates = ['modified', 'created']; |
|
43
|
|
|
|
|
44
|
|
|
public function shiftExists($shift){ |
|
45
|
|
|
return self::query() |
|
46
|
|
|
->where('institution_id',$shift['institution_id']) |
|
47
|
|
|
->where('location_institution_id',$shift['location_institution_id']) |
|
48
|
|
|
->where('shift_option_id',$shift['shift_option_id']) |
|
49
|
|
|
->where('academic_period_id',$shift['academic_period_id'])->exists(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getShift($shift){ |
|
53
|
|
|
return self::query() |
|
54
|
|
|
->where('institution_id',$shift['institution_id']) |
|
55
|
|
|
->where('location_institution_id',$shift['location_institution_id']) |
|
56
|
|
|
->where('shift_option_id',$shift['shift_option_id']) |
|
57
|
|
|
->where('academic_period_id',$shift['academic_period_id'])->first(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getShiftsToClone(string $year,$limit,$mode){ |
|
61
|
|
|
return self::query() |
|
62
|
|
|
->select('institution_shifts.*') |
|
63
|
|
|
->join('academic_periods','academic_periods.id','=','institution_shifts.academic_period_id') |
|
64
|
|
|
->where('academic_periods.code',$year) |
|
65
|
|
|
->whereNotIn('institution_shifts.cloned',[ !$mode ? '2020' : '2018/2019']) |
|
66
|
|
|
->groupBy('institution_shifts.id') |
|
67
|
|
|
->limit($limit) |
|
68
|
|
|
->get() |
|
69
|
|
|
->toArray(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getShiftsTodelete(string $year,$academic_period_id){ |
|
73
|
|
|
return self::query() |
|
74
|
|
|
// ->select('institution_shifts.*','academic_periods.academic_period_id') |
|
75
|
|
|
->join('academic_periods','academic_periods.id','=','institution_shifts.academic_period_id') |
|
76
|
|
|
->where('academic_period_id',$academic_period_id) |
|
77
|
|
|
->where('institution_shifts.cloned',$year) |
|
78
|
|
|
->get()->toArray(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|