Completed
Push — develop ( c09155...432462 )
by
unknown
16:18
created

OrganizationSelect::setHeadscripts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
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;
12
13
use Core\Form\HeadscriptProviderInterface;
14
use Doctrine\MongoDB\Cursor;
15
use Zend\Form\Element\Select;
16
17
/**
18
 * Select element to select an organization.
19
 *
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @since  0.23
22
 */
23
class OrganizationSelect extends Select implements HeadscriptProviderInterface
24
{
25
26
    protected $scripts = ['Jobs/js/form.organization-select.js'];
27
28
    public function setHeadscripts(array $scripts)
29
    {
30
        $this->scripts = $scripts;
31
32
        return $this;
33
    }
34
35
    public function getHeadscripts()
36
    {
37
        return $this->scripts;
38
    }
39
40
    public function init()
41
    {
42
        $this->setAttributes(['data-autoinit' => 'false', 'data-element' => 'organization-select']);
43
    }
44
45
46
    /**
47
     * Sets the selectable organizations.
48
     *
49
     * @param Cursor|array $organizations
50
     * @param bool         $addEmptyOption If true, an empty option is created as the first value option.
51
     *
52
     * @return self
53
     */
54
    public function setSelectableOrganizations($organizations, $addEmptyOption = true)
55
    {
56
        $options = $addEmptyOption ? ['0' => ''] : [];
57
58
        foreach ($organizations as $org) {
59
            /* @var $org \Organizations\Entity\Organization */
60
61
            $name     = $org->getOrganizationName()->getName();
62
            $contact  = $org->getContact();
63
            $image    = $org->getImage();
64
            $imageUrl = $image ? $image->getUri() : '';
65
66
            $options[$org->getId()] = $name . '|'
67
                                      . $contact->getCity() . '|'
68
                                      . $contact->getStreet() . '|'
69
                                      . $contact->getHouseNumber() . '|'
70
                                      . $imageUrl;
71
        }
72
73
        return $this->setValueOptions($options);
74
    }
75
}