1
|
|
|
<?php namespace Anomaly\Streams\Platform\Assignment; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Assignment\Event\AssignmentWasSaved; |
4
|
|
|
use Anomaly\Streams\Platform\Assignment\Event\AssignmentWasUpdated; |
5
|
|
|
use Anomaly\Streams\Platform\Assignment\Event\AssignmentWasCreated; |
6
|
|
|
use Anomaly\Streams\Platform\Assignment\Event\AssignmentWasDeleted; |
7
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\AddAssignmentColumn; |
8
|
|
|
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentInterface; |
9
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\BackupAssignmentData; |
10
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\DropAssignmentColumn; |
11
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\MoveAssignmentColumn; |
12
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\RestoreAssignmentData; |
13
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\UpdateAssignmentColumn; |
14
|
|
|
use Anomaly\Streams\Platform\Assignment\Command\DeleteAssignmentTranslations; |
15
|
|
|
use Anomaly\Streams\Platform\Support\Observer; |
16
|
|
|
|
17
|
|
|
class AssignmentObserver extends Observer |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Fired before creating an assignment. |
22
|
|
|
* |
23
|
|
|
* @param AssignmentInterface|AssignmentModel $model |
24
|
|
|
*/ |
25
|
|
|
public function creating(AssignmentInterface $model) |
26
|
|
|
{ |
27
|
|
|
$model->sort_order = $model->newQuery()->count('id') + 1; |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Run after a record is created. |
32
|
|
|
* |
33
|
|
|
* @param AssignmentInterface $model |
34
|
|
|
*/ |
35
|
|
|
public function created(AssignmentInterface $model) |
36
|
|
|
{ |
37
|
|
|
$model->flushCache(); |
38
|
|
|
$model->compileStream(); |
39
|
|
|
|
40
|
|
|
$this->dispatch(new AddAssignmentColumn($model)); |
41
|
|
|
|
42
|
|
|
$this->events->fire(new AssignmentWasCreated($model)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Run before a record is updated. |
47
|
|
|
* |
48
|
|
|
* @param AssignmentInterface $model |
49
|
|
|
*/ |
50
|
|
|
public function updating(AssignmentInterface $model) |
51
|
|
|
{ |
52
|
|
|
$this->dispatch(new BackupAssignmentData($model)); |
53
|
|
|
$this->dispatch(new MoveAssignmentColumn($model)); |
54
|
|
|
$this->dispatch(new RestoreAssignmentData($model)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Run after a record is updated. |
59
|
|
|
* |
60
|
|
|
* @param AssignmentInterface $model |
61
|
|
|
*/ |
62
|
|
|
public function updated(AssignmentInterface $model) |
63
|
|
|
{ |
64
|
|
|
$model->flushCache(); |
65
|
|
|
$model->compileStream(); |
66
|
|
|
|
67
|
|
|
$this->dispatch(new UpdateAssignmentColumn($model)); |
68
|
|
|
|
69
|
|
|
$this->events->fire(new AssignmentWasUpdated($model)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Run after saving a record. |
74
|
|
|
* |
75
|
|
|
* @param AssignmentInterface $model |
76
|
|
|
*/ |
77
|
|
|
public function saved(AssignmentInterface $model) |
78
|
|
|
{ |
79
|
|
|
$model->flushCache(); |
80
|
|
|
$model->compileStream(); |
81
|
|
|
|
82
|
|
|
$this->events->fire(new AssignmentWasSaved($model)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Run after a record has been deleted. |
87
|
|
|
* |
88
|
|
|
* @param AssignmentInterface $model |
89
|
|
|
*/ |
90
|
|
|
public function deleted(AssignmentInterface $model) |
91
|
|
|
{ |
92
|
|
|
$model->flushCache(); |
93
|
|
|
$model->compileStream(); |
94
|
|
|
|
95
|
|
|
$this->dispatch(new DropAssignmentColumn($model)); |
96
|
|
|
$this->dispatch(new DeleteAssignmentTranslations($model)); |
97
|
|
|
|
98
|
|
|
$this->events->fire(new AssignmentWasDeleted($model)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: