/** * @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; }
public function save(ParametersInterface $data) { $em = $this->getEntityManager(); $attribute = $data->get('attribute'); $primaryKey = $data->get('primaryKey'); $content = $data->get('content') ? $data->get('content') : null; $constraints = $data->get('constraints', null); $repository = $this->getRepository('post', 'post'); if ($constraints) { $constraints = json_decode(str_replace('\\', '\\\\', $constraints), true); } if ($primaryKey) { $entity = $repository->find($primaryKey); if ($entity) { $filter = $this->getServiceManager()->get('postFilter')->filter($attribute, $content); /** * @var \Zend\InputFilter\InputFilterInterface $filter */ if ($filter->isValid()) { if (!empty($constraints) && $content) { foreach ($constraints as $constraint) { if ($constraint["type"] == "foreign") { $content = $em->getReference($constraint["target"], $content); } } } if ($attribute == "thumbnail") { $this->deleteImages($entity); foreach (PostEntity::$thumbnailVariations as $variation) { $result = FileUtilService::resize($content, 'images/posts', $variation["width"], $variation["height"]); if (!$result) { $this->message = $result; return false; } } } $entity->{'set' . ucfirst($attribute)}($content); try { $em->persist($entity); $em->flush(); $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_SAVED"]); return true; } catch (\Exception $e) { $this->message = $this->getTranslator()->translate($this->getVocabulary()["ERROR_POST_NOT_SAVED"]); } } else { $this->message = $filter->getMessages()[$attribute]; } } } return false; }