|
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 Core\Form\SearchForm; |
|
14
|
|
|
use Jobs\Form\ListFilter; |
|
15
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
16
|
|
|
use Zend\Session\Container as Session; |
|
17
|
|
|
use Jobs\Repository; |
|
18
|
|
|
use Zend\View\Model\ViewModel; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method \Auth\Controller\Plugin\Auth auth() |
|
22
|
|
|
* @method \Core\Controller\Plugin\CreatePaginatorService paginatorService() |
|
23
|
|
|
* |
|
24
|
|
|
* Controller for jobboard actions |
|
25
|
|
|
*/ |
|
26
|
|
|
class JobboardController extends AbstractActionController |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Repository\Job $jobRepository |
|
30
|
|
|
*/ |
|
31
|
|
|
private $jobRepository; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
private $options = [ |
|
37
|
|
|
'count' => 10 |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Construct the jobboard controller |
|
42
|
|
|
* |
|
43
|
|
|
* @param Repository\Job $jobRepository |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(Repository\Job $jobRepository, $options) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->jobRepository = $jobRepository; |
|
48
|
|
|
$this->options = $options; |
|
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->serviceLocator; |
|
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
|
|
|
/* @todo: move this into a listener. |
|
72
|
|
|
* |
|
73
|
|
|
* The following lines allow to override get param[q] with the |
|
74
|
|
|
* param from route. This feature is needed for a landing-page feature, where |
|
75
|
|
|
* human readable urls like http://yawik.org/demo/de/jobs/sales.html |
|
76
|
|
|
* |
|
77
|
|
|
* move the Logic into a Listener, which can be activated, if needed |
|
78
|
|
|
*/ |
|
79
|
|
|
$request = $this->getRequest(); |
|
80
|
|
|
$getParams = $request->getQuery(); |
|
81
|
|
|
$routeParams = $this->params()->fromRoute(); |
|
82
|
|
|
if (isset($routeParams['q']) && !isset($getParams['q'])){ |
|
83
|
|
|
$getParams['q']=$routeParams['q']; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$result = $this->pagination([ |
|
|
|
|
|
|
87
|
|
|
'params' => ['Jobs_Board', [ |
|
88
|
|
|
'q', |
|
89
|
|
|
'count' => $this->options['count'], |
|
90
|
|
|
'page' => 1, |
|
91
|
|
|
'l', |
|
92
|
|
|
'd' => 10] |
|
93
|
|
|
], |
|
94
|
|
|
'form' => ['as' => 'filterForm', 'Jobs/JobboardSearch'], |
|
95
|
|
|
'paginator' => ['as' => 'jobs', 'Jobs/Board'] |
|
96
|
|
|
]); |
|
97
|
|
|
|
|
98
|
|
|
$params['by'] = "guest"; |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$organizationImageCache = $this->serviceLocator->get('Organizations\ImageFileCache\Manager'); |
|
101
|
|
|
|
|
102
|
|
|
$result['organizationImageCache'] = $organizationImageCache; |
|
103
|
|
|
|
|
104
|
|
|
return $result; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
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.