1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\Users\Observers; |
4
|
|
|
|
5
|
|
|
use Acacha\Users\Models\UserInvitation; |
6
|
|
|
use Acacha\Users\Services\UserInvitations; |
7
|
|
|
use Venturecraft\Revisionable\Revision; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class UserInvitationObserver. |
11
|
|
|
*/ |
12
|
|
|
class UserInvitationObserver |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public $service; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* UserInvitationObserver constructor. |
19
|
|
|
* |
20
|
|
|
* @param $service |
21
|
|
|
*/ |
22
|
|
|
public function __construct(UserInvitations $service) |
23
|
|
|
{ |
24
|
|
|
$this->service = $service; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Listen to the UserInvitation created event. |
29
|
|
|
* |
30
|
|
|
* @param UserInvitation $invitation |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function created(UserInvitation $invitation) |
34
|
|
|
{ |
35
|
|
|
$this->service->send($invitation); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Listen to the UserInvitation deleting event. |
40
|
|
|
* |
41
|
|
|
* @param UserInvitation $invitation |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function deleting(UserInvitation $invitation) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
// |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Listen to the UserInvitation deleted event. |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function deleted(UserInvitation $invitation) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
// Insert into 'revisions' (calling getTable probably not necessary, but to be safe). |
55
|
|
|
\DB::table((new Revision())->getTable())->insert([ |
56
|
|
|
[ |
57
|
|
|
'revisionable_type' => $invitation->getMorphClass(), |
58
|
|
|
'revisionable_id' => $invitation->id, |
|
|
|
|
59
|
|
|
'key' => 'deleted_at', |
60
|
|
|
'old_value' => null, |
61
|
|
|
'new_value' => new \DateTime(), |
62
|
|
|
'user_id' => (\Auth::check() ? \Auth::user()->id : null), |
63
|
|
|
'created_at' => new \DateTime(), |
64
|
|
|
'updated_at' => new \DateTime(), |
65
|
|
|
] |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.