|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @author [email protected] |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Jobs\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Entity\PermissionsInterface; |
|
14
|
|
|
use Jobs\Entity\Status; |
|
15
|
|
|
use Jobs\Repository; |
|
16
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
17
|
|
|
use Zend\View\Model\ViewModel; |
|
18
|
|
|
use Zend\View\Model\JsonModel; |
|
19
|
|
|
use Zend\Stdlib\AbstractOptions; |
|
20
|
|
|
use Zend\Http\PhpEnvironment\Response; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Handles rendering the job in formular and in preview mode |
|
24
|
|
|
* |
|
25
|
|
|
* Class TemplateController |
|
26
|
|
|
* @package Jobs\Controller |
|
27
|
|
|
*/ |
|
28
|
|
|
class TemplateController extends AbstractActionController |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Repository\Job $jobRepository |
|
33
|
|
|
*/ |
|
34
|
|
|
private $jobRepository; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var AbstractOptions |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $config; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct(Repository\Job $jobRepository, AbstractOptions $config) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->jobRepository = $jobRepository; |
|
44
|
|
|
$this->config = $config; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Handles the job opening template in preview mode |
|
49
|
|
|
* |
|
50
|
|
|
* @return ViewModel |
|
51
|
|
|
* @throws \RuntimeException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function viewAction() |
|
54
|
|
|
{ |
|
55
|
|
|
$id = $this->params()->fromQuery('id'); |
|
56
|
|
|
/* @var \Jobs\Entity\Job $job */ |
|
57
|
|
|
$job = $this->jobRepository->find($id); |
|
58
|
|
|
$services = $this->getServiceLocator(); |
|
59
|
|
|
$mvcEvent = $this->getEvent(); |
|
60
|
|
|
$applicationViewModel = $mvcEvent->getViewModel(); |
|
61
|
|
|
|
|
62
|
|
|
/* @var \Auth\Entity\User $user */ |
|
63
|
|
|
$user = $this->auth()->getUser(); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/* @var \Zend\View\Model\ViewModel $model */ |
|
66
|
|
|
$model = $services->get('Jobs/viewModelTemplateFilter')->__invoke($job); |
|
67
|
|
|
|
|
68
|
|
|
if ( false &&( |
|
69
|
|
|
Status::ACTIVE == $job->getStatus() or |
|
|
|
|
|
|
70
|
|
|
$job->getPermissions()->isGranted($user, PermissionsInterface::PERMISSION_VIEW) or |
|
|
|
|
|
|
71
|
|
|
$this->auth()->isAdmin() |
|
|
|
|
|
|
72
|
|
|
)) { |
|
73
|
|
|
$applicationViewModel->setTemplate('iframe/iFrameInjection'); |
|
74
|
|
|
}elseif(Status::EXPIRED == $job->getStatus() or Status::INACTIVE == $job->getStatus()) { |
|
|
|
|
|
|
75
|
|
|
$this->response->setStatusCode(Response::STATUS_CODE_410); |
|
|
|
|
|
|
76
|
|
|
$model->setTemplate('jobs/error/expired'); |
|
77
|
|
|
$model->setVariables( |
|
78
|
|
|
[ |
|
79
|
|
|
'job'=>$job, |
|
80
|
|
|
'message', 'the job posting you were trying to open, was inactivated or has expired' |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
} else { |
|
84
|
|
|
// there is a special handling for 404 in ZF2 |
|
85
|
|
|
$this->response->setStatusCode(Response::STATUS_CODE_404); |
|
|
|
|
|
|
86
|
|
|
$model->setVariable('message', 'job is not available'); |
|
87
|
|
|
} |
|
88
|
|
|
return $model; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Handles the job opening template in formular mode. |
|
93
|
|
|
* |
|
94
|
|
|
* All template forms are sending the ID of a job posting and an identifier of the sending |
|
95
|
|
|
* form. |
|
96
|
|
|
* |
|
97
|
|
|
* @return ViewModel |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function editTemplateAction() |
|
100
|
|
|
{ |
|
101
|
|
|
$id = $this->params('id'); |
|
102
|
|
|
$formIdentifier=$this->params()->fromQuery('form'); |
|
103
|
|
|
$job = $this->jobRepository->find($id); |
|
104
|
|
|
|
|
105
|
|
|
/** @var \Zend\Http\Request $request */ |
|
106
|
|
|
$request = $this->getRequest(); |
|
107
|
|
|
$isAjax = $request->isXmlHttpRequest(); |
|
108
|
|
|
$services = $this->getServiceLocator(); |
|
109
|
|
|
$viewHelperManager = $services->get('ViewHelperManager'); |
|
110
|
|
|
$mvcEvent = $this->getEvent(); |
|
111
|
|
|
$applicationViewModel = $mvcEvent->getViewModel(); |
|
112
|
|
|
$forms = $services->get('FormElementManager'); |
|
113
|
|
|
|
|
114
|
|
|
/** @var \Jobs\Form\JobDescriptionTemplate $formTemplate */ |
|
115
|
|
|
$formTemplate = $forms->get( |
|
116
|
|
|
'Jobs/Description/Template', |
|
117
|
|
|
array( |
|
118
|
|
|
'mode' => $job->id ? 'edit' : 'new' |
|
119
|
|
|
) |
|
120
|
|
|
); |
|
121
|
|
|
|
|
122
|
|
|
$formTemplate->setParam('id', $job->id); |
|
123
|
|
|
$formTemplate->setParam('applyId', $job->applyId); |
|
124
|
|
|
|
|
125
|
|
|
$formTemplate->setEntity($job); |
|
126
|
|
|
|
|
127
|
|
|
if (isset($formIdentifier) && $request->isPost()) { |
|
128
|
|
|
// at this point the form get instantiated and immediately accumulated |
|
129
|
|
|
|
|
130
|
|
|
$instanceForm = $formTemplate->get($formIdentifier); |
|
131
|
|
|
if (!isset($instanceForm)) { |
|
132
|
|
|
throw new \RuntimeException('No form found for "' . $formIdentifier . '"'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
// the id is part of the postData, but it never should be altered |
|
136
|
|
|
$postData = $request->getPost(); |
|
137
|
|
|
|
|
138
|
|
|
unset($postData['id']); |
|
139
|
|
|
unset($postData['applyId']); |
|
140
|
|
|
|
|
141
|
|
|
$instanceForm->setData($postData); |
|
142
|
|
|
if ($instanceForm->isValid()) { |
|
143
|
|
|
$this->getServiceLocator()->get('repositories')->persist($job); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
$model = $services->get('Jobs/ViewModelTemplateFilter')->__invoke($formTemplate); |
|
148
|
|
|
|
|
149
|
|
|
if (!$isAjax) { |
|
150
|
|
|
$basePath = $viewHelperManager->get('basepath'); |
|
151
|
|
|
$headScript = $viewHelperManager->get('headscript'); |
|
152
|
|
|
$headScript->appendFile($basePath->__invoke('/Core/js/core.forms.js')); |
|
153
|
|
|
} else { |
|
154
|
|
|
return new JsonModel(array('valid' => true)); |
|
155
|
|
|
} |
|
156
|
|
|
$applicationViewModel->setTemplate('iframe/iFrameInjection'); |
|
157
|
|
|
return $model; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: