Passed
Push — master ( d1c6ec...66cfc7 )
by Iman
06:37
created

CRUD::deleteImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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) {
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudboost...sModule\Listeners\Event was not found. Did you mean Event? If so, make sure to prefix the type with \.
Loading history...
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
}