public function indexAction() { $mainLayout = $this->initializeAdminArea(); $lang = $this->params()->fromRoute('lang'); $moduleCode = $this->params()->fromRoute('module'); $referenceId = $this->params()->fromRoute('referenceId'); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $userDetails = $this->layout()->getVariable('userDetails'); try { $helper = new AttachmentsFormControllerHelper(); $helper->setModulesGetterWrapper(new ModulesGetterWrapper(new ModulesGetter($em))); $helper->setupModuleRecords($moduleCode); $helper->setAttachmentsGetterWrapper(new AttachmentsGetterWrapper(new AttachmentsGetter($em))); $helper->setupAttachmentsRecords(array('moduleId' => ModulesContainer::recoverIdFromModuleCode($moduleCode), 'referenceId' => $referenceId, 'orderBy' => 'a.position')); $helper->setModuleCode($moduleCode); $helper->checkModuleRecords(); $helper->setupPropertiesGetterClassPath(); $helper->setupPropertiesGetterClassInstance(); $helper->getPropertiesGetterClassInstance()->setModuleCode($moduleCode); $helper->getPropertiesGetterClassInstance()->setEntityManager($em); $helper->getPropertiesGetterClassInstance()->setAttachmentsReferenceId($referenceId); $helper->getPropertiesGetterClassInstance()->setupProperties(); if ($moduleCode == 'albo-pretorio') { $alboRettificaColumnDisplay = 1; } if ($moduleCode == 'atti-concessione') { $attiConcessioneColumnDisplayForm = new AttiConcessioneColumnDisplayForm(); $attiConcessioneColumnDisplayForm->addSubmitButton(); } $this->layout()->setVariables(array('hideBreadcrumb' => 1, 'attachmentsList' => $helper->getAttachmentRecords(), 'articleTitle' => $helper->getPropertiesGetterClassInstance()->getAttachmentFormTitle(), 'attachmentType' => $helper->getModuleCode(), 'moduleCode' => $moduleCode, 'referenceId' => $referenceId, 'formBreadCrumbCategory' => $helper->getPropertiesGetterClassInstance()->getBreadcrumbModule(), 'formBreadCrumbCategoryLink' => $this->url()->fromRoute($helper->getPropertiesGetterClassInstance()->getBreadcrumbRoute(), array('lang' => $lang, 'languageSelection' => $lang, 'modulename' => $moduleCode)), 'alboRettificaColumnDisplay' => isset($alboRettificaColumnDisplay) ? $alboRettificaColumnDisplay : null, 'attiConcessioneCatColumnDisplay' => isset($attiConcessioneColumnDisplayForm) ? 1 : null, 'attiConcessioneColumnDisplayForm' => isset($attiConcessioneColumnDisplayForm) ? $attiConcessioneColumnDisplayForm : null, 'templatePartial' => 'attachments/attachments-summary.phtml')); } catch (NullException $e) { $this->layout()->setVariables(array('templatePartial' => 'message.phtml', 'messageType' => 'danger', 'messageTitle' => 'Si è verificato un errore', 'messageText' => $e->getMessage())); } $this->layout()->setTemplate($mainLayout); }
public function indexAction() { $id = $this->params()->fromPost('id'); /** * @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(); $userDetails = $this->recoverUserDetails(); $helper = new AttachmentsControllerHelper(); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); try { $helper->setLoggedUser($userDetails); $attachmentRecord = $helper->recoverWrapperRecordsById(new AttachmentsGetterWrapper(new AttachmentsGetter($em)), array('id' => $post['deleteId'], 'limit' => 1), $post['deleteId']); $helper->checkRecords($attachmentRecord, 'Dati file allegato non trovati'); $configurations = $this->layout()->getVariable('configurations'); $s3 = new S3($configurations['amazon_s3_accesskey'], $configurations['amazon_s3_secretkey']); $s3->deleteObject($configurations['amazon_s3_bucket'], $this->params()->fromRoute('modulename') . '/' . $attachmentRecord[0]['name']); $helper->deleteAttachments($post['deleteId']); $helper->deleteAttachmentsRelations($post['deleteId']); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::recoverIdFromModuleCode($this->params()->fromRoute('modulename')), 'message' => "Eliminato file allegato ", 'type' => 'info', 'reference_id' => $id, 'backend' => 1)); $helper->getConnection()->commit(); $referer = $this->getRequest()->getHeader('Referer'); if (is_object($referer)) { return $this->redirect()->toUrl($referer->getUri()); } } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $dbEx) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore eliminazione file allegato", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $id, 'backend' => 1)); $referer = $this->getRequest()->getHeader('Referer'); if (is_object($referer)) { $refererLink = $referer->getUri(); } $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore eliminazione file allegato', 'messageText' => $e->getMessage(), 'previousPageLink' => isset($refererLink) ? $refererLink : null, 'previousPageLabel' => "Torna all'elenco allegati", 'templatePartial' => "message.phtml")); } $this->layout()->setTemplate($mainLayout); }
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 PostsCategoriesFormInputFilter(); $form = new PostsCategoriesForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new PostsCategoriesControllerHelper(); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); try { if (!$form->isValid()) { throw new NullException("The form is not valid"); } $inputFilter->exchangeArray($form->getData()); $helper->setLoggedUser($userDetails); $inputFilter->moduleId = ModulesContainer::recoverIdFromModuleCode($this->params()->fromRoute('modulename')); $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::recoverIdFromModuleCode($this->params()->fromRoute('formtype')); $lastInsertId = $helper->insert($inputFilter); $helper->getConnection()->commit(); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::blogs, 'message' => "Inserita nuova categoria " . $this->params()->fromRoute('formtype') . ' ' . $inputFilter->name, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Categoria inserita correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryLink' => $this->url()->fromRoute('admin/posts-categories-summary', array('lang' => $this->params()->fromRoute('lang'), 'languageSelection' => $this->params()->fromRoute('languageSelection'), 'moduleCode' => $this->params()->fromRoute('formtype'))), 'backToSummaryText' => "Elenco categorie")); } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $e) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore inserimento nuova categoria: " . $inputFilter->name, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento nuova categoria', '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'); }
/** * Delete element from home page: recover blockID, remove record from homepage, update related module home flag * * @return \Zend\Http\Response */ public function removeAction() { $mainLayout = $this->initializeAdminArea(); $referenceId = $this->params()->fromRoute('referenceid'); $moduleCode = $this->params()->fromRoute('modulecode'); $moduleId = ModulesContainer::recoverIdFromModuleCode($moduleCode); /** * @var \Doctrine\ORM\EntityManager $em */ $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $connection = $em->getConnection(); $userDetails = $this->layout()->getVariable('userDetails'); $helper = new HomePagePutRemoveControllerHelper(); $helper->setConnection($em->getConnection()); $helper->getConnection()->beginTransaction(); try { $homePageBlocksRecords = $helper->recoverWrapperRecords(new HomePageBlocksGetterWrapper(new HomePageBlocksGetter($em)), array('fields' => 'homePageBlocks.id', 'moduleId' => $moduleId, 'limit' => 1)); $helper->checkRecords($homePageBlocksRecords, 'Impossibile recuperare i dati relativi al modulo in home page'); $helper->deleteFromHomePage($referenceId, $homePageBlocksRecords[0]['id']); $helper->updateHomeFlag(DbTableContainer::recoverMainTableFromModuleCode($moduleCode), $referenceId, $helper->recoverHomeFlagFromModuleCode($moduleCode), 0); $helper->getConnection()->commit(); $referer = $this->getRequest()->getHeader('Referer'); if (is_object($referer)) { return $this->redirect()->toUrl($referer->getUri()); } return $this->redirect()->toRoute('main'); } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $dbEx) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => isset($userDetails->id) ? $userDetails->id : 1, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore nell'operazione di resa visibile bando di gara sul sito pubblico. ID: " . $referenceId, 'type' => 'error', 'reference_id' => $referenceId, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore verificato', 'messageText' => $e->getMessage(), 'templatePartial' => 'message.phtml')); } $this->layout()->setTemplate($mainLayout); }
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(); if (!($request->isXmlHttpRequest() or $request->isPost())) { return $this->redirect()->toRoute('main'); } $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $inputFilter = new AttachmentsFormInputFilter(); $moduleCode = $this->params()->fromRoute('modulename'); $form = new AttachmentsForm(); $form->setBindOnValidate(false); $form->setInputFilter($inputFilter->getInputFilter()); $form->setData($post); $this->initializeAdminArea(); $userDetails = $this->recoverUserDetails(); $helper = new AttachmentsControllerHelper(); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); $s3Helper = new S3Helper(); try { if (!$form->isValid()) { throw new NullException("The form is not valid"); } $inputFilter->exchangeArray($form->getData()); $helper->setLoggedUser($userDetails); $configurations = $this->layout()->getVariable('configurations'); $s3AccessKey = isset($configurations['amazon_s3_accesskey']) ? $configurations['amazon_s3_accesskey'] : null; $s3SecretKey = isset($configurations['amazon_s3_secretkey']) ? $configurations['amazon_s3_secretkey'] : null; $s3Helper->setAccessKey($s3AccessKey); $s3Helper->setSecretKey($s3SecretKey); $s3Helper->setBucket(isset($configurations['amazon_s3_bucket']) ? $configurations['amazon_s3_bucket'] : null); $s3Helper->setS3Directory($inputFilter->s3_directory); $s3Helper->setS3(new S3($s3AccessKey, $s3SecretKey)); $mimeRecords = $helper->recoverWrapperRecords(new AttachmentsMimetypeGetterWrapper(new AttachmentsMimetypeGetter($em)), array('mimetype' => $inputFilter->attachmentFile['type'], 'limit' => 1)); $helper->checkRecords($mimeRecords, "Il tipo di file inserito non è supportato. Per ulteriori informazioni contattare l'amministrazione"); $lastInsertId = $helper->insertAttachments($inputFilter, $mimeRecords[0]['id']); $attachmentFileName = $s3Helper->assignFileName($inputFilter->attachmentFile['name'], $lastInsertId); $helper->updateAttachmentsFilename($lastInsertId, $attachmentFileName); $helper->insertAttachmentsRelations($inputFilter, $lastInsertId); $s3Helper->upload($inputFilter->attachmentFile['tmp_name'], $attachmentFileName); $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::recoverIdFromModuleCode($moduleCode), 'message' => "Inserito nuovo allegato " . $inputFilter->title, 'type' => 'info', 'reference_id' => $lastInsertId, 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'success', 'messageTitle' => 'Allegato inserito correttamente', 'messageText' => 'I dati sono stati processati correttamente dal sistema', 'showLinkResetFormAndShowIt' => 1, 'backToSummaryText' => "Elenco file allegati", 'insertAgainLabel' => "Inserisci un altro file allegato", 'attachmentsLabel' => 'Elenco allegati', 'attachmentsLink' => $this->url()->fromRoute('admin/attachments-summary', array('lang' => $this->params()->fromRoute('lang'), 'module' => $moduleCode, 'referenceId' => $inputFilter->referenceId)))); $helper->getConnection()->commit(); } catch (\Exception $e) { try { $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $dbEx) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::recoverIdFromModuleCode($moduleCode), 'message' => "Errore inserimento nuovo file allegato: " . $inputFilter->title, 'type' => 'error', 'description' => $e->getMessage(), 'backend' => 1)); $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore inserimento file allegato', 'messageText' => $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'); }
public function indexAction() { $id = $this->params()->fromPost('id'); /** * @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(); $moduleId = $this->params()->fromRoute('modulename') == 'contenuti' ? ModulesContainer::contenuti_id : ModulesContainer::amministrazione_trasparente_id; $helper = new ContenutiControllerHelper(); try { $contentRecord = $helper->recoverWrapperRecordsById(new ContenutiGetterWrapper(new ContenutiGetter($em)), array('id' => $post['deleteId'], 'limit' => 1), $post['deleteId']); $helper->checkRecords($contentRecord, 'Articolo da eliminare non trovato'); $helper->setConnection($connection); $helper->getConnection()->beginTransaction(); $helper->delete($post['deleteId']); $helper->getConnection()->commit(); /* Delte Attachments files */ $attachmentsHelper = new AttachmentsControllerHelper(); $attachmentsHelper->setConnection($connection); $attachmentsRecords = $helper->recoverWrapperRecords(new AttachmentsGetterWrapper(new AttachmentsGetter($em)), array('referenceId' => $post['deleteId'], 'moduleId' => $moduleId)); if (!empty($attachmentsRecords)) { foreach ($attachmentsRecords as $attachmentRecord) { $attachmentsHelper->deleteAttachments($attachmentsRecords['id']); $attachmentsHelper->deleteAttachmentsRelations($attachmentsRecords['id']); $s3 = new S3($configurations['amazon_s3_accesskey'], $configurations['amazon_s3_secretkey']); $s3->deleteObject($configurations['amazon_s3_bucket'], $this->params()->fromRoute('modulename') . '/' . $attachmentRecord[0]['name']); } } /* Delete from home page */ $homeHelper = new HomePagePutRemoveControllerHelper(); $homePageRecords = $homeHelper->recoverWrapperRecords(new HomePageGetterWrapper(new HomePageGetter($em)), array('referenceId' => $post['deleteId'], 'moduleId' => $moduleId, 'moduleCode' => $this->params()->fromRoute('modulename'))); if (!empty($homePageRecords)) { $homePageBlocksRecords = $helper->recoverWrapperRecords(new HomePageBlocksGetterWrapper(new HomePageBlocksGetter($em)), array('fields' => 'homePageBlocks.id', 'moduleId' => $moduleId, 'limit' => 1)); $helper->checkRecords($homePageBlocksRecords, 'Impossibile recuperare i dati relativi al modulo in home page'); $homeHelper->setConnection($connection); $homeHelper->getConnection()->beginTransaction(); $homeHelper->deleteFromHomePage($post['deleteId'], $homePageBlocksRecords[0]['id']); $homeHelper->getConnection()->commit(); } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::recoverIdFromModuleCode($this->params()->fromRoute('modulename')), 'message' => "Eliminato articolo " . $contentRecord[0]['titolo'], 'type' => 'info', 'reference_id' => $id, 'backend' => 1)); $referer = $this->getRequest()->getHeader('Referer'); if (is_object($referer)) { return $this->redirect()->toUrl($referer->getUri()); } } catch (\Exception $e) { try { // $helper->getConnection()->rollBack(); } catch (\Doctrine\DBAL\ConnectionException $dbEx) { } $logWriter = new LogWriter($connection); $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Errore eliminazione file articolo ", 'type' => 'error', 'description' => $e->getMessage(), 'reference_id' => $id, 'backend' => 1)); $referer = $this->getRequest()->getHeader('Referer'); if (is_object($referer)) { $refererLink = $referer->getUri(); } $this->layout()->setVariables(array('messageType' => 'danger', 'messageTitle' => 'Errore eliminazione contenuto', 'messageText' => $e->getMessage(), 'previousPageLink' => isset($refererLink) ? $refererLink : null, 'previousPageLabel' => "Torna all'elenco", 'templatePartial' => "message.phtml")); } $this->layout()->setTemplate($mainLayout); }