Passed
Push — master ( 13c395...4d9cd3 )
by Josh
04:14
created

Tab::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: joshgulledge
5
 * Date: 10/26/18
6
 * Time: 11:22 AM
7
 */
8
9
namespace LCI\Blend\Helpers\MIGX;
10
11
12
class Tab
13
{
14
    /** @var string */
15
    protected $caption;
16
17
    /** @var array ~ [LCI\Blend\Helpers\MIGX\Field, ... ] */
18
    protected $fields = [];
19
20
    /** @var array  */
21
    protected $custom_properties = [];
22
23
    /**
24
     * Tab constructor.
25
     * @param string $caption
26
     */
27
    public function __construct(string $caption)
28
    {
29
        $this->caption = $caption;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getCaption(): string
36
    {
37
        return $this->caption;
38
    }
39
40
    /**
41
     * @return array ~ [LCI\Blend\Helpers\MIGX\Field, ... ]
42
     */
43
    public function getFields(): array
44
    {
45
        return $this->fields;
46
    }
47
48
    /**
49
     * @param array $columns ~ any existing columns to pass first
50
     * @return array
51
     */
52
    public function getGridColumns($columns=[])
53
    {
54
        $fields = $this->getFields();
55
56
        /** @var Field $field */
57
        foreach ($fields as $field) {
58
            if ($field->isShowInGrid()) {
59
                $columns[] = $field->getGridArray();
60
            }
61
        }
62
63
        return $columns;
64
    }
65
    /**
66
     * @return array
67
     */
68
    public function toArray()
69
    {
70
        $data = [
71
            'caption' => $this->caption,
72
            'fields' => []
73
        ];
74
75
        /** @var Field $field */
76
        foreach ($this->fields as $field) {
77
            $data['fields'][] = $field->toArray();
78
        }
79
80
        return $data;
81
    }
82
83
    /**
84
     * @param string $name
85
     * @return Field
86
     */
87
    public function makeField(string $name)
88
    {
89
        $field = new Field($name);
90
91
        $this->fields[] = $field;
92
93
        return $field;
94
    }
95
96
    /**
97
     * Use if a custom MIGX property is needed that is not defined in this object
98
     * @param string $key
99
     * @param mixed $value
100
     * @return $this
101
     */
102
    public function setCustomProperty($key, $value): self
103
    {
104
        $this->custom_properties[$key] = $value;
105
106
        return $this;
107
    }
108
109
110
}