Completed
Push — master ( ee94bf...c321ed )
by Mohamed
07:15
created

getValueAsString()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 7
nc 1
nop 0
crap 6
1
<?php
2
3
/**
4
 * @author  Mohamed Alsharaf <[email protected]>
5
 */
6
class EditableFieldCheckboxGroupExtension extends DataExtension
7
{
8
    /**
9
     * Get field value that is suitable for the view template file.
10
     *
11
     * @return ArrayList
12
     */
13
    public function getViewValue()
14
    {
15
        $values = explode(',', $this->owner->Value);
16
        $value = new ArrayList();
17
18
        array_walk($values, function ($item) use ($value) {
19
            $value->push(['name' => $item]);
20
        });
21
22
        return $value;
23
    }
24
25
    /**
26
     * Get string value of a field.
27
     *
28
     * @return null|string
29
     */
30
    public function getValueAsString()
31
    {
32
        $return = '';
33
34
        $this->getViewValue()->each(function (ArrayData $item) use (&$return) {
35
            if ($return) {
36
                $return .= ', ';
37
            }
38
            $return .= $item->getField('name');
39
        });
40
41
        return $return;
42
    }
43
}
44