Completed
Push — develop ( 1b162b...714124 )
by
unknown
16:38 queued 08:10
created

HiringOrganizationSelectFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createService() 0 25 3
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