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; }
/** * @testdox Allows setting/getting multi job applications * @covers Jobs\Entity\Job::getApplications * @covers Jobs\Entity\Job::setApplications */ public function testSetGetApplications() { $arrayCollection = new ArrayCollection(); $application = new Application(); $application->setIsDraft(false); $application->setId(123); $arrayCollection->add($application); $this->target->setApplications($arrayCollection); $this->assertEquals($arrayCollection, $this->target->getApplications()); }