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() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
parent::attachDefaultListeners(); |
68
|
|
|
|
69
|
|
|
$serviceLocator = $this->getServiceLocator(); |
70
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
71
|
|
|
$events = $this->getEventManager(); |
72
|
|
|
$events->attach($defaultServices); |
|
|
|
|
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return ViewModel |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function listOpenJobsAction() |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
|
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.