Exemplo n.º 1
0
 /**
  * Test Contact entity should inherit from InfoInterface
  */
 public function testShouldCopyFromInfoInterface()
 {
     $info = new Info();
     $info->setFirstName('First Name')->setLastName('Last Name')->setBirthDay('01-01-1980');
     $ob = $this->target;
     $ob->inherit($info);
     $this->assertEquals($info->getFirstName(), $ob->getFirstName());
     $this->assertEquals($info->getLastName(), $ob->getLastName());
     $this->assertEquals($info->getBirthDay(), $ob->getBirthDay());
 }
Exemplo n.º 2
0
 /**
  * @testdox Allows setting the users city
  * @covers Auth\Entity\Info::getLastName
  * @covers Auth\Entity\Info::setLastName
  * @dataProvider provideGetDisplayNameTestData
  */
 public function testGetDisplayName($firstname, $lastname, $email, $result)
 {
     $this->target->setFirstName($firstname);
     $this->target->setLastName($lastname);
     $this->target->setEmail($email);
     $this->assertEquals($result, $this->target->getDisplayName());
 }
Exemplo n.º 3
0
 /**
  * @param array $params
  *
  * @return User
  */
 public static function createEntityWithRandomData(array $params = array())
 {
     $withId = true;
     $entityId = bin2hex(substr(uniqid(), 1));
     $email = uniqid('email');
     $login = uniqid('login');
     $password = uniqid('password');
     $role = User::ROLE_RECRUITER;
     extract($params);
     $userEntity = new User();
     $userEntity->setEmail($email)->setLogin($login)->setPassword($password)->setRole($role);
     $infoEntity = new Info();
     $infoEntity->setEmail($email);
     $userEntity->setInfo($infoEntity);
     if ($withId) {
         $userEntity->setId($entityId);
     }
     $organization = new OrganizationReferenceMock();
     $userEntity->setOrganization($organization);
     return $userEntity;
 }
Exemplo n.º 4
0
 protected function createUser($role = User::ROLE_RECRUITER)
 {
     $email = '*****@*****.**';
     $locator = $this->getApplicationServiceLocator();
     /* @var DocumentManager $dm */
     $dm = $locator->get('doctrine.documentmanager.odm_default');
     $userRepo = $dm->getRepository('Auth\\Entity\\User');
     $user = $userRepo->findOneBy(array('login' => $email));
     if (empty($user)) {
         $user = new User();
         $user->setEmail($email)->setLogin($email)->setRole($role)->setPassword($email);
         $infoEntity = new Info();
         $infoEntity->setEmail($email);
         $user->setInfo($infoEntity);
         $dm->persist($user);
     } else {
         $user->setRole($role);
     }
     $dm->flush();
     $this->activeUser = $user;
     return $user;
 }
Exemplo n.º 5
0
 /**
  * Copy user info into the applications info Entity
  * 
  * @param \Auth\Entity\Info $info
  */
 public function copyUserInfo(Info $info)
 {
     $contact = new Info();
     $contact->fromArray(Info::toArray($info));
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 public function testSetGetContactEmailWithUser()
 {
     $input = "*****@*****.**";
     $info = new Info();
     $info->setEmail($input);
     $user = new User();
     $user->setInfo($info);
     $this->target->setUser($user);
     $this->assertEquals($this->target->getContactEmail(), $input);
 }
Exemplo n.º 8
0
 /**
  * @testdox Allows to set the role name of a user
  * @covers Auth\Entity\User::getEmail
  * @covers Auth\Entity\User::setEmail
  * @dataProvider provideEmailTestData
  */
 public function testSetGetEmail($userEmail, $infoEmail, $expectedEmail)
 {
     $info = new Info();
     $info->setEmail($infoEmail);
     $this->target->setInfo($info);
     $this->target->setEmail($userEmail);
     $this->assertEquals($expectedEmail, $this->target->getEmail());
 }