Passed
Push — master ( aaaee4...c2a29b )
by Mihail
04:03
created

FormCommentDelete::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Apps\Model\Admin\Comments;
4
5
use Ffcms\Core\Arch\Model;
6
7
class FormCommentDelete extends Model
8
{
9
    private $_record;
10
    private $_type;
11
   
12
    /**
13
     * FormCommentDelete constructor. Pass active record and type of comment system inside.
14
     * @param object $record
15
     * @param string $type
16
     */
17
    public function __construct($record, $type)
18
    {
19
        $this->_record = $record;
20
        $this->_type = $type;
21
        parent::__construct();
22
    }
23
24
    /**
25
     * Make delete items after submit
26
     */
27
    public function make()
28
    {
29
        // also delete all answers
30
        if ($this->_type === 'comment') {
31
            foreach ($this->_record->get() as $com) {
32
                $com->getAnswer()->delete();
33
            }
34
        }
35
        
36
        $this->_record->delete();
37
    }
38
    
39
    /**
40
     * Get records to delete as object
41
     * @return object
42
     */
43
    public function getRecord()
44
    {
45
        return $this->_record->get();
46
    }
47
}