1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @filesource |
6
|
|
|
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de) |
7
|
|
|
* @author [email protected] |
8
|
|
|
* @license MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Jobs\Controller; |
12
|
|
|
|
13
|
|
|
use Jobs\Form\JobDescriptionTemplate; |
14
|
|
|
use Jobs\Repository; |
15
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
16
|
|
|
use Zend\View\Model\ViewModel; |
17
|
|
|
use Zend\View\Model\JsonModel; |
18
|
|
|
use Zend\Stdlib\AbstractOptions; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Handles rendering the job in formular and in preview mode |
22
|
|
|
* |
23
|
|
|
* Class TemplateController |
24
|
|
|
* @package Jobs\Controller |
25
|
|
|
*/ |
26
|
|
|
class TemplateController extends AbstractActionController |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Repository\Job $jobRepository |
31
|
|
|
*/ |
32
|
|
|
private $jobRepository; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var AbstractOptions |
36
|
|
|
*/ |
37
|
|
|
protected $config; |
38
|
|
|
|
39
|
|
|
public function __construct(Repository\Job $jobRepository, AbstractOptions $config) |
40
|
|
|
{ |
41
|
|
|
$this->jobRepository = $jobRepository; |
42
|
|
|
$this->config = $config; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Handles the job opening template in preview mode |
47
|
|
|
* |
48
|
|
|
* @return ViewModel |
49
|
|
|
* @throws \RuntimeException |
50
|
|
|
*/ |
51
|
|
|
public function viewAction() |
52
|
|
|
{ |
53
|
|
|
$id = $this->params()->fromQuery('id'); |
54
|
|
|
$job = $this->jobRepository->find($id); |
55
|
|
|
$services = $this->getServiceLocator(); |
56
|
|
|
$mvcEvent = $this->getEvent(); |
57
|
|
|
$applicationViewModel = $mvcEvent->getViewModel(); |
58
|
|
|
|
59
|
|
|
$isAdmin=$this->auth()->isAdmin(); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$model = $services->get('Jobs/viewModelTemplateFilter')->__invoke($job); |
62
|
|
|
|
63
|
|
|
# @todo make this working for anonymous users |
|
|
|
|
64
|
|
|
// if ($job->status != 'active' && !$job->getPermissions()->isChangeGranted($this->auth()->getUser()) && ! $isAdmin) { |
65
|
|
|
// $this->response->setStatusCode(404); |
66
|
|
|
// $model->setVariable('message','job is not available'); |
67
|
|
|
// } else { |
68
|
|
|
$applicationViewModel->setTemplate('iframe/iFrameInjection'); |
69
|
|
|
// } |
70
|
|
|
return $model; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Handles the job opening template in formular mode |
75
|
|
|
* |
76
|
|
|
* @return ViewModel |
77
|
|
|
*/ |
78
|
|
|
protected function editTemplateAction() |
79
|
|
|
{ |
80
|
|
|
$id = $this->params('id'); |
81
|
|
|
$formIdentifier=$this->params()->fromQuery('form'); |
82
|
|
|
$job = $this->jobRepository->find($id); |
83
|
|
|
|
84
|
|
|
$request = $this->getRequest(); |
85
|
|
|
$isAjax = $request->isXmlHttpRequest(); |
86
|
|
|
$services = $this->getServiceLocator(); |
87
|
|
|
$viewHelperManager = $services->get('ViewHelperManager'); |
88
|
|
|
$mvcEvent = $this->getEvent(); |
89
|
|
|
$applicationViewModel = $mvcEvent->getViewModel(); |
90
|
|
|
$forms = $services->get('FormElementManager'); |
91
|
|
|
/** @var \Jobs\Form\JobDescriptionTemplate $formTemplate */ |
92
|
|
|
$formTemplate = $forms->get( |
93
|
|
|
'Jobs/Description/Template', |
94
|
|
|
array( |
95
|
|
|
'mode' => $job->id ? 'edit' : 'new' |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$formTemplate->setParam('id', $job->id); |
100
|
|
|
$formTemplate->setParam('applyId', $job->applyId); |
101
|
|
|
$formTemplate->setEntity($job); |
102
|
|
|
|
103
|
|
|
if (isset($formIdentifier) && $request->isPost()) { |
104
|
|
|
// at this point the form get instanciated and immediately accumulated |
105
|
|
|
$instanceForm = $formTemplate->get($formIdentifier); |
106
|
|
|
if (!isset($instanceForm)) { |
107
|
|
|
throw new \RuntimeException('No form found for "' . $formIdentifier . '"'); |
108
|
|
|
} |
109
|
|
|
// the id is part of the postData, but it never should be altered |
110
|
|
|
$postData = $request->getPost(); |
111
|
|
|
unset($postData['id']); |
112
|
|
|
unset($postData['applyId']); |
113
|
|
|
$instanceForm->setData($postData); |
114
|
|
|
if ($instanceForm->isValid()) { |
115
|
|
|
$this->getServiceLocator()->get('repositories')->persist($job); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$model = $services->get('Jobs/viewModelTemplateFilter')->__invoke($formTemplate); |
120
|
|
|
|
121
|
|
|
if (!$isAjax) { |
122
|
|
|
$basePath = $viewHelperManager->get('basepath'); |
123
|
|
|
$headScript = $viewHelperManager->get('headscript'); |
124
|
|
|
$headScript->appendFile($basePath->__invoke('/Core/js/core.forms.js')); |
125
|
|
|
} else { |
126
|
|
|
return new JsonModel(array('valid' => true)); |
127
|
|
|
} |
128
|
|
|
$applicationViewModel->setTemplate('iframe/iFrameInjection'); |
129
|
|
|
return $model; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Gets the organization logo. If no logo exists, take a predefined one |
134
|
|
|
* |
135
|
|
|
* @param \Organizations\Entity\Organization $organization |
136
|
|
|
* @return String |
137
|
|
|
*/ |
138
|
|
|
private function getOrganizationLogo(\Organizations\Entity\Organization $organization) |
139
|
|
|
{ |
140
|
|
|
if (isset($organization) && isset($organization->image) && $organization->image->uri) { |
|
|
|
|
141
|
|
|
return ($organization->image->uri); |
|
|
|
|
142
|
|
|
} else { |
143
|
|
|
/** @var \Zend\ServiceManager\ServiceManager $serviceLocator */ |
144
|
|
|
return $this->config->default_logo; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: