Passed
Push — master ( ae9760...35700c )
by Andreas
17:19
created

csv::tinymce_widget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace midcom\datamanager\template;
3
4
use Symfony\Component\Form\FormView;
5
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
6
7
class csv extends base
8
{
9
    public function form_rows(FormView $view, array $data)
10
    {
11
        $ret = [];
12
        foreach ($view as $child) {
13
            $ret[] = $this->renderer->widget($child);
14
        }
15
        return implode(', ', array_filter($ret));
16
    }
17
18 2
    public function form_widget_simple(FormView $view, array $data)
19
    {
20 2
        if (   !empty($data['value'])
21 2
            || is_numeric($data['value'])) {
22 2
            return $data['value'];
23
        }
24 2
        return '';
25
    }
26
27
    public function form_widget_compound(FormView $view, array $data)
28
    {
29
        return $this->renderer->block($view, 'form_rows');
30
    }
31
32
    public function attachment_widget(FormView $view, array $data)
33
    {
34
        if (!empty($data['value']['url'])) {
35
            return $data['value']['url'];
36
        }
37
        return '';
38
    }
39
40
    public function radiocheckselect_widget(FormView $view, array $data)
41
    {
42
        $ret = [];
43
        foreach ($view->children as $child) {
44
            if ($child->vars['checked']) {
45
                $ret[] = $this->renderer->humanize($child->vars['label']);
46
            }
47
        }
48
        return implode(', ', $ret);
49
    }
50
51
    public function image_widget(FormView $view, array $data)
52
    {
53
        if (empty($data['value']['objects'])) {
54
            return '';
55
        }
56
        if (array_key_exists('archival', $data['value']['objects'])) {
57
            return $data['value']['objects']['archival']['url'];
58
        }
59
        if (array_key_exists('main', $data['value']['objects'])) {
60
            return $data['value']['objects']['main']['url'];
61
        }
62
        $img = reset($data['value']['objects']);
63
        return $img['url'];
64
    }
65
66 2
    public function autocomplete_widget(FormView $view, array $data)
67
    {
68 2
        return implode(', ', $data['handler_options']['preset']);
69
    }
70
71 2
    public function choice_widget_collapsed(FormView $view, array $data)
72
    {
73 2
        if (isset($data['data'])) {
74 2
            if (!empty($data['multiple'])) {
75
                $selection = $data['data'];
76
            } else {
77 2
                $selection = (string) $data['data'];
78
            }
79 2
            foreach ($data['choices'] as $choice) {
80
                if ($choice instanceof ChoiceGroupView) {
81
                    foreach ($choice->choices as $option) {
82
                        if ($data['is_selected']($option->value, $selection)) {
83
                            return $this->renderer->humanize($option->label);
84
                        }
85
                    }
86
                } elseif ($data['is_selected']($choice->value, $selection)) {
87
                    return $this->renderer->humanize($choice->label);
88
                }
89
            }
90
        }
91 2
        return '';
92
    }
93
94 2
    public function checkbox_widget(FormView $view, $data)
95
    {
96 2
        return ($data['checked']) ? '1' : '0';
97
    }
98
99
    public function tinymce_widget(FormView $view, array $data)
100
    {
101
        return $data['value'];
102
    }
103
104 2
    public function jsdate_widget(FormView $view, array $data)
105
    {
106 2
        if (empty($data['value']['date'])) {
107 2
            return '';
108
        }
109
110 2
        $format = $this->renderer->humanize('short date csv');
111
112 2
        if (isset($view['time'])) {
113 2
            $format .= (isset($data['value']['seconds'])) ? ' H:i' : ' H:i:s';
114
        }
115 2
        return $data['value']['date']->format($format);
116
    }
117
}
118