Completed
Push — develop ( 1b162b...714124 )
by
unknown
08:09
created

HiringOrganizationSelectFactory::createService()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 25
rs 8.8571
cc 3
eloc 13
nc 3
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\Factory\Form;
12
13
use Jobs\Form\HiringOrganizationSelect;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * Factory for the HiringOrganization select box
19
 *
20
 * @author Mathias Gelhausen <[email protected]>
21
 */
22
class HiringOrganizationSelectFactory implements FactoryInterface
23
{
24
    /**
25
     * Creates the hiring organization select box.
26
     *
27
     */
28
    public function createService(ServiceLocatorInterface $serviceLocator)
29
    {
30
        /* @var $serviceLocator \Zend\ServiceManager\AbstractPluginManager
31
         * @var $headscript     \Zend\View\Helper\HeadScript
32
         * @var $user           \Auth\Entity\User
33
         * @var $organization   \Organizations\Entity\OrganizationInterface | \Organizations\Entity\OrganizationReferenceInterface
34
         */
35
        $services     = $serviceLocator->getServiceLocator();
36
        $user         = $services->get('AuthenticationService')->getUser();
37
        $select       = new HiringOrganizationSelect();
38
        $organizationReference = $user->getOrganization();
39
40
        if ($organizationReference->hasAssociation()) {
41
            $organizations = $organizationReference->getHiringOrganizations()->toArray();
42
            $organization = $organizationReference->getOrganization();
43
            if (!$organization->isDraft()) {
44
    			array_unshift($organizations, $organization);
45
            }
46
            $select->setSelectableOrganizations($organizations, /* addEmptyOption */
47
                                                false
48
            );
49
        }
50
51
        return $select;
52
    }
53
}
54