FormIgnoreDelete::labels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Apps\Model\Front\Profile;
4
5
use Apps\ActiveRecord\Blacklist;
6
use Ffcms\Core\Arch\Model;
7
use Ffcms\Core\Interfaces\iUser;
8
9
/**
10
 * Class FormIgnoreDelete. Business logic of delete ignored user for current users object from database
11
 * @package Apps\Model\Front\Profile
12
 */
13
class FormIgnoreDelete extends Model
14
{
15
    public $id;
16
17
    private $_user;
18
    private $_target_id;
19
20
    /**
21
     * FormIgnoreDelete constructor. Pass current user object and target user id inside
22
     * @param iUser $user
23
     * @param int $target_id
24
     */
25
    public function __construct(iUser $user, $target_id)
26
    {
27
        $this->_user = $user;
28
        $this->_target_id = $target_id;
29
        parent::__construct(true);
30
    }
31
32
    /**
33
     * Set public display data
34
     */
35
    public function before()
36
    {
37
        $this->id = $this->_target_id;
38
    }
39
40
    /**
41
     * Display labels in form
42
     * @return array
43
     */
44
    public function labels(): array
45
    {
46
        return [
47
            'id' => __('User ID'),
48
            'name' => __('Nickname')
49
        ];
50
    }
51
52
    /**
53
     * Form submit action - delete user from database
54
     * @throws \Exception
55
     */
56
    public function make()
57
    {
58
        Blacklist::where('user_id', '=', $this->_user->getId())
59
            ->where('target_id', '=', $this->_target_id)
60
            ->delete();
61
    }
62
}
63