/** * @covers Applications\Entity\Application::getJob * @covers Applications\Entity\Application::setJob */ public function testSetGetJob() { $user = new User(); $user->setId(123); $job = new Job(); $job->setUser($user); $this->target->setJob($job); $this->assertEquals($job, $this->target->getJob()); }
public function preDispatch(MvcEvent $e) { /* @var $application \Applications\Entity\Application */ if ($this->params()->fromQuery('do')) { $e->getRouteMatch()->setParam('action', 'do'); return; } /* @var $request \Zend\Http\Request */ /* @var $repository \Applications\Repository\Application */ /* @var $container \Applications\Form\Apply */ $request = $this->getRequest(); $services = $this->getServiceLocator(); $repositories = $services->get('repositories'); $repository = $repositories->get('Applications/Application'); $container = $services->get('forms')->get('Applications/Apply'); if ($request->isPost()) { $appId = $this->params()->fromPost('applicationId'); if (!$appId) { throw new \RuntimeException('Missing application id.'); } $routeMatch = $e->getRouteMatch(); if ('recruiter-preview' == $appId) { $routeMatch->setParam('action', 'process-preview'); return; } $application = $repository->find($appId); if (!$application) { throw new \RuntimeException('Invalid application id.'); } $action = 'process'; $routeMatch->setParam('action', $action); } else { $user = $this->auth()->getUser(); $appId = $this->params('applyId'); if (!$appId) { throw new \RuntimeException('Missing apply id'); } /* @var \Jobs\Entity\Job $job */ $job = $repositories->get('Jobs/Job')->findOneByApplyId($appId); if ($user === $job->getUser()) { $application = new \Applications\Entity\Application(); $application->setContact(new Contact()); $application->setJob($job); $application->setId('recruiter-preview'); } else { $subscriberUri = $this->params()->fromQuery('subscriber'); $application = $repository->findDraft($user, $appId); if ($application) { /* @var $form \Auth\Form\UserInfo */ $form = $container->getForm('contact.contact'); $form->setDisplayMode('summary'); if ($subscriberUri) { $subscriber = $application->getSubscriber(); if (!$subscriber || $subscriber->uri != $subscriberUri) { $subscriber = $repositories->get('Applications/Subscriber')->findbyUri($subscriberUri, true); $application->setSubscriber($subscriber); $subscriber->getname(); } } } else { if (!$job) { $e->getRouteMatch()->setParam('action', 'job-not-found'); return; } /* @var $application \Applications\Entity\Application */ $application = $repository->create(); $application->setIsDraft(true)->setContact($user->getInfo())->setUser($user)->setJob($job); if ($subscriberUri) { $subscriber = $repositories->get('Applications/Subscriber')->findbyUri($subscriberUri, true); $application->setSubscriber($subscriber); } $repositories->store($application); /* * If we had copy an user image, we need to refresh its data * to populate the length property. */ if ($image = $application->contact->image) { $repositories->refresh($image); } } } } $container->setEntity($application); $this->configureContainer($container); $this->container = $container; }
/** * Processes formular data of the application form * * @return \Zend\View\Model\ViewModel */ public function indexAction() { $services = $this->getServiceLocator(); /** @var Request $request */ $request = $this->getRequest(); $jobId = $this->params()->fromPost('jobId', 0); $applyId = (int) $this->params()->fromPost('applyId', 0); // subscriber comes from the form $subscriberUri = $this->params()->fromPost('subscriberUri', ''); if (empty($subscriberUri)) { // subscriber comes with the request of the form // which implies that the backlink in the job-offer had such an link in the query $subscriberUri = $this->params()->fromQuery('subscriberUri', ''); } if (empty($subscriberUri)) { // the subscriber comes from an external module, maybe after interpreting the backlink, or the referer $e = $this->getEvent(); $subscriberResponseCollection = $this->getEventManager()->trigger('subscriber.getUri', $e); if (!$subscriberResponseCollection->isEmpty()) { $subscriberUri = $subscriberResponseCollection->last(); } } $job = $request->isPost() && !empty($jobId) ? $services->get('repositories')->get('Jobs/Job')->find($jobId) : $services->get('repositories')->get('Jobs/Job')->findOneBy(array("applyId" => 0 == $applyId ? $this->params('jobId') : $applyId)); if (!$job) { $this->response->setStatusCode(410); $model = new ViewModel(array('content' => 'Invalid apply id')); $model->setTemplate('auth/index/job-not-found.phtml'); return $model; } /* @var $form \Zend\Form\Form */ $form = $services->get('FormElementManager')->get('Application/Create'); $form->setValidate(); $viewModel = new ViewModel(); $viewModel->setVariables(array('job' => $job, 'form' => $form, 'isApplicationSaved' => false, 'subscriberUri' => $subscriberUri)); $applicationEntity = new Application(); $applicationEntity->setJob($job); if ($this->auth()->isLoggedIn()) { // copy the contact info into the application $contact = new Info(); $contact->fromArray(Info::toArray($this->auth()->get('info'))); $applicationEntity->setContact($contact); } $form->bind($applicationEntity); $form->get('jobId')->setValue($job->id); $form->get('subscriberUri')->setValue($subscriberUri); if ($request->isPost()) { if ($returnTo = $this->params()->fromPost('returnTo', false)) { $returnTo = \Zend\Uri\UriFactory::factory($returnTo); } $services = $this->getServiceLocator(); $data = array_merge_recursive($this->request->getPost()->toArray(), $this->request->getFiles()->toArray()); if (!empty($subscriberUri) && $request->isPost()) { $subscriber = $services->get('repositories')->get('Applications/Subscriber')->findbyUriOrCreate($subscriberUri); $applicationEntity->subscriber = $subscriber; } $form->setData($data); if (!$form->isValid()) { if ($request->isXmlHttpRequest()) { return new JsonModel(array('ok' => false, 'messages' => $form->getMessages())); } if ($returnTo) { $returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'failure')); return $this->redirect()->toUrl((string) $returnTo); } $this->notification()->error('There were errors in the form.'); } else { $auth = $this->auth(); if ($auth->isLoggedIn()) { // in instance user is logged in, // and no image is uploaded // take his profile-image as copy $applicationEntity->setUser($auth->getUser()); $imageData = $form->get('contact')->get('image')->getValue(); if (UPLOAD_ERR_NO_FILE == $imageData['error']) { // has the user an image $image = $auth->getUser()->info->image; if ($image) { $repositoryAttachment = $services->get('repositories')->get('Applications/Attachment'); // this should provide a real copy, not just a reference $contactImage = $repositoryAttachment->copy($image); $applicationEntity->contact->setImage($contactImage); } else { $applicationEntity->contact->setImage(null); //explicitly remove image. } } } if (!$request->isXmlHttpRequest()) { $applicationEntity->setStatus(new Status()); $permissions = $applicationEntity->getPermissions(); $permissions->inherit($job->getPermissions()); /* * New Application alert Mails to job recruiter * This is temporary until Companies are implemented. */ $recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail); if (!$recruiter) { $recruiter = $job->user; $admin = false; } else { $admin = $job->user; } $services->get('repositories')->store($applicationEntity); /* * New Application alert Mails to job recruiter * This is temporary until Companies are implemented. */ $recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail); if (!$recruiter) { $recruiter = $job->user; $admin = false; } else { $admin = $job->user; } if ($recruiter->getSettings('Applications')->getMailAccess()) { $this->mailer('Applications/NewApplication', array('job' => $job, 'user' => $recruiter, 'admin' => $admin), true); } if ($recruiter->getSettings('Applications')->getAutoConfirmMail()) { $ackBody = $recruiter->getSettings('Applications')->getMailConfirmationText(); if (empty($ackBody)) { $ackBody = $job->user->getSettings('Applications')->getMailConfirmationText(); } if (!empty($ackBody)) { /* Acknowledge mail to the applicant */ $ackMail = $this->mailer('Applications/Confirmation', array('application' => $applicationEntity, 'body' => $ackBody)); // Must be called after initializers in creation $ackMail->setSubject('Application confirmation'); $ackMail->setFrom($recruiter->getInfo()->getEmail()); $this->mailer($ackMail); $applicationEntity->changeStatus(StatusInterface::CONFIRMED, sprintf('Mail was sent to %s', $applicationEntity->contact->email)); } } // send carbon copy of the application $paramsCC = $this->getRequest()->getPost('carboncopy', 0); if (isset($paramsCC) && array_key_exists('carboncopy', $paramsCC)) { $wantCarbonCopy = (int) $paramsCC['carboncopy']; if ($wantCarbonCopy) { $mail = $this->mailer('Applications/CarbonCopy', array('application' => $applicationEntity, 'to' => $applicationEntity->contact->email), true); } } } if ($request->isXmlHttpRequest()) { return new JsonModel(array('ok' => true, 'id' => $applicationEntity->id, 'jobId' => $applicationEntity->job->id)); } if ($returnTo) { $returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'success')); return $this->redirect()->toUrl((string) $returnTo); } $this->notification()->success('your application was sent successfully'); $viewModel->setVariable('isApplicationSaved', true); } } return $viewModel; }