/** * Handles the job opening template in formular mode * * @return ViewModel */ protected function editTemplateAction() { $id = $this->params('id'); $formIdentifier = $this->params()->fromQuery('form'); $job = $this->jobRepository->find($id); $request = $this->getRequest(); $isAjax = $request->isXmlHttpRequest(); $services = $this->getServiceLocator(); $viewHelperManager = $services->get('ViewHelperManager'); $mvcEvent = $this->getEvent(); $applicationViewModel = $mvcEvent->getViewModel(); $model = new ViewModel(); $forms = $services->get('FormElementManager'); /** @var \Jobs\Form\JobDescriptionTemplate $formTemplate */ $formTemplate = $forms->get('Jobs/Description/Template', array('mode' => $job->id ? 'edit' : 'new')); $formTemplate->setParam('id', $job->id); $formTemplate->setParam('applyId', $job->applyId); $formTemplate->setEntity($job); if (isset($formIdentifier) && $request->isPost()) { // at this point the form get instanciated and immediately accumulated $instanceForm = $formTemplate->get($formIdentifier); if (!isset($instanceForm)) { throw new \RuntimeException('No form found for "' . $formIdentifier . '"'); } // the id is part of the postData, but it never should be altered $postData = $request->getPost(); unset($postData['id']); unset($postData['applyId']); $instanceForm->setData($postData); if ($instanceForm->isValid()) { $this->getServiceLocator()->get('repositories')->persist($job); } } if (!$isAjax) { $basePath = $viewHelperManager->get('basepath'); $headScript = $viewHelperManager->get('headscript'); $headScript->appendFile($basePath->__invoke('/Core/js/core.forms.js')); } else { return new JsonModel(array('valid' => True)); } $model->setTemplate('templates/' . $job->template . '/index'); $applicationViewModel->setTemplate('iframe/iFrameInjection'); $model->setVariables($this->getTemplateFields($job, $formTemplate)); return $model; }
/** * Handles the job opening template in formular mode. * * All template forms are sending the ID of a job posting and an identifier of the sending * form. * * @return ViewModel */ protected function editTemplateAction() { $id = $this->params('id'); $formIdentifier = $this->params()->fromQuery('form'); $job = $this->jobRepository->find($id); $this->acl($job, 'edit'); /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $isAjax = $request->isXmlHttpRequest(); $services = $this->serviceLocator; $viewHelperManager = $services->get('ViewHelperManager'); $mvcEvent = $this->getEvent(); $applicationViewModel = $mvcEvent->getViewModel(); $forms = $services->get('FormElementManager'); /** @var \Jobs\Form\JobDescriptionTemplate $formTemplate */ $formTemplate = $forms->get('Jobs/Description/Template', array('mode' => $job->id ? 'edit' : 'new')); $formTemplate->setParam('id', $job->id); $formTemplate->setParam('applyId', $job->applyId); $formTemplate->setEntity($job); if (isset($formIdentifier) && $request->isPost()) { // at this point the form get instantiated and immediately accumulated $instanceForm = $formTemplate->get($formIdentifier); if (!isset($instanceForm)) { throw new \RuntimeException('No form found for "' . $formIdentifier . '"'); } // the id is part of the postData, but it never should be altered $postData = $request->getPost(); unset($postData['id']); unset($postData['applyId']); $instanceForm->setData($postData); if ($instanceForm->isValid()) { $this->serviceLocator->get('repositories')->persist($job); } } $model = $services->get('Jobs/ViewModelTemplateFilter')->__invoke($formTemplate); if (!$isAjax) { $basePath = $viewHelperManager->get('basepath'); $headScript = $viewHelperManager->get('headscript'); $headScript->appendFile($basePath->__invoke('/Core/js/core.forms.js')); $headStyle = $viewHelperManager->get('headstyle'); $headStyle->prependStyle('form > input { color: inherit !important; margin:inherit !important; padding:inherit !important; border:0 !important; cursor:pointer !important; letter-spacing:inherit !important; line-height: inherit !important; font-size: inherit !important; } '); } else { return new JsonModel(array('valid' => true)); } $applicationViewModel->setTemplate('iframe/iFrameInjection'); return $model; }