|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 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() |
|
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->serviceLocator; |
|
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
|
|
|
$queryParams = $request->getQuery(); |
|
86
|
|
|
$params = $queryParams->get('params', []); |
|
87
|
|
|
$jsonFormat = 'json' == $queryParams->get('format'); |
|
88
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
|
89
|
|
|
|
|
90
|
|
|
if (!$jsonFormat && !$request->isXmlHttpRequest()) { |
|
91
|
|
|
$session = new Session('Jobs\Index'); |
|
92
|
|
|
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams'; |
|
93
|
|
|
$sessionParams = $session[$sessionKey]; |
|
94
|
|
|
|
|
95
|
|
|
if ($sessionParams) { |
|
96
|
|
|
$params = array_merge($sessionParams, $params); |
|
97
|
|
|
} elseif ($isRecruiter) { |
|
98
|
|
|
$params['by'] = 'me'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$session[$sessionKey] = $params; |
|
102
|
|
|
$queryParams->set('params', $params); |
|
103
|
|
|
|
|
104
|
|
|
$this->searchForm->bind($queryParams); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if (!isset($params['sort'])) { |
|
108
|
|
|
$params['sort'] = '-date'; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$paginator = $this->paginator('Jobs/Job', $params); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
$return = [ |
|
114
|
|
|
'by' => $queryParams->get('by', 'all'), |
|
115
|
|
|
'jobs' => $paginator, |
|
116
|
|
|
]; |
|
117
|
|
|
if (isset($this->searchForm)) { |
|
118
|
|
|
$return['filterForm'] = $this->searchForm; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$model = new ViewModel(); |
|
122
|
|
|
$model->setVariables($return); |
|
123
|
|
|
$model->setTemplate('jobs/index/index'); |
|
124
|
|
|
return $model; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Handles the dashboard widget for the jobs module. |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
public function dashboardAction() |
|
133
|
|
|
{ |
|
134
|
|
|
/* @var $request \Zend\Http\Request */ |
|
135
|
|
|
$request = $this->getRequest(); |
|
136
|
|
|
$params = $request->getQuery(); |
|
137
|
|
|
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER); |
|
138
|
|
|
|
|
139
|
|
|
if ($isRecruiter) { |
|
140
|
|
|
$params->set('by', 'me'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$paginator = $this->paginator('Jobs/Job'); |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
return [ |
|
146
|
|
|
'script' => 'jobs/index/dashboard', |
|
147
|
|
|
'type' => $this->params('type'), |
|
148
|
|
|
'myJobs' => $this->jobRepository, |
|
149
|
|
|
'jobs' => $paginator |
|
150
|
|
|
]; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
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.