FormContentGlobDelete::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Date;
8
use Illuminate\Database\Eloquent\Collection;
9
10
/**
11
 * Class FormContentGlobDelete. Mass delete content items from passed active record collection
12
 * @package Apps\Model\Admin\Content
13
 */
14
class FormContentGlobDelete extends Model
15
{
16
    /** @var Content[]|Collection */
17
    private $_records;
18
19
    public $data = [];
20
21
    /**
22
     * FormContentGlobDelete constructor. Pass records inside.
23
     * @param Content[]|Collection $records
24
     */
25
    public function __construct($records)
26
    {
27
        $this->_records = $records;
28
        parent::__construct();
29
    }
30
31
    /**
32
     * Construct records into data array to display in view
33
     */
34
    public function before()
35
    {
36
        // set data to display in view
37
        foreach ($this->_records as $row) {
38
            $this->data[] = [
39
                'id' => $row->id,
40
                'title' => $row->getLocaled('title'),
41
                'date' => Date::convertToDatetime($row->created_at, Date::FORMAT_TO_HOUR)
42
            ];
43
        }
44
    }
45
46
    /**
47
     * Delete founded records
48
     */
49
    public function make()
50
    {
51
        foreach ($this->_records as $record) {
52
            $record->delete();
53
        }
54
    }
55
}
56