|
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
|
|
|
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 job postings |
|
78
|
|
|
* |
|
79
|
|
|
* @return ViewModel |
|
80
|
|
|
*/ |
|
81
|
|
|
public function indexAction() |
|
82
|
|
|
{ |
|
83
|
|
|
/* @var $request \Zend\Http\Request */ |
|
84
|
|
|
$request = $this->getRequest(); |
|
85
|
|
|
$params = $request->getQuery(); |
|
86
|
|
|
$jsonFormat = 'json' == $params->get('format'); |
|
87
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
|
88
|
|
|
|
|
89
|
|
|
if (!$jsonFormat && !$request->isXmlHttpRequest()) { |
|
90
|
|
|
$session = new Session('Jobs\Index'); |
|
91
|
|
|
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams'; |
|
92
|
|
|
$sessionParams = $session[$sessionKey]; |
|
93
|
|
|
|
|
94
|
|
|
if ($sessionParams) { |
|
95
|
|
|
foreach ($sessionParams as $key => $value) { |
|
96
|
|
|
$params->set($key, $params->get($key, $value)); |
|
97
|
|
|
} |
|
98
|
|
|
} elseif ($isRecruiter) { |
|
99
|
|
|
$params->set('by', 'me'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$session[$sessionKey] = $params->toArray(); |
|
103
|
|
|
|
|
104
|
|
|
$this->searchForm->bind($params); |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (!isset($params['sort'])) { |
|
109
|
|
|
$params['sort'] = '-date'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$paginator = $this->paginatorservice('Jobs/Job', $params); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
$return = array( |
|
115
|
|
|
'by' => $params->get('by', 'all'), |
|
116
|
|
|
'jobs' => $paginator, |
|
117
|
|
|
'showPendingJobs' => false, |
|
118
|
|
|
); |
|
119
|
|
|
if (isset($this->searchForm)) { |
|
120
|
|
|
$return['filterForm'] = $this->searchForm; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$model = new ViewModel(); |
|
124
|
|
|
$model->setVariables($return); |
|
125
|
|
|
$model->setTemplate('jobs/index/index'); |
|
126
|
|
|
return $model; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Handles the dashboard widget for the jobs module. |
|
131
|
|
|
* |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
|
public function dashboardAction() |
|
135
|
|
|
{ |
|
136
|
|
|
/* @var $request \Zend\Http\Request */ |
|
137
|
|
|
$services = $this->getServiceLocator(); |
|
138
|
|
|
$request = $this->getRequest(); |
|
139
|
|
|
$params = $request->getQuery(); |
|
140
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
|
141
|
|
|
|
|
142
|
|
|
if ($isRecruiter) { |
|
143
|
|
|
$params->set('by', 'me'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$myJobs = $services->get('repositories')->get('Jobs/Job'); |
|
147
|
|
|
$paginator = $this->paginator('Jobs/Job'); |
|
148
|
|
|
|
|
149
|
|
|
return array( |
|
150
|
|
|
'script' => 'jobs/index/dashboard', |
|
151
|
|
|
'type' => $this->params('type'), |
|
152
|
|
|
'myJobs' => $myJobs, |
|
153
|
|
|
'jobs' => $paginator |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Action hook for Job search bar in list filter. |
|
159
|
|
|
* |
|
160
|
|
|
* @return JsonModel |
|
161
|
|
|
*/ |
|
162
|
|
|
public function typeaheadAction() |
|
163
|
|
|
{ |
|
164
|
|
|
/* @var $repository \Jobs\Repository\Job */ |
|
165
|
|
|
$query = $this->params()->fromQuery('q', '*'); |
|
166
|
|
|
$repository = $this->getServiceLocator() |
|
167
|
|
|
->get('repositories') |
|
168
|
|
|
->get('Jobs/Job'); |
|
169
|
|
|
|
|
170
|
|
|
$return = array(); |
|
171
|
|
|
foreach ($repository->getTypeaheadResults($query, $this->auth('id')) as $id => $item) { |
|
|
|
|
|
|
172
|
|
|
$return[] = array( |
|
173
|
|
|
'id' => $id, |
|
174
|
|
|
'title' => $item['title'], |
|
175
|
|
|
'applyId' => $item['applyId'], |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return new JsonModel($return); |
|
180
|
|
|
} |
|
181
|
|
|
} |
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: