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 Core */ |
11
|
|
|
namespace Cv\Controller; |
12
|
|
|
|
13
|
|
|
use Cv\Form\SearchForm; |
14
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
15
|
|
|
use Zend\View\Model\ViewModel; |
16
|
|
|
use Zend\Session\Container as Session; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Main Action Controller for the application. |
20
|
|
|
* Responsible for displaying the home site. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
class IndexController extends AbstractActionController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var SearchForm |
27
|
|
|
*/ |
28
|
|
|
protected $searchForm; |
29
|
|
|
|
30
|
|
|
public function __construct(SearchForm $searchForm) |
31
|
|
|
{ |
32
|
|
|
$this->searchForm = $searchForm; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* attaches further Listeners for generating / processing the output |
37
|
|
|
* @return $this |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function attachDefaultListeners() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
parent::attachDefaultListeners(); |
42
|
|
|
$serviceLocator = $this->serviceLocator; |
43
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
44
|
|
|
$events = $this->getEventManager(); |
45
|
|
|
$events->attach($defaultServices); |
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Home site |
51
|
|
|
* |
52
|
|
|
*/ |
53
|
|
|
public function indexAction() |
54
|
|
|
{ |
55
|
|
|
/* @var \Zend\Http\Request $request */ |
56
|
|
|
$request = $this->getRequest(); |
57
|
|
|
$params = $request->getQuery(); |
58
|
|
|
$jsonFormat = 'json' == $request->getQuery()->get('format'); |
59
|
|
|
$event = $this->getEvent(); |
60
|
|
|
$routeMatch = $event->getRouteMatch(); |
61
|
|
|
$matchedRouteName = $routeMatch->getMatchedRouteName(); |
62
|
|
|
$url = $this->url()->fromRoute($matchedRouteName, array(), array('force_canonical' => true)); |
63
|
|
|
|
64
|
|
|
|
65
|
|
View Code Duplication |
if (!$jsonFormat && !$request->isXmlHttpRequest()) { |
|
|
|
|
66
|
|
|
$session = new Session('Cv\Index'); |
67
|
|
|
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams'; |
|
|
|
|
68
|
|
|
$sessionParams = $session[$sessionKey]; |
69
|
|
|
if ($sessionParams) { |
70
|
|
|
foreach ($sessionParams as $key => $value) { |
71
|
|
|
$params->set($key, $params->get($key, $value)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
$session[$sessionKey] = $params->toArray(); |
75
|
|
|
|
76
|
|
|
$this->searchForm->bind($params); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$params = $params->get('params', []); |
80
|
|
|
|
81
|
|
View Code Duplication |
if (isset($params['l']['data']) && |
|
|
|
|
82
|
|
|
isset($params['l']['name']) && |
83
|
|
|
!empty($params['l']['name']) |
84
|
|
|
) { |
85
|
|
|
/* @var \Geo\Form\GeoText $geoText */ |
86
|
|
|
$geoText = $this->searchForm->get('params')->get('l'); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$geoText->setValue($params['l']); |
89
|
|
|
$params['location'] = $geoText->getValue('entity'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
$this->searchForm->setAttribute('action', $url); |
94
|
|
|
$paginator = $this->paginator('Cv/Paginator', $params); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$options = $this->searchForm->getOptions(); |
97
|
|
|
$options['showButtons'] = false; |
98
|
|
|
$this->searchForm->setOptions($options); |
99
|
|
|
|
100
|
|
|
$return = array( |
101
|
|
|
'resumes' => $paginator, |
102
|
|
|
'filterForm' => $this->searchForm |
103
|
|
|
); |
104
|
|
|
$model = new ViewModel($return); |
105
|
|
|
|
106
|
|
|
return $model; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.