Completed
Push — develop ( 41c7f2...c75883 )
by
unknown
16:43 queued 08:14
created

StatusSelect::getValueOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Jobs\Form\Element;
12
13
use Jobs\Entity\Status;
14
use Zend\Form\Element\Select;
15
16
/**
17
 * ${CARET}
18
 * 
19
 * @author Mathias Gelhausen <[email protected]>
20
 * @todo write test 
21
 */
22
class StatusSelect extends Select
23
{
24
    public function init()
25
    {
26
        $valueOptions = [
27
            Status::ACTIVE => /*@translate*/ 'Active',
28
            Status::INACTIVE => /*@translate*/ 'Inactive',
29
            //Status::WAITING_FOR_APPROVAL => /*@translate*/ 'Waiting for approval',
30
            Status::CREATED => /*@translate*/ 'Created',
31
            Status::PUBLISH => /*@translate*/ 'Published',
32
            Status::REJECTED => /*@translate*/ 'Rejected',
33
            Status::EXPIRED => /*@translate*/ 'Expired',
34
        ];
35
36
        if (true === $this->getOption('include_all_option')) {
37
            $valueOptions = array_merge([
38
                                            'all' => /*@translate*/ 'All',
39
                                         ], $valueOptions );
40
        }
41
42
        $this->setValueOptions($valueOptions);
43
44
        foreach (['data-searchbox' => -1, 'data-allowclear' => 'false', 'class' => 'form-control'] as $attr => $value) {
45
            if (!$this->hasAttribute($attr)) {
46
                $this->setAttribute($attr, $value);
47
            }
48
        }
49
50
        if (null === $this->getName()) {
51
            $this->setName('status');
52
        }
53
54
        if (null === $this->getLabel()) {
55
            $this->setLabel(/*@translate*/ 'Status');
56
        }
57
58
        if (null === $this->getOption('description')) {
59
            $this->setOption('description', /*@translate*/ 'Select a job status.');
60
        }
61
    }
62
63
    public function setOptions($options)
64
    {
65
        parent::setOptions($options);
66
67
        if (null == $this->getLabel()) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->getLabel() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
68
            $this->setLabel('Status');
69
        }
70
71
        if (!isset($this->options['description'])) {
72
            $this->options['description'] = /*@translate*/ 'Select a job status.';
73
        }
74
75
        if (null == $this->getName()) {
76
            $this->setName('status');
77
        }
78
    }
79
80
    public function getValueOptions()
81
    {
82
        $options = parent::getValueOptions();
83
84
        return true === $this->getOption('include_all_option')
85
               ? array_merge([ 'all' => /*@translate*/ 'All' ], $options)
86
               : $options;
87
    }
88
89
90
}