1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace crocodicstudio\crudbooster\Modules\LogsModule\Listeners; |
4
|
|
|
|
5
|
|
|
use crocodicstudio\crudbooster\CBCoreModule\CbUser; |
6
|
|
|
use crocodicstudio\crudbooster\Modules\LogsModule\LogsRepository; |
7
|
|
|
|
8
|
|
|
class CRUD |
9
|
|
|
{ |
10
|
|
|
public static function registerListeners() |
11
|
|
|
{ |
12
|
|
|
self::delete(); |
13
|
|
|
self::update(); |
14
|
|
|
self::create(); |
15
|
|
|
self::deleteImage(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
private static function delete() |
19
|
|
|
{ |
20
|
|
|
Event::listen('cb.dataDeleted', function (string $table, array $ids, string $time, CbUser $user) { |
|
|
|
|
21
|
|
|
$ids = implode(', ', $ids); |
22
|
|
|
self::insertLog("Data deleted from $table table with Ids: $ids at $time", $user->id); |
23
|
|
|
}); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private static function insertLog($description, $userId = null) |
27
|
|
|
{ |
28
|
|
|
LogsRepository::insertLog('crudbooster: '.$description, $userId ?: auth('cbAdmin')->id()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private static function create() |
32
|
|
|
{ |
33
|
|
|
Event::listen('cb.dataInserted', function (string $table, int $id, string $time, CbUser $user) { |
34
|
|
|
self::insertLog("Data inserted into $table table with Id: $id at $time", $user->id); |
35
|
|
|
}); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private static function update() |
39
|
|
|
{ |
40
|
|
|
Event::listen('cb.dataUpdated', function (string $table, int $id, string $time, CbUser $user) { |
41
|
|
|
self::insertLog("Data updated within $table table with Id: $id at $time", $user->id); |
42
|
|
|
}); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private static function deleteImage() |
46
|
|
|
{ |
47
|
|
|
Event::listen('cb.imageDeleted', function (string $table, array $prop, string $time, CbUser $user) { |
48
|
|
|
$file = $prop['file']; |
49
|
|
|
$id = $prop['id']; |
50
|
|
|
self::insertLog("($file) Image deleted from $table table with Id: $id at $time", $user->id); |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
} |