Example #1
0
 /**
  * Edit the profile of the person.
  *
  * @return ViewModel
  */
 public function editAction()
 {
     $contactService = $this->getContactService()->setContactId($this->zfcUserAuthentication()->getIdentity()->getId());
     //Find the amount of possible organisations
     $organisations = $this->getOrganisationService()->findOrganisationForProfileEditByContact($contactService->getContact());
     $branches = [];
     if ($contactService->hasOrganisation()) {
         $branches = $this->getOrganisationService()->findBranchesByOrganisation($contactService->getContact()->getContactOrganisation()->getOrganisation());
     }
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new Profile($this->getEntityManager(), $this->getContactService(), $contactService->getContact());
     $form->bind($contactService->getContact());
     /**
      * When the organisation name is typed, we force the value to zero
      */
     if (!isset($data['contact_organisation']['organisation_id'])) {
         $form->getInputFilter()->get('contact_organisation')->remove('organisation_id');
     }
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $contact = $form->getData();
         $fileData = $this->params()->fromFiles();
         if (!empty($fileData['file']['name'])) {
             $photo = $contactService->getContact()->getPhoto()->first();
             if (!$photo) {
                 //Create a photo element
                 $photo = new Photo();
             }
             $photo->setPhoto(file_get_contents($fileData['file']['tmp_name']));
             $photo->setThumb(file_get_contents($fileData['file']['tmp_name']));
             $imageSizeValidator = new ImageSize();
             $imageSizeValidator->isValid($fileData['file']);
             $photo->setWidth($imageSizeValidator->width);
             $photo->setHeight($imageSizeValidator->height);
             $photo->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
             $collection = new ArrayCollection();
             $collection->add($photo);
             $contact->addPhoto($collection);
         }
         /*
          * Remove any unwanted photo's
          */
         foreach ($contact->getPhoto() as $photo) {
             if (is_null($photo->getWidth())) {
                 $collection = new ArrayCollection();
                 $collection->add($photo);
                 $contact->removePhoto($collection);
             }
         }
         $contact = $this->getContactService()->updateEntity($contact);
         /**
          * The contact_organisation is different and not a drop-down.
          * we will extract the organisation name from the contact_organisation text-field
          */
         $this->getContactService()->updateContactOrganisation($contact, $data['contact_organisation']);
         $this->flashMessenger()->setNamespace('success')->addMessage(_("txt-profile-has-successfully-been-updated"));
         return $this->redirect()->toRoute('community/contact/profile/view');
     }
     return new ViewModel(['form' => $form, 'branches' => $branches, 'contactService' => $contactService, 'hasOrganisations' => sizeof($organisations) > 1, 'fullVersion' => true]);
 }
Example #2
0
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\ImageSize(array('minWidth' => 100, 'minHeight' => 1000, 'maxWidth' => 10000, 'maxHeight' => 100000));
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileImageSizeNotReadable', $validator->getMessages()));
     $this->assertContains("'nofile.mo'", current($validator->getMessages()));
 }
Example #3
0
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     $validator = new File\ImageSize();
     $this->assertFalse($validator->isValid(''));
     $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages());
     $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => '');
     $this->assertFalse($validator->isValid($filesArray));
     $this->assertArrayHasKey(File\ImageSize::NOT_READABLE, $validator->getMessages());
 }
Example #4
0
 /**
  * Ensures that setImageHeight() returns expected value
  *
  * @return void
  */
 public function testSetImageHeight()
 {
     $validator = new File\ImageSize(array('minwidth' => 100, 'minheight' => 1000, 'maxwidth' => 10000, 'maxheight' => 100000));
     $validator->setImageHeight(array('minheight' => 2000, 'maxheight' => 2200));
     $this->assertEquals(array('minheight' => 2000, 'maxheight' => 2200), $validator->getImageHeight());
     $this->setExpectedException('Zend\\Validator\\Exception\\InvalidArgumentException', 'less than or equal');
     $validator->setImageHeight(array('minheight' => 20000, 'maxheight' => 200));
 }
Example #5
0
 /**
  * Edit the profile of the person
  * @return ViewModel
  */
 public function profileEditAction()
 {
     $contactService = $this->getContactService()->setContactId($this->zfcUserAuthentication()->getIdentity()->getId());
     $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
     $form = new Profile($this->getServiceLocator(), $contactService->getContact());
     $form->bind($contactService->getContact());
     $form->setData($data);
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $contact = $form->getData();
         $fileData = $this->params()->fromFiles();
         if (!empty($fileData['file']['name'])) {
             $photo = $contactService->getContact()->getPhoto()->first();
             if (!$photo) {
                 //Create a photo element
                 $photo = new Photo();
             }
             $photo->setPhoto(file_get_contents($fileData['file']['tmp_name']));
             $photo->setThumb(file_get_contents($fileData['file']['tmp_name']));
             $imageSizeValidator = new ImageSize();
             $imageSizeValidator->isValid($fileData['file']);
             $photo->setWidth($imageSizeValidator->width);
             $photo->setHeight($imageSizeValidator->height);
             $photo->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
             $collection = new ArrayCollection();
             $collection->add($photo);
             $contact->addPhoto($collection);
         }
         /**
          * Remove any unwanted photo's
          */
         foreach ($contact->getPhoto() as $photo) {
             if (is_null($photo->getWidth())) {
                 $collection = new ArrayCollection();
                 $collection->add($photo);
                 $contact->removePhoto($collection);
             }
         }
         $contact = $this->getContactService()->updateEntity($contact);
         /**
          * The contact_organisation is different and not a drop-down.
          * we will extract the organisation name from the contact_organisation text-field
          */
         $this->getContactService()->updateContactOrganisation($contact, $data['contact_organisation']);
         $this->flashMessenger()->setNamespace('success')->addMessage(_("txt-profile-has-successfully-been-updated"));
         return $this->redirect()->toRoute('contact/profile');
     }
     return new ViewModel(['form' => $form, 'contactService' => $contactService, 'fullVersion' => true]);
 }
Example #6
0
 /**
  * Ensures that setImageHeight() returns expected value
  *
  * @return void
  */
 public function testSetImageHeight()
 {
     $validator = new File\ImageSize(array('minwidth' => 100, 'minheight' => 1000, 'maxwidth' => 10000, 'maxheight' => 100000));
     $validator->setImageHeight(array('minheight' => 2000, 'maxheight' => 2200));
     $this->assertEquals(array('minheight' => 2000, 'maxheight' => 2200), $validator->getImageHeight());
     try {
         $validator->setImageHeight(array('minheight' => 20000, 'maxheight' => 200));
         $this->fail("Missing exception");
     } catch (Validator\Exception $e) {
         $this->assertContains("less than or equal", $e->getMessage());
     }
 }
 /**
  * @return ViewModel
  */
 public function editAction()
 {
     $organisationService = $this->getOrganisationService()->setOrganisationId($this->params('id'));
     $data = array_merge(['description' => $organisationService->getOrganisation()->getDescription()], $this->getRequest()->getPost()->toArray());
     $form = $this->getFormService()->prepare($organisationService->getOrganisation(), $organisationService->getOrganisation(), $data);
     if ($this->getRequest()->isPost()) {
         if (isset($data['cancel'])) {
             return $this->redirect()->toRoute('zfcadmin/organisation/view', ['id' => $organisationService->getOrganisation()->getId()]);
         }
         if ($form->isValid()) {
             $this->flashMessenger()->setNamespace('success')->addMessage(sprintf($this->translate("txt-organisation-%s-has-successfully-been-updated"), $organisationService->getOrganisation()));
             /**
              * @var $organisation Organisation
              */
             $organisation = $form->getData();
             $fileData = $this->params()->fromFiles();
             if (!empty($fileData['file']['name'])) {
                 $logo = $organisationService->getOrganisation()->getLogo()->first();
                 if (!$logo) {
                     //Create a logo element
                     $logo = new Logo();
                     $logo->setOrganisation($organisationService->getOrganisation());
                 }
                 $logo->setOrganisationLogo(file_get_contents($fileData['file']['tmp_name']));
                 $imageSizeValidator = new ImageSize();
                 $imageSizeValidator->isValid($fileData['file']);
                 $logo->setContentType($this->getGeneralService()->findContentTypeByContentTypeName($fileData['file']['type']));
                 $logo->setLogoExtension($logo->getContentType()->getExtension());
                 $organisation->getLogo()->add($logo);
                 /**
                  * Remove the cached file
                  */
                 if (file_exists($logo->getCacheFileName())) {
                     unlink($logo->getCacheFileName());
                 }
             }
             $this->getOrganisationService()->updateEntity($organisation);
             return $this->redirect()->toRoute('zfcadmin/organisation/view', ['id' => $organisationService->getOrganisation()->getId()]);
         }
     }
     return new ViewModel(['organisationService' => $organisationService, 'form' => $form]);
 }