Esempio n. 1
0
 /**
  * Create a new image
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $entity = new ImageEntity();
     $em = $this->getEntityManager();
     $form->bind($entity);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
     foreach (ImageEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $entity->setImage($newName);
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
         return false;
     }
 }
Esempio n. 2
0
 /**
  * Create a new post
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $post = new PostEntity();
     $em = $this->getEntityManager();
     $form->bind($post);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
     foreach (PostEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $post->setThumbnail($newName);
     $post->setPostDate("now");
     $post->setUrl($this->getPostUrl($post));
     try {
         $em->persist($post);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
         return false;
     }
 }
Esempio n. 3
0
 /**
  * @param $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     if (!empty($data['setting']['aboutProfileImage']['name'])) {
         if (!($newName = FileUtilService::rename($data['setting']['aboutProfileImage'], 'images', null, "about-profile"))) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         } else {
             FileUtilService::resize($newName, 'images', 400, null, 'png');
             FileUtilService::deleteFile(ROOT_PATH . '/images/' . $newName);
         }
     }
     if (!empty($data['setting']['homeImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['homeImage'], 'images', null, "home-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['aboutImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['aboutImage'], 'images', null, "about-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['galleriesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['galleriesImage'], 'images', null, "galleries-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['servicesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['servicesImage'], 'images', null, "services-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['contactImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['contactImage'], 'images', null, "contact-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_UPDATED"]);
     return true;
 }