Passed
Push — master ( cc7747...d2190f )
by Mihail
10:36
created

FormContentDelete::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Apps\Model\Admin\Content;
4
5
use Apps\ActiveRecord\Content;
6
use Ffcms\Core\Arch\Model;
7
use Ffcms\Core\Helper\Serialize;
8
9
/**
10
 * Class FormContentDelete. Delete content item business logic
11
 * @package Apps\Model\Admin\Content
12
 */
13
class FormContentDelete extends Model
14
{
15
    public $id;
16
    public $title;
17
18
    private $_record;
19
20
    /**
21
     * FormContentDelete constructor. Pass object in model on init
22
     * @param Content $record
23
     */
24
    public function __construct(Content $record)
25
    {
26
        $this->_record = $record;
27
        parent::__construct();
28
    }
29
30
    /**
31
     * Set readable title of content to property
32
     */
33
    public function before()
34
    {
35
        $this->id = $this->_record->id;
36
        $this->title = Serialize::getDecodeLocale($this->_record->title);
37
    }
38
39
    /**
40
     * Form display labels
41
     * @return array
42
     */
43
    public function labels()
44
    {
45
        return [
46
            'title' => __('Title')
47
        ];
48
    }
49
50
    /**
51
     * Make delete
52
     * @throws \Exception
53
     */
54
    public function make()
55
    {
56
        $this->_record->getTags()->delete();
57
        $this->_record->getRating()->delete();
58
        $this->_record->delete();
59
    }
60
}