Completed
Push — develop ( 60c2a6...7c4b2f )
by Carsten
61:42 queued 47:32
created

ApprovalController::listOpenJobsAction()   C

Complexity

Conditions 9
Paths 28

Size

Total Lines 47
Code Lines 29

Duplication

Lines 47
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 47
loc 47
rs 5.2941
cc 9
eloc 29
nc 28
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @license       MIT
8
 */
9
10
/** ActionController of Jobs */
11
namespace Jobs\Controller;
12
13
use Zend\Mvc\Controller\AbstractActionController;
14
use Zend\Session\Container as Session;
15
use Zend\View\Model\JsonModel;
16
use Auth\Entity\User;
17
use Jobs\Repository;
18
use Jobs\Form\ListFilter;
19
use Zend\View\Model\ViewModel;
20
21
/**
22
 * Handles the job listing for recruiters.
23
 *
24
 * @author Mathias Gelhausen <[email protected]>
25
 * @author Mathias Weitz <[email protected]>
26
 * @author Carsten Bleek <[email protected]>
27
 *
28
 * @method \Auth\Controller\Plugin\Auth auth()
29
 * @method \Acl\Controller\Plugin\Acl acl()
30
 * @method \Core\Controller\Plugin\CreatePaginator paginator(string $repositoryName, array $defaultParams = array(), bool $usePostParams = false)
31
 */
32
class ApprovalController extends AbstractActionController
33
{
34
35
    /**
36
     * @var Repository\Job $jobRepository
37
     */
38
    private $jobRepository;
39
40
    /**
41
     * Formular for searching job postings
42
     *
43
     * @var ListFilter $searchForm
44
     */
45
    private $searchForm;
46
47
48
    /**
49
     * Construct the jobboard controller
50
     *
51
     * @param Repository\Job $jobRepository
52
     * @param ListFilter $searchForm
53
     */
54
    public function __construct(Repository\Job $jobRepository, ListFilter $searchForm)
55
    {
56
        $this->jobRepository = $jobRepository;
57
        $this->searchForm = $searchForm;
58
    }
59
60
    /**
61
     * attaches further Listeners for generating / processing the output
62
     *
63
     * @return $this
64
     */
65 View Code Duplication
    public function attachDefaultListeners()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        parent::attachDefaultListeners();
68
69
        $serviceLocator  = $this->getServiceLocator();
70
        $defaultServices = $serviceLocator->get('DefaultListeners');
71
        $events          = $this->getEventManager();
72
        $events->attach($defaultServices);
0 ignored issues
show
Documentation introduced by
$defaultServices is of type object|array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return ViewModel
79
     */
80 View Code Duplication
    public function listOpenJobsAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        /* @var $request \Zend\Http\Request */
83
        $request     = $this->getRequest();
84
        $params      = $request->getQuery();
85
        $jsonFormat  = 'json' == $params->get('format');
86
        $isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER);
87
88
        if (!$jsonFormat && !$request->isXmlHttpRequest()) {
89
            $session       = new Session('Jobs\Index');
90
            $sessionKey    = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams';
91
            $sessionParams = $session[$sessionKey];
92
93
            if ($sessionParams) {
94
                foreach ($sessionParams as $key => $value) {
95
                    $params->set($key, $params->get($key, $value));
96
                }
97
            } elseif ($isRecruiter) {
98
                $params->set('by', 'me');
99
            }
100
            /* @var $filterForm \Jobs\Form\ListFilter */
101
            $session[$sessionKey] = $params->toArray();
102
103
            $this->searchForm->bind($params);
104
105
        }
106
107
        if (!isset($params['sort'])) {
108
            $params['sort'] = '-date';
109
        }
110
111
        $paginator = $this->paginatorservice('Jobs/Admin', $params);
0 ignored issues
show
Documentation Bug introduced by
The method paginatorservice does not exist on object<Jobs\Controller\ApprovalController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
112
113
        $return = array(
114
            'by'   => $params->get('by', 'all'),
115
            'jobs' => $paginator,
116
            'showPendingJobs' => true,
117
        );
118
        if (isset($this->searchForm)) {
119
            $return['filterForm'] = $this->searchForm;
120
        }
121
122
        $model = new ViewModel();
123
        $model->setVariables($return);
124
        $model->setTemplate('jobs/index/index');
125
        return $model;
126
    }
127
}
128