|
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 Jobs\Form\ListFilter; |
|
14
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
15
|
|
|
use Zend\Session\Container as Session; |
|
16
|
|
|
use Jobs\Repository; |
|
17
|
|
|
use Zend\View\Model\ViewModel; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @method \Auth\Controller\Plugin\Auth auth() |
|
21
|
|
|
* @method \Core\Controller\Plugin\CreatePaginatorService paginatorService() |
|
22
|
|
|
* |
|
23
|
|
|
* Controller for jobboard actions |
|
24
|
|
|
*/ |
|
25
|
|
|
class JobboardController extends AbstractActionController |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var Repository\Job $jobRepository |
|
29
|
|
|
*/ |
|
30
|
|
|
private $jobRepository; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Formular for searching job postings |
|
34
|
|
|
* |
|
35
|
|
|
* @var ListFilter $searchForm |
|
36
|
|
|
*/ |
|
37
|
|
|
private $searchForm; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Construct the jobboard controller |
|
41
|
|
|
* |
|
42
|
|
|
* @param Repository\Job $jobRepository |
|
43
|
|
|
* @param ListFilter $searchForm |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(Repository\Job $jobRepository, ListFilter $searchForm) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->jobRepository = $jobRepository; |
|
48
|
|
|
$this->searchForm = $searchForm; |
|
49
|
|
|
} |
|
50
|
|
|
/** |
|
51
|
|
|
* attaches further Listeners for generating / processing the output |
|
52
|
|
|
* @return $this |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function attachDefaultListeners() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
parent::attachDefaultListeners(); |
|
57
|
|
|
$serviceLocator = $this->getServiceLocator(); |
|
58
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
|
59
|
|
|
$events = $this->getEventManager(); |
|
60
|
|
|
$events->attach($defaultServices); |
|
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* List jobs |
|
66
|
|
|
* |
|
67
|
|
|
* @return ViewModel |
|
68
|
|
|
*/ |
|
69
|
|
|
public function indexAction() |
|
70
|
|
|
{ |
|
71
|
|
|
/* @var \Zend\Http\Request $request */ |
|
72
|
|
|
$request = $this->getRequest(); |
|
73
|
|
|
$params = $request->getQuery(); |
|
74
|
|
|
$jsonFormat = 'json' == $request->getQuery()->get('format'); |
|
75
|
|
|
$event = $this->getEvent(); |
|
76
|
|
|
$routeMatch = $event->getRouteMatch(); |
|
77
|
|
|
$matchedRouteName = $routeMatch->getMatchedRouteName(); |
|
78
|
|
|
$url = $this->url()->fromRoute($matchedRouteName, array(), array('force_canonical' => true)); |
|
79
|
|
|
|
|
80
|
|
View Code Duplication |
if (!$jsonFormat && !$request->isXmlHttpRequest()) { |
|
|
|
|
|
|
81
|
|
|
$session = new Session('Jobs\Index'); |
|
82
|
|
|
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams'; |
|
83
|
|
|
$sessionParams = $session[$sessionKey]; |
|
84
|
|
|
if ($sessionParams) { |
|
85
|
|
|
foreach ($sessionParams as $key => $value) { |
|
86
|
|
|
$params->set($key, $params->get($key, $value)); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
$session[$sessionKey] = $params->toArray(); |
|
90
|
|
|
|
|
91
|
|
|
$this->searchForm->bind($params); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$params = $params->get('params', []); |
|
95
|
|
|
|
|
96
|
|
|
if (isset($params['l']['data']) && |
|
97
|
|
|
isset($params['l']['name']) && |
|
98
|
|
|
!empty($params['l']['name'])) { |
|
99
|
|
|
/* @var \Geo\Form\GeoText $geoText */ |
|
100
|
|
|
$geoText = $this->searchForm->get('params')->get('l'); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
$geoText->setValue($params['l']); |
|
103
|
|
|
$params['location'] = $geoText->getValue('entity'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (!isset($params['sort'])) { |
|
107
|
|
|
$params['sort']='-date'; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$this->searchForm->setAttribute('action', $url); |
|
111
|
|
|
|
|
112
|
|
|
$params['by'] = "guest"; |
|
113
|
|
|
|
|
114
|
|
|
$paginator = $this->paginatorService('Jobs/Board', $params); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
$options = $this->searchForm->getOptions(); |
|
117
|
|
|
$options['showButtons'] = false; |
|
118
|
|
|
$this->searchForm->setOptions($options); |
|
119
|
|
|
|
|
120
|
|
|
$return = array( |
|
121
|
|
|
'by' => $params['by'], |
|
122
|
|
|
'jobs' => $paginator, |
|
123
|
|
|
'filterForm' => $this->searchForm |
|
124
|
|
|
); |
|
125
|
|
|
$model = new ViewModel($return); |
|
126
|
|
|
|
|
127
|
|
|
return $model; |
|
128
|
|
|
} |
|
129
|
|
|
} |
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.