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 IndexController 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
|
|
|
* Construct the index controller |
49
|
|
|
* |
50
|
|
|
* @param Repository\Job $jobRepository |
51
|
|
|
* @param ListFilter $searchForm |
52
|
|
|
*/ |
53
|
|
|
public function __construct(Repository\Job $jobRepository, ListFilter $searchForm) |
54
|
|
|
{ |
55
|
|
|
$this->jobRepository = $jobRepository; |
56
|
|
|
$this->searchForm = $searchForm; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* attaches further Listeners for generating / processing the output |
61
|
|
|
* |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function attachDefaultListeners() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
parent::attachDefaultListeners(); |
67
|
|
|
|
68
|
|
|
$serviceLocator = $this->getServiceLocator(); |
69
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
70
|
|
|
$events = $this->getEventManager(); |
71
|
|
|
$events->attach($defaultServices); |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* List jobs. |
78
|
|
|
* |
79
|
|
|
* @return array |
|
|
|
|
80
|
|
|
*/ |
81
|
|
|
public function indexAction() |
82
|
|
|
{ |
83
|
|
|
return $this->listJobs(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param bool $showPendingJobs |
|
|
|
|
88
|
|
|
* |
89
|
|
|
* @return ViewModel |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
protected function listJobs() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
/* @var $request \Zend\Http\Request */ |
94
|
|
|
$request = $this->getRequest(); |
95
|
|
|
$params = $request->getQuery(); |
96
|
|
|
$jsonFormat = 'json' == $params->get('format'); |
97
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
98
|
|
|
|
99
|
|
|
if (!$jsonFormat && !$request->isXmlHttpRequest()) { |
100
|
|
|
$session = new Session('Jobs\Index'); |
101
|
|
|
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams'; |
102
|
|
|
$sessionParams = $session[$sessionKey]; |
103
|
|
|
|
104
|
|
|
if ($sessionParams) { |
105
|
|
|
foreach ($sessionParams as $key => $value) { |
106
|
|
|
$params->set($key, $params->get($key, $value)); |
107
|
|
|
} |
108
|
|
|
} elseif ($isRecruiter) { |
109
|
|
|
$params->set('by', 'me'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$session[$sessionKey] = $params->toArray(); |
113
|
|
|
|
114
|
|
|
$this->searchForm->bind($params); |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (!isset($params['sort'])) { |
119
|
|
|
$params['sort'] = '-date'; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$paginator = $this->paginatorservice('Jobs/Job', $params); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$return = array( |
125
|
|
|
'by' => $params->get('by', 'all'), |
126
|
|
|
'jobs' => $paginator, |
127
|
|
|
'showPendingJobs' => false, |
128
|
|
|
); |
129
|
|
|
if (isset($this->searchForm)) { |
130
|
|
|
$return['filterForm'] = $this->searchForm; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$model = new ViewModel(); |
134
|
|
|
$model->setVariables($return); |
135
|
|
|
$model->setTemplate('jobs/index/index'); |
136
|
|
|
return $model; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Handles the dashboard widget for the jobs module. |
141
|
|
|
* |
142
|
|
|
* @return array |
143
|
|
|
*/ |
144
|
|
|
public function dashboardAction() |
145
|
|
|
{ |
146
|
|
|
/* @var $request \Zend\Http\Request */ |
147
|
|
|
$services = $this->getServiceLocator(); |
148
|
|
|
$request = $this->getRequest(); |
149
|
|
|
$params = $request->getQuery(); |
150
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
151
|
|
|
|
152
|
|
|
if ($isRecruiter) { |
153
|
|
|
$params->set('by', 'me'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
$myJobs = $services->get('repositories')->get('Jobs/Job'); |
157
|
|
|
$paginator = $this->paginator('Jobs/Job'); |
158
|
|
|
|
159
|
|
|
return array( |
160
|
|
|
'script' => 'jobs/index/dashboard', |
161
|
|
|
'type' => $this->params('type'), |
162
|
|
|
'myJobs' => $myJobs, |
163
|
|
|
'jobs' => $paginator |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Action hook for Job search bar in list filter. |
169
|
|
|
* |
170
|
|
|
* @return JsonModel |
171
|
|
|
*/ |
172
|
|
|
public function typeaheadAction() |
173
|
|
|
{ |
174
|
|
|
/* @var $repository \Jobs\Repository\Job */ |
175
|
|
|
$query = $this->params()->fromQuery('q', '*'); |
176
|
|
|
$repository = $this->getServiceLocator() |
177
|
|
|
->get('repositories') |
178
|
|
|
->get('Jobs/Job'); |
179
|
|
|
|
180
|
|
|
$return = array(); |
181
|
|
|
foreach ($repository->getTypeaheadResults($query, $this->auth('id')) as $id => $item) { |
|
|
|
|
182
|
|
|
$return[] = array( |
183
|
|
|
'id' => $id, |
184
|
|
|
'title' => $item['title'], |
185
|
|
|
'applyId' => $item['applyId'], |
186
|
|
|
); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
return new JsonModel($return); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
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.