Example #1
0
 /**
  * Generates the Mail Body
  */
 protected function generateBody()
 {
     $message = new Mime\Message();
     $text = $this->generateHtml();
     $textPart = new Mime\Part($text);
     $textPart->type = 'text/html';
     $textPart->charset = 'UTF-8';
     $textPart->disposition = Mime\Mime::DISPOSITION_INLINE;
     $message->addPart($textPart);
     if (isset($this->application->getContact()->image) && $this->application->getContact()->getImage()->id) {
         /* @var $image \Auth\Entity\UserImage */
         $image = $this->application->getContact()->getImage();
         $part = new Mime\Part($image->getResource());
         $part->type = $image->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $image->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     foreach ($this->application->getAttachments() as $attachment) {
         /* @var $part \Applications\Entity\Attachment */
         $part = new Mime\Part($attachment->getResource());
         $part->type = $attachment->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $attachment->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     $this->setBody($message);
 }
Example #2
0
 /**
  * @testdox Allows setting a the cover letter
  * @covers Applications\Entity\Application::isDraft
  * @covers Applications\Entity\Application::setIsDraft
  */
 public function testSetGetIsDraft()
 {
     $input = true;
     $this->target->setIsDraft($input);
     $this->assertEquals($input, $this->target->isDraft());
     $input = false;
     $this->target->setIsDraft($input);
     $this->assertEquals($input, $this->target->isDraft());
 }
 public function provideAssertTestData()
 {
     $role = new GenericRole('Test');
     $resource = new GenericResource('Test');
     $user = new User();
     $user->setId('testuser');
     $user2 = new User();
     $user2->setId('testuser2');
     $app = new Application();
     $app2 = new Application();
     $app2->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     return array('nouser-noapp' => array($role, $resource, null, false), 'user-noapp' => array($user, $resource, null, false), 'user-app-no-perm' => array($role, $app, null, false), 'read-not-granted' => array($user, $app, 'read', false), 'change-not-granted' => array($user, $app, 'write', false), 'read-granted' => array($user2, $app2, 'read', true), 'change-granted' => array($user2, $app2, 'write', true), 'change-not-granted2' => array($user, $app2, 'change', false));
 }
Example #4
0
 public function provideIsValidTestData()
 {
     $app1 = new Application();
     $app2 = new Application();
     $app3 = new Application();
     $app4 = new Application();
     $contact = new Contact();
     $contact->setEmail('*****@*****.**');
     $app1->setContact(new Contact());
     $app2->setContact($contact);
     $app3->setContact(new Contact());
     $app3->getAttributes()->setAcceptedPrivacyPolicy(true);
     $app4->setContact($contact);
     $app4->getAttributes()->setAcceptedPrivacyPolicy(true);
     return array(array($app1, false, 'NO_EMAIL,NO_ACCEPT_PP'), array($app2, false, 'NO_ACCEPT_PP'), array($app3, false, 'NO_EMAIL'), array($app4, true));
 }
 public function provideAssertTestData()
 {
     $role = new GenericRole('Test');
     $resource = new GenericResource('Test');
     $user = new User();
     $user->setId('testuser');
     $user2 = new User();
     $user2->setId('testuser2');
     $app = new Application();
     $app2 = new Application();
     $app2->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     $app3 = new Application();
     $app3->setIsDraft(true);
     //$app3->setUser($user);
     $app3->getPermissions()->grant($user, PermissionsInterface::PERMISSION_VIEW)->grant($user2, PermissionsInterface::PERMISSION_CHANGE);
     return array('nouser-noapp' => array($role, $resource, null, false), 'user-noapp' => array($user, $resource, null, false), 'user-app-no-perm' => array($role, $app, null, false), 'read-not-granted' => array($user, $app, 'read', false), 'change-not-granted' => array($user, $app, 'write', false), 'read-granted' => array($user2, $app2, 'read', true), 'change-granted' => array($user2, $app2, 'write', true), 'change-not-granted2' => array($user, $app2, 'change', false), 'subsequentAttachmentUpload-not-granted' => array($user, $app, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, false), 'subsequentAttachmentUpload-granted' => array($user, $app2, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, true), 'allow-draft-view' => [$user2, $app3, 'change', true], 'disallow-draft-view' => [$user, $app3, 'change', false]);
 }
Example #6
0
 /**
  * @param Application $application
  * @param UserInterface $user
  * @return CvEntity
  * @since 0.26
  */
 public function createFromApplication(Application $application, UserInterface $user)
 {
     $cv = $this->create();
     $cv->setContact($application->getContact());
     $assignedUser = $application->getJob()->getUser();
     $cv->setUser($assignedUser);
     $perms = $cv->getPermissions();
     $perms->inherit($application->getPermissions());
     // grant view permission to the user that issued this creation.
     $perms->grant($user, PermissionsInterface::PERMISSION_VIEW);
     // revoke change permission to the original applicant
     $perms->revoke($application->getUser(), PermissionsInterface::PERMISSION_CHANGE);
     $applicationAttachments = $application->getAttachments();
     if (count($applicationAttachments) > 0) {
         $cvAttachments = [];
         /* @var $applicationAttachment \Applications\Entity\Attachment */
         foreach ($applicationAttachments as $applicationAttachment) {
             $file = new \Doctrine\MongoDB\GridFSFile();
             $file->setBytes($applicationAttachment->getContent());
             $cvAttachment = new \Cv\Entity\Attachment();
             $cvAttachment->setName($applicationAttachment->getName());
             $cvAttachment->setType($applicationAttachment->getType());
             $cvAttachment->setUser($assignedUser);
             $cvAttachment->setFile($file);
             $cvAttachment->setDateUploaded($applicationAttachment->getDateUploaded());
             $cvAttachments[] = $cvAttachment;
         }
         $cv->setAttachments(new \Doctrine\Common\Collections\ArrayCollection($cvAttachments));
     }
     return $cv;
 }
 /**
  * Send Carbon Copy to the User
  */
 protected function sendCarbonCopyToCandidate()
 {
     if ($this->application->getAttributes()->getSendCarbonCopy()) {
         $this->mailService->send('Applications/CarbonCopy', ['application' => $this->application]);
     }
 }
Example #8
0
 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;
 }
 /**
  * @param $application Application
  * @return $this
  */
 public function setApplication(Application $application)
 {
     /* Applications\Entity\Contact */
     $this->setTo($application->getContact()->getEmail());
     return parent::setApplication($application);
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * @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());
 }
Example #12
0
 public function testSetGetSubscriber()
 {
     $user = new Subscriber();
     $this->target->setSubscriber($user);
     $this->assertEquals($this->target->getSubscriber(), $user);
 }
Example #13
0
 /**
  * @param Application $application
  * @param             $status
  *
  * @return AddressList
  */
 protected function getRecipient(Application $application, $status)
 {
     $recipient = Status::ACCEPTED == $status ? $application->getJob()->getUser()->getInfo() : $application->getContact();
     $email = $recipient->getEmail();
     $name = $recipient->getDisplayName(false);
     return $name ? [$email => $name] : [$email];
 }