public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $id = $this->params()->fromRoute('id');
     $lang = $this->params()->fromRoute('lang');
     $languageSelection = $this->params()->fromRoute('languageSelection');
     $formtype = $this->params()->fromRoute('formtype');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $helper = new PostsControllerHelper();
     $recordFromDb = $helper->recoverWrapperRecordsById(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $form = new PostsCategoriesForm();
     if (!empty($recordFromDb)) {
         $form->setData($recordFromDb[0]);
         $submitButtonValue = 'Modifica';
         $formTitle = $recordFromDb[0]['name'];
         $formAction = $this->url()->fromRoute('admin/posts-categories-update', array('lang' => $lang, 'languageSelection' => $languageSelection, 'formtype' => $formtype));
     } else {
         $form->setData(array('posizione' => 1, 'lingua' => 1, 'isAmmTrasparente' => $formtype != 'contenuti' ? 1 : 0));
         $formTitle = 'Nuova categoria';
         $submitButtonValue = 'Inserisci';
         $formAction = $this->url()->fromRoute('admin/posts-categories-insert', array('lang' => $lang, 'languageSelection' => $languageSelection, 'formtype' => $formtype));
     }
     $this->layout()->setVariables(array('form' => $form, 'formAction' => $formAction, 'formTitle' => $formTitle, 'formDescription' => 'Compila i dati relativi alla categoria', 'submitButtonValue' => $submitButtonValue, 'formBreadCrumbCategory' => array(array('href' => $this->url()->fromRoute('admin/posts-categories-summary', array('lang' => $lang, 'moduleCode' => 'blogs', 'languageSelection' => $languageSelection)), 'label' => $formtype == 'blogs' ? ucfirst($formtype) : 'Foto', 'title' => 'Elenco ' . $formtype), array('href' => $this->url()->fromRoute('admin/posts-categories-summary', array('lang' => $lang, 'languageSelection' => $languageSelection, 'moduleCode' => $formtype)), 'label' => 'Categorie', 'title' => 'Categorie ')), 'templatePartial' => self::formTemplate));
     $this->layout()->setTemplate($mainLayout);
 }
 public function jsonAction()
 {
     $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $id = $this->params()->fromRoute('id');
     $helper = new PostsControllerHelper();
     $wrapper = $helper->recoverWrapperById(new PostsGetterWrapper(new PostsGetter($em)), array('id' => $id, 'limit' => 1), $id);
     $wrapper->setEntityManager($em);
     $records = $wrapper->addAttachmentsFromRecords($wrapper->getRecords(), array());
     if (empty($records)) {
         return $this->redirectForUnvalidAccess();
     }
     $record = $records[0];
     return new JsonModel(array('Titolo' => $record['title'], 'Sottotitolo' => $record['subtitle'], 'Descrizione' => $record['description']));
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $mainLayout = $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $page = $this->params()->fromRoute('page');
     $configurations = $this->layout()->getVariable('configurations');
     $directoryThumb = $configurations['media_dir'] . $configurations['media_project'] . 'photo/thumbs/';
     $directoryBig = $configurations['media_dir'] . $configurations['media_project'] . 'photo/big/';
     $helper = new PostsControllerHelper();
     $wrapper = $helper->recoverWrapperRecordsPaginator(new PostsGetterWrapper(new PostsGetter($em)), array('moduleCode' => 'photo', 'orderBy' => 'p.id DESC'), $page, null);
     $categoriesRecords = $helper->recoverWrapperRecords(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($em)), array('moduleCode' => 'photo', 'orderBy' => 'category.name', 'fields' => 'category.id, category.name'));
     $paginator = $wrapper->getPaginator();
     $records = $wrapper->setupRecords();
     $this->layout()->setVariables(array('directoryThumb' => $directoryThumb, 'directoryBig' => $directoryBig, 'categoriesRecords' => $categoriesRecords, 'records' => $records, 'paginator' => $paginator, 'item_count' => $paginator->getTotalItemCount(), 'templatePartial' => 'posts/photo/list.phtml'));
     $this->layout()->setTemplate($mainLayout);
 }
Exemplo n.º 4
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $lang = $this->params()->fromRoute('lang');
     $languageSelection = $this->params()->fromRoute('languageSelection');
     $id = $this->params()->fromRoute('id');
     $configurations = $this->layout()->getVariable('configurations');
     try {
         $helper = new PostsControllerHelper();
         $helper->checkMediaDir($configurations);
         $helper->checkMediaProject($configurations);
         $helper->checkMediaSubDir($configurations);
         $categoriesRecords = $helper->recoverWrapperRecords(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($entityManager)), array('fields' => 'category.id, category.name', 'orderBy' => 'category.name', 'moduleCode' => 'blogs'));
         $helper->checkRecords($categoriesRecords, 'Nessuna categorie non presente. Inserire almeno una categoria');
         $categoriesRecordsForDropDown = $helper->formatForDropwdown($categoriesRecords, 'id', 'name');
         $postsRecords = $helper->recoverWrapperRecordsById($wrapper = new PostsGetterWrapper(new PostsGetter($entityManager)), array('id' => $id, 'limit' => 1), $id);
         $form = new PostsForm();
         $form->addUploadImage();
         $form->addTitle();
         $form->addSubtitle();
         $form->addMainFields();
         $form->addCategory($categoriesRecordsForDropDown);
         /* Additional fields:
            $form->addSeo();
            $form->addHome();
            $form->addFacebook();
            */
         if (!empty($postsRecords)) {
             $categoryIdForForm = $helper->gatherCategoriesId(new PostsGetterWrapper(new PostsGetter($entityManager)), array('fields' => 'c.id, c.name', 'id' => $postsRecords[0]['id'], 'orderBy' => 'c.name'));
             $postsRecords[0]['currentImage'] = isset($postsRecords[0]['image']) ? $postsRecords[0]['image'] : null;
             $postsRecords[0]['categories'] = $categoryIdForForm;
             $form->setData($postsRecords[0]);
             $formTitle = 'Modifica blog post';
             $formAction = $this->url()->fromRoute('admin/blogs-update', array('lang' => $lang, 'languageSelection' => $languageSelection));
             $submitButtonValue = 'Modifica';
         } else {
             $formTitle = 'Nuovo blog post';
             $formAction = $this->url()->fromRoute('admin/blogs-insert', array('lang' => $lang, 'languageSelection' => $languageSelection));
             $submitButtonValue = 'Inserisci';
             $form->setData(array('expireDate' => date('Y-m-d H:i:s', strtotime('+5 years')), 'status' => 1));
         }
         $this->layout()->setVariables(array('form' => $form, 'formTitle' => $formTitle, 'formDescription' => 'Compila dati blog post', 'formAction' => $formAction, 'submitButtonValue' => $submitButtonValue, 'CKEditorField' => 'description', 'formBreadCrumbCategory' => 'Blogs', 'formBreadCrumbCategoryLink' => $this->url()->fromRoute('admin/blogs-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'))), 'templatePartial' => self::formTemplate));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
Exemplo n.º 5
0
 /**
  * @throws \ModelModule\Model\NullException
  */
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     try {
         $helper = new PostsControllerHelper();
         $categoriesRecords = $helper->recoverWrapperRecords(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($em)), array('fields' => 'category.id, category.name', 'orderBy' => 'category.name', 'moduleCode' => 'photo'));
         $helper->checkRecords($categoriesRecords, 'Nessuna categoria foto presente. Aggiungere almeno una categoria');
         $wrapperPosts = $helper->recoverWrapperRecordsPaginator(new PostsGetterWrapper(new PostsGetter($em)), array('moduleCode' => 'photo', 'userId' => null, 'orderBy' => 'p.id DESC', 'fields' => 'DISTINCT(p.id) AS id, p.lastUpdate,
                                 p.createDate, p.expireDate, p.hasAttachments,
                                 p.image, p.title, p.subtitle, p.description, p.slug, p.seoTitle,
                                 p.seoDescription, p.seoKeywords,
                                 users.name AS userName, users.surname AS userSurname'), $page, $perPage);
         /* Add categories to the recordset */
         $postsRecords = $wrapperPosts->setupRecords();
         $helper->checkRecords($postsRecords, 'Nessuna foto in archivio');
         foreach ($postsRecords as &$postsRecord) {
             $wrapper = new PostsGetterWrapper(new PostsGetter($em));
             $wrapper->setInput(array('fields' => 'c.id, c.name', 'id' => $postsRecord['id'], 'orderBy' => 'c.name'));
             $wrapper->setupQueryBuilder();
             $postsRecord['categories'] = $wrapper->getRecords();
         }
         $form = new PostsFormSearch();
         $form->addCategories($helper->formatForDropwdown($categoriesRecords, 'id', 'name'));
         $form->addSubmitButton();
         $paginator = $wrapperPosts->getPaginator();
         $postsRecords = $wrapperPosts->setupRecords();
         $this->layout()->setVariables(array('tableTitle' => 'Foto', 'tableDescription' => $paginator->getTotalItemCount() . ' foto in archivio.', 'paginator' => $paginator, 'records' => $this->formatColumnRecords($postsRecords), 'columns' => array('Foto', "Titolo", "Categorie", "Inserito da", "Date", " ", " "), 'formSearch' => $form, 'templatePartial' => 'datatable/datatable_photo.phtml'));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageType' => 'warning', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
Exemplo n.º 6
0
 public function indexAction()
 {
     $mainLayout = $this->initializeAdminArea();
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $configurations = $this->layout()->getVariable('configurations');
     $lang = $this->params()->fromRoute('lang');
     $languageSelection = $this->params()->fromRoute('languageSelection');
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     $sessionContainer = new SessionContainer();
     $sessionSearch = $sessionContainer->offsetGet(BlogsSearchController::sessionIdentifier);
     try {
         $helper = new PostsControllerHelper();
         $categoriesRecords = $helper->recoverWrapperRecords(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($entityManager)), array('fields' => 'category.id, category.name', 'orderBy' => 'category.name', 'languageAbbreviation' => $languageSelection ? $languageSelection : 'it', 'moduleCode' => 'blogs'));
         $helper->checkRecords($categoriesRecords, 'Nessuna categoria presente');
         $wrapperBlogPosts = $helper->recoverWrapperRecordsPaginator(new PostsGetterWrapper(new PostsGetter($entityManager)), array('moduleCode' => 'blogs', 'userId' => null, 'orderBy' => 'p.id DESC', 'languageAbbr' => $languageSelection ? $languageSelection : 'it', 'freeSearch' => isset($sessionSearch['testo']) ? $sessionSearch['testo'] : null, 'categoryId' => isset($sessionSearch['category']) ? $sessionSearch['category'] : null, 'fields' => 'DISTINCT(p.id) AS id, p.lastUpdate,
                                             p.createDate, p.expireDate, p.hasAttachments,
                                             p.image, p.title, p.subtitle, p.description, p.slug, p.seoTitle,
                                             p.seoDescription, p.seoKeywords,
                                             users.name AS userName, users.surname AS userSurname'), $page, $perPage);
         /* Add categories to the recordset */
         $postsRecords = $wrapperBlogPosts->setupRecords();
         $helper->checkRecords($postsRecords, 'Nessun blog post in archivio');
         /* Add attachments files to the recordset */
         $wrapperBlogPosts->setEntityManager($entityManager);
         $postsRecords = $wrapperBlogPosts->addAttachmentsFromRecords($postsRecords, array('moduleId' => ModulesContainer::blogs));
         foreach ($postsRecords as &$postsRecord) {
             $wrapper = new PostsGetterWrapper(new PostsGetter($entityManager));
             $wrapper->setInput(array('fields' => 'c.id, c.name', 'id' => $postsRecord['id'], 'orderBy' => 'c.name'));
             $wrapper->setupQueryBuilder();
             $postsRecord['categories'] = $wrapper->getRecords();
         }
         $paginator = $wrapperBlogPosts->getPaginator();
         $isMultiLanguage = !empty($configurations['isMultiLanguage']);
         if ($isMultiLanguage == 1) {
             $helper->setLanguagesGetterWrapper(new LanguagesGetterWrapper(new LanguagesGetter($entityManager)));
             $formLanguage = $helper->setupLanguageFormSearch(new LanguagesFormSearch(), array('status' => 1), $languageSelection);
         }
         $form = new PostsFormSearch();
         $form->addCategories($helper->formatForDropwdown($categoriesRecords, 'id', 'name'));
         $form->addSubmitButton();
         $form->setData(isset($sessionSearch) ? $sessionSearch : array());
         $this->layout()->setVariables(array('tableTitle' => 'Blogs', 'tableDescription' => $paginator->getTotalItemCount() . ' posts in archivio', 'columns' => array("Immagine", "Titolo", "Categorie", "Inserita da", "Date", " ", " ", " "), 'paginator' => $paginator, 'records' => $this->formatColumnRecords($postsRecords), 'formSearch' => $form, 'formLanguage' => !empty($formLanguage) ? $formLanguage : null, 'sessionSearch' => $sessionSearch, 'formLanguageAction' => $this->url()->fromRoute('admin/blogs-operations', array('action' => 'switchlanguage', 'lang' => $lang, 'languageSelection' => $languageSelection)), 'templatePartial' => 'datatable/datatable_blogs.phtml'));
     } catch (\Exception $e) {
         $this->layout()->setVariables(array('messageText' => $e->getMessage(), 'templatePartial' => 'message-exception.phtml'));
     }
     $this->layout()->setTemplate($mainLayout);
 }
Exemplo n.º 7
0
 public function indexAction()
 {
     $mainLayout = $this->initializeFrontendWebsite();
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $configurations = $this->layout()->getVariable('configurations');
     $lang = $this->params()->fromRoute('lang');
     $page = $this->params()->fromRoute('page');
     $perPage = $this->params()->fromRoute('perpage');
     $category = $this->params()->fromRoute('category');
     $helper = new PostsControllerHelper();
     $categoriesRecords = $helper->recoverWrapperRecords(new PostsCategoriesGetterWrapper(new PostsCategoriesGetter($em)), array('languageAbbr' => $lang, 'orderBy' => ''));
     $categoriesRecordsForDropDown = $helper->formatForDropwdown($categoriesRecords, 'id', 'name');
     $wrapper = $helper->recoverWrapperRecordsPaginator(new PostsGetterWrapper(new PostsGetter($em)), array('moduleCode' => 'blogs', 'categorySlug' => $category, 'languageAbbr' => $lang, 'orderBy' => 'p.id DESC'), $page, $perPage);
     $wrapper->setEntityManager($em);
     $records = $wrapper->addAttachmentsToPaginatorRecords($wrapper->setupRecords(), array('moduleId' => ModulesContainer::blogs, 'noScaduti' => 1, 'languageAbbreviation' => $lang, 'orderBy' => 'a.position'));
     $paginator = $wrapper->getPaginator();
     if (!empty($categoriesRecordsForDropDown)) {
         $formSearch = new PostsFormSearch();
         $formSearch->addCategories($categoriesRecordsForDropDown);
         $formSearch->addSubmitButton();
     }
     $this->layout()->setVariables(array('records' => $records, 'paginator' => $paginator, 'item_count' => $paginator->getTotalItemCount(), 'category' => $category, 'formSearch' => !empty($formSearch) ? $formSearch : null, 'categoryName' => Slugifier::deSlugify($category), 'mediaDir' => isset($configurations['media_dir']) ? $configurations['media_dir'] : null, 'mediaProject' => isset($configurations['media_project']) ? $configurations['media_project'] : null, 'templatePartial' => 'posts/blogs/list.phtml'));
     $this->layout()->setTemplate($mainLayout);
 }
Exemplo n.º 8
0
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $mainLayout = $this->initializeAdminArea();
     $configurations = $this->layout()->getVariable('configurations');
     $userDetails = $this->recoverUserDetails();
     $id = $post['deleteId'];
     $helper = new PostsControllerHelper();
     $helper->setEntityManager($em);
     $helper->setConnection($connection);
     $helper->setLoggedUser($userDetails);
     try {
         $records = $helper->recoverWrapperRecordsById(new PostsGetterWrapper(new PostsGetter($em)), array('id' => $id, 'limit' => 1, 'fields' => 'p.image'), $id);
         $helper->checkRecords('Dati post corrente non trovati');
         /* Delete images from file system */
         $currentImage = isset($records[0]['image']) ? $records[0]['image'] : null;
         if ($currentImage) {
             $mediaDir = $helper->checkMediaDir($configurations);
             $mediaProject = $helper->checkMediaProject($configurations);
             /* Delete old image */
             $oldImageThumbPath = $mediaDir . $mediaProject . '/blogs/thumbs/' . $currentImage;
             $oldImageBigPath = $mediaDir . $mediaProject . '/blogs/big/' . $currentImage;
             if (file_exists($oldImageThumbPath) and $currentImage != '') {
                 unlink($oldImageThumbPath);
             }
             if (file_exists($oldImageBigPath) and $currentImage != '') {
                 unlink($oldImageBigPath);
             }
         }
         /* Delete Post from database */
         $helper->getConnection()->beginTransaction();
         $helper->delete($id, ModulesContainer::blogs);
         $helper->getConnection()->commit();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::blogs, 'message' => "Eliminato post blog " . $id, 'type' => 'info', 'reference_id' => $id, 'backend' => 1));
         return $this->redirect()->toUrl($this->url()->fromRoute('admin/blogs-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'page' => $this->params()->fromRoute('page'), 'modulename' => $this->params()->fromRoute('modulename'))));
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $exDb) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::blogs, 'message' => "Errore eliminazione blog post", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore eliminazione blog post', 'messageText' => $e->getMessage(), 'messageShowFormLink' => 1, 'messageShowForm' => "Torna all'elenco posts", 'templatePartial' => 'message.phtml'));
         $this->layout()->setTemplate($mainLayout);
     }
 }
Exemplo n.º 9
0
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new PostsFormInputFilter();
     $form = new PostsForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $userDetails = $this->recoverUserDetails();
     $configurations = $this->layout()->getVariable('configurations');
     $helper = new PostsControllerHelper();
     $helper->setConnection($connection);
     $helper->getConnection()->beginTransaction();
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $publicDirPath = $helper->recoverPublicDirPath($this->layout()->getVariable('isPublicDirOnRoot'));
         $mediaDir = $helper->checkMediaDir($configurations);
         $mediaProject = $helper->checkMediaProject($configurations);
         $helper->checkMediaSubDir($configurations);
         $languageRecords = $helper->recoverWrapperRecords(new LanguagesGetterWrapper(new LanguagesGetter($em)), array('abbrev1' => $this->params()->fromRoute('languageSelection'), 'fields' => 'languages.id'));
         $helper->checkRecords($languageRecords, 'Nessun dato relativo alle lingue');
         $inputFilter->languageId = $languageRecords[0]['id'];
         $inputFilter->moduleId = ModulesContainer::blogs;
         $helper->setLoggedUser($userDetails);
         $helper->insert($inputFilter);
         $lastInsertId = $helper->getConnection()->lastInsertId();
         /* Create thumbnail and upload big image*/
         if ($inputFilter->image) {
             $imagePathInfo = pathinfo($inputFilter->image['name']);
             $newFilename = $lastInsertId . '_' . uniqid() . '.' . $imagePathInfo['extension'];
             $thumbWitdth = isset($configurations['blogs_image_width']) ? $configurations['blogs_image_width'] : 160;
             $thumbHeight = isset($configurations['blogs_image_height']) ? $configurations['blogs_image_height'] : 130;
             $imagine = new \Imagine\Gd\Imagine();
             $imagine->open($inputFilter->image['tmp_name'])->thumbnail(new \Imagine\Image\Box($thumbWitdth, $thumbHeight), \Imagine\Image\ImageInterface::THUMBNAIL_INSET)->save($publicDirPath . $mediaDir . $mediaProject . '/blogs/thumbs/' . $newFilename);
             move_uploaded_file($inputFilter->image['tmp_name'], $publicDirPath . $mediaDir . $mediaProject . '/blogs/big/' . $newFilename);
             $helper->updateImage($lastInsertId, $newFilename);
         }
         /* Insert Relations */
         foreach ($inputFilter->categories as $category) {
             $helper->insertRelation($inputFilter, $lastInsertId, $category);
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::blogs, 'message' => "Inserita nuovo blog post " . $inputFilter->title, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Blog post inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/blogs-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'))), 'backToSummaryText' => "Elenco posts", 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('lang'), 'module' => 'blogs', 'referenceId' => $lastInsertId)), 'insertAgainLabel' => "Inserisci un altro post"));
         $helper->getConnection()->commit();
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $ex) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::blogs, 'message' => "Errore inserimento nuovo blog post: " . $inputFilter->title, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuovo blog post', 'messageText' => 'Messaggio generato: ' . $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => 'Torna al form di inserimento dati'));
     }
     $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
 }
Exemplo n.º 10
0
 public function indexAction()
 {
     /**
      * @var \Doctrine\ORM\EntityManager $em
      */
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /**
      * @var \Doctrine\DBAL\Connection $connection
      */
     $connection = $em->getConnection();
     $request = $this->getRequest();
     $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
     if (!($request->isXmlHttpRequest() or $request->isPost())) {
         return $this->redirect()->toRoute('main');
     }
     $inputFilter = new PostsFormInputFilter();
     $form = new PostsForm();
     $form->setBindOnValidate(false);
     $form->setInputFilter($inputFilter->getInputFilter());
     $form->setData($post);
     $this->initializeAdminArea();
     $configurations = $this->layout()->getVariable('configurations');
     $userDetails = $this->recoverUserDetails();
     $moduleId = ModulesContainer::photo;
     try {
         if (!$form->isValid()) {
             throw new NullException("The form is not valid");
         }
         $inputFilter->exchangeArray($form->getData());
         $helper = new PostsControllerHelper();
         $helper->setConnection($connection);
         $helper->getConnection()->beginTransaction();
         $helper->setLoggedUser($userDetails);
         $publicDirPath = $helper->recoverPublicDirPath($this->layout()->getVariable('isPublicDirOnRoot'));
         if ($inputFilter->image) {
             $records = $helper->recoverWrapperRecordsById(new PostsGetterWrapper(new PostsGetter($em)), array('id' => $inputFilter->id, 'limit' => 1, 'fields' => 'p.image'), $inputFilter->id);
             $helper->checkRecords('Dati foto corrente non trovati');
             $currentImage = isset($records[0]['image']) ? $records[0]['image'] : null;
             $mediaDir = $helper->checkMediaDir($configurations);
             $mediaProject = $helper->checkMediaProject($configurations);
             /* Delete old image */
             $oldImageThumbPath = $publicDirPath . $mediaDir . $mediaProject . 'photo/thumbs/' . $currentImage;
             $oldImageBigPath = $publicDirPath . $mediaDir . $mediaProject . 'photo/big/' . $currentImage;
             if (file_exists($oldImageThumbPath) and $currentImage != '') {
                 unlink($oldImageThumbPath);
             }
             if (file_exists($oldImageBigPath) and $currentImage != '') {
                 unlink($oldImageBigPath);
             }
             $imagePathInfo = pathinfo($inputFilter->image['name']);
             $newFilename = $inputFilter->id . '_' . uniqid() . '.' . $imagePathInfo['extension'];
             $thumbWitdth = isset($configurations['photo_image_width']) ? $configurations['photo_image_width'] : 160;
             $thumbHeight = isset($configurations['photo_image_height']) ? $configurations['photo_image_height'] : 130;
             $imagine = new \Imagine\Gd\Imagine();
             $imagine->open($inputFilter->image['tmp_name'])->thumbnail(new \Imagine\Image\Box($thumbWitdth, $thumbHeight), \Imagine\Image\ImageInterface::THUMBNAIL_INSET)->save($publicDirPath . $mediaDir . $mediaProject . '/photo/thumbs/' . $newFilename);
             move_uploaded_file($inputFilter->image['tmp_name'], $publicDirPath . $mediaDir . $mediaProject . '/photo/big/' . $newFilename);
             $inputFilter->image = $newFilename;
         }
         $helper->update($inputFilter);
         /* Delete old relations */
         $helper->deleteRelation($inputFilter->id, $moduleId);
         /* Insert Relations */
         foreach ($inputFilter->categories as $category) {
             $inputFilter->moduleId = $moduleId;
             $helper->insertRelation($inputFilter, $inputFilter->id, $category);
         }
         $helper->getConnection()->commit();
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => $moduleId, 'message' => "Aggiornata foto " . $inputFilter->title, 'type' => 'info', 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Foto aggiornata correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'messageShowFormLink' => 1, 'messageShowForm' => "Torna ai dati della foto", 'backToSummaryLink' => $this->url()->fromRoute('admin/photo-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'))), 'backToSummaryText' => "Elenco foto"));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     } catch (\Exception $e) {
         try {
             $helper->getConnection()->rollBack();
         } catch (\Doctrine\DBAL\ConnectionException $exDb) {
         }
         $logWriter = new LogWriter($connection);
         $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => $moduleId, 'message' => "Errore aggiornamento foto", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $inputFilter->id, 'backend' => 1));
         $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore aggiornamento foto', 'messageText' => $e->getMessage(), 'form' => $form, 'formInputFilter' => $inputFilter->getInputFilter(), 'messageShowFormLink' => 1, 'messageShowForm' => "Torna all'elenco foto"));
         $this->layout()->setTemplate($this->layout()->getVariable('templateDir') . 'message.phtml');
     }
 }