Completed
Push — develop ( 8cb156...27be84 )
by
unknown
17:07
created

JobSelect::setHeadscripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Applications\Form\Element;
12
13
use Core\Form\HeadscriptProviderInterface;
14
use Jobs\Entity\JobInterface;
15
use Zend\Form\Element\Select;
16
17
/**
18
 * Select element for job titles
19
 * 
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @since 0.29.2
22
 */
23
class JobSelect extends Select implements HeadscriptProviderInterface
24
{
25
    private $scripts = [ 'Applications/js/form.job-select.js' ];
26
27
    /**
28
     * Sets the array of script names.
29
     *
30
     * @param string[] $scripts
31
     *
32
     * @return self
33
     */
34
    public function setHeadscripts(array $scripts)
35
    {
36
        $this->scripts = $scripts;
37
38
        return $this;
39
    }
40
41
    /**
42
     * Gets the array of script names.
43
     *
44
     * @return string[]
45
     */
46
    public function getHeadscripts()
47
    {
48
        return $this->scripts;
49
    }
50
51
    /**
52
     * Set the pre selected job.
53
     *
54
     * @param JobInterface $job
55
     *
56
     * @return self
57
     */
58
    public function setSelectedJob(JobInterface $job)
59
    {
60
        $this->setValueOptions([
61
            '0' => '',
62
            $job->getId() => $job->getTitle(),
63
        ]);
64
65
        $this->setValue($job->getId());
66
67
        return $this;
68
    }
69
70
    public function init()
71
    {
72
        $this->setAttribute('data-element', 'job-select');
73
74
        if (!count($this->getValueOptions())) {
75
            $this->setValueOptions(['0' => '']);
76
        }
77
    }
78
}