1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Scool\Timetables\Models; |
4
|
|
|
|
5
|
|
|
use Acacha\Stateful\Contracts\Stateful; |
6
|
|
|
use Acacha\Stateful\Traits\StatefulTrait; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Prettus\Repository\Contracts\Transformable; |
9
|
|
|
use Prettus\Repository\Traits\TransformableTrait; |
10
|
|
|
use Scool\Timetables\Events\LessonCreated; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Lesson |
14
|
|
|
* @package Scool\Timetables\Models |
15
|
|
|
*/ |
16
|
|
|
class Lesson extends Model implements Transformable, Stateful |
17
|
|
|
{ |
18
|
|
|
use TransformableTrait, StatefulTrait; |
19
|
|
|
|
20
|
|
|
protected $fillable = ['id','location_id','day_id','timeslot_id','classroom_id', 'state']; |
21
|
|
|
|
22
|
|
|
protected $events = [ |
23
|
|
|
'created' => LessonCreated::class |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
28
|
|
|
*/ |
29
|
|
|
public function locations() |
30
|
|
|
{ |
31
|
|
|
return $this->belongsTo(\Scool\Timetables\Models\Location::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
36
|
|
|
*/ |
37
|
|
|
public function days() |
38
|
|
|
{ |
39
|
|
|
return $this->belongsTo(\Scool\Timetables\Models\Day::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
44
|
|
|
*/ |
45
|
|
|
public function timeslots() |
46
|
|
|
{ |
47
|
|
|
return $this->belongsTo(\Scool\Timetables\Models\Timeslot::class); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
52
|
|
|
*/ |
53
|
|
|
public function classrooms() |
54
|
|
|
{ |
55
|
|
|
return $this->belongsTo(\Scool\Timetables\Models\Classroom::class); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
60
|
|
|
*/ |
61
|
|
|
public function users() |
62
|
|
|
{ |
63
|
|
|
return $this->belongsToMany(\App\User::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
68
|
|
|
*/ |
69
|
|
|
public function submodules() |
70
|
|
|
{ |
71
|
|
|
return $this->belongsToMany(\Submodule::class); //TODO |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* States. |
76
|
|
|
* |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
protected $states = [ |
80
|
|
|
'step1' => ['initial' => true], |
81
|
|
|
'step2' => ['final' => true] |
82
|
|
|
]; |
83
|
|
|
/** |
84
|
|
|
* Transaction State Transitions |
85
|
|
|
* |
86
|
|
|
* @var array |
87
|
|
|
*/ |
88
|
|
|
protected $transitions = [ |
89
|
|
|
'step1step2' => [ |
90
|
|
|
'from' => 'step1', |
91
|
|
|
'to' => 'step2' |
92
|
|
|
], |
93
|
|
|
'step2step1' => [ |
94
|
|
|
'from' => 'step2', |
95
|
|
|
'to' => 'step1' |
96
|
|
|
] |
97
|
|
|
]; |
98
|
|
|
/** |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
protected function validateStep1step2() |
102
|
|
|
{ |
103
|
|
|
if ($this->location_id != null) { |
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
/** |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
protected function validateStep2step1() |
112
|
|
|
{ |
113
|
|
|
return false; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|