From cf774b779961a5376cb40a5234ef5c4ebbe7c625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ismail=20=C3=A7ak=C4=B1r?= Date: Sat, 5 Dec 2020 19:43:02 +0300 Subject: [PATCH] initial commit --- Api/Data/LogInterface.php | 197 +++++++++++++ Api/Data/LogSearchResultsInterface.php | 26 ++ Api/Data/ReportInterface.php | 169 +++++++++++ Api/Data/ReportSearchResultsInterface.php | 26 ++ Api/ExportManagementInterface.php | 20 ++ Api/LogRepositoryInterface.php | 62 +++++ Api/ReportRepositoryInterface.php | 62 +++++ Api/ReportsManagementInterface.php | 20 ++ Block/Adminhtml/Log/Edit/BackButton.php | 38 +++ Block/Adminhtml/Log/Edit/DeleteButton.php | 44 +++ Block/Adminhtml/Log/Edit/GenericButton.php | 47 ++++ .../Log/Edit/SaveAndContinueButton.php | 32 +++ Block/Adminhtml/Log/Edit/SaveButton.php | 31 +++ Block/Adminhtml/Report/Edit/BackButton.php | 38 +++ Block/Adminhtml/Report/Edit/DeleteButton.php | 44 +++ Block/Adminhtml/Report/Edit/GenericButton.php | 47 ++++ .../Report/Edit/SaveAndContinueButton.php | 32 +++ Block/Adminhtml/Report/Edit/SaveButton.php | 31 +++ COPYING.txt | 19 ++ Console/Command/Export.php | 48 ++++ Controller/Adminhtml/Log.php | 42 +++ Controller/Adminhtml/Log/Delete.php | 47 ++++ Controller/Adminhtml/Log/Edit.php | 64 +++++ Controller/Adminhtml/Log/Index.php | 41 +++ Controller/Adminhtml/Log/InlineEdit.php | 65 +++++ Controller/Adminhtml/Log/NewAction.php | 41 +++ Controller/Adminhtml/Log/Save.php | 71 +++++ Controller/Adminhtml/Report.php | 42 +++ Controller/Adminhtml/Report/Delete.php | 47 ++++ Controller/Adminhtml/Report/Edit.php | 64 +++++ Controller/Adminhtml/Report/Index.php | 41 +++ Controller/Adminhtml/Report/InlineEdit.php | 65 +++++ Controller/Adminhtml/Report/NewAction.php | 41 +++ Controller/Adminhtml/Report/Save.php | 71 +++++ Cron/DeleteFile.php | 35 +++ Cron/Email.php | 35 +++ Helper/Config.php | 32 +++ Helper/Export.php | 24 ++ Helper/Functions.php | 24 ++ LICENSE.txt | 19 ++ Model/Data/Log.php | 263 ++++++++++++++++++ Model/Data/Report.php | 225 +++++++++++++++ Model/ExportManagement.php | 21 ++ Model/Log.php | 64 +++++ Model/Log/DataProvider.php | 73 +++++ Model/LogRepository.php | 187 +++++++++++++ Model/Report.php | 64 +++++ Model/Report/DataProvider.php | 73 +++++ Model/ReportRepository.php | 187 +++++++++++++ Model/ReportsManagement.php | 21 ++ Model/ResourceModel/Log.php | 23 ++ Model/ResourceModel/Log/Collection.php | 31 +++ Model/ResourceModel/Report.php | 23 ++ Model/ResourceModel/Report/Collection.php | 31 +++ Observer/Export/ReportEnd.php | 25 ++ Observer/Export/ReportStart.php | 25 ++ README.md | 94 +++++++ Ui/Component/Listing/Column/LogActions.php | 78 ++++++ Ui/Component/Listing/Column/ReportActions.php | 78 ++++++ composer.json | 24 ++ etc/acl.xml | 33 +++ etc/adminhtml/menu.xml | 28 ++ etc/adminhtml/routes.xml | 8 + etc/adminhtml/system.xml | 35 +++ etc/config.xml | 15 + etc/cron_groups.xml | 12 + etc/crontab.xml | 11 + etc/db_schema.xml | 35 +++ etc/di.xml | 38 +++ etc/events.xml | 9 + etc/module.xml | 4 + etc/webapi.xml | 75 +++++ i18n/en_US.csv | 1 + i18n/tr_TR.csv | 1 + registration.php | 9 + .../layout/kodhub_reporter_log_edit.xml | 9 + .../layout/kodhub_reporter_log_index.xml | 9 + .../layout/kodhub_reporter_log_new.xml | 4 + .../layout/kodhub_reporter_report_edit.xml | 9 + .../layout/kodhub_reporter_report_index.xml | 9 + .../layout/kodhub_reporter_report_new.xml | 4 + .../ui_component/kodhub_reporter_log_form.xml | 59 ++++ .../kodhub_reporter_log_listing.xml | 96 +++++++ .../kodhub_reporter_report_form.xml | 179 ++++++++++++ .../kodhub_reporter_report_listing.xml | 192 +++++++++++++ 85 files changed, 4438 insertions(+) create mode 100644 Api/Data/LogInterface.php create mode 100644 Api/Data/LogSearchResultsInterface.php create mode 100644 Api/Data/ReportInterface.php create mode 100644 Api/Data/ReportSearchResultsInterface.php create mode 100644 Api/ExportManagementInterface.php create mode 100644 Api/LogRepositoryInterface.php create mode 100644 Api/ReportRepositoryInterface.php create mode 100644 Api/ReportsManagementInterface.php create mode 100644 Block/Adminhtml/Log/Edit/BackButton.php create mode 100644 Block/Adminhtml/Log/Edit/DeleteButton.php create mode 100644 Block/Adminhtml/Log/Edit/GenericButton.php create mode 100644 Block/Adminhtml/Log/Edit/SaveAndContinueButton.php create mode 100644 Block/Adminhtml/Log/Edit/SaveButton.php create mode 100644 Block/Adminhtml/Report/Edit/BackButton.php create mode 100644 Block/Adminhtml/Report/Edit/DeleteButton.php create mode 100644 Block/Adminhtml/Report/Edit/GenericButton.php create mode 100644 Block/Adminhtml/Report/Edit/SaveAndContinueButton.php create mode 100644 Block/Adminhtml/Report/Edit/SaveButton.php create mode 100644 COPYING.txt create mode 100644 Console/Command/Export.php create mode 100644 Controller/Adminhtml/Log.php create mode 100644 Controller/Adminhtml/Log/Delete.php create mode 100644 Controller/Adminhtml/Log/Edit.php create mode 100644 Controller/Adminhtml/Log/Index.php create mode 100644 Controller/Adminhtml/Log/InlineEdit.php create mode 100644 Controller/Adminhtml/Log/NewAction.php create mode 100644 Controller/Adminhtml/Log/Save.php create mode 100644 Controller/Adminhtml/Report.php create mode 100644 Controller/Adminhtml/Report/Delete.php create mode 100644 Controller/Adminhtml/Report/Edit.php create mode 100644 Controller/Adminhtml/Report/Index.php create mode 100644 Controller/Adminhtml/Report/InlineEdit.php create mode 100644 Controller/Adminhtml/Report/NewAction.php create mode 100644 Controller/Adminhtml/Report/Save.php create mode 100644 Cron/DeleteFile.php create mode 100644 Cron/Email.php create mode 100644 Helper/Config.php create mode 100644 Helper/Export.php create mode 100644 Helper/Functions.php create mode 100644 LICENSE.txt create mode 100644 Model/Data/Log.php create mode 100644 Model/Data/Report.php create mode 100644 Model/ExportManagement.php create mode 100644 Model/Log.php create mode 100644 Model/Log/DataProvider.php create mode 100644 Model/LogRepository.php create mode 100644 Model/Report.php create mode 100644 Model/Report/DataProvider.php create mode 100644 Model/ReportRepository.php create mode 100644 Model/ReportsManagement.php create mode 100644 Model/ResourceModel/Log.php create mode 100644 Model/ResourceModel/Log/Collection.php create mode 100644 Model/ResourceModel/Report.php create mode 100644 Model/ResourceModel/Report/Collection.php create mode 100644 Observer/Export/ReportEnd.php create mode 100644 Observer/Export/ReportStart.php create mode 100644 README.md create mode 100644 Ui/Component/Listing/Column/LogActions.php create mode 100644 Ui/Component/Listing/Column/ReportActions.php create mode 100644 composer.json create mode 100644 etc/acl.xml create mode 100644 etc/adminhtml/menu.xml create mode 100644 etc/adminhtml/routes.xml create mode 100644 etc/adminhtml/system.xml create mode 100644 etc/config.xml create mode 100644 etc/cron_groups.xml create mode 100644 etc/crontab.xml create mode 100644 etc/db_schema.xml create mode 100644 etc/di.xml create mode 100644 etc/events.xml create mode 100644 etc/module.xml create mode 100644 etc/webapi.xml create mode 100644 i18n/en_US.csv create mode 100644 i18n/tr_TR.csv create mode 100644 registration.php create mode 100644 view/adminhtml/layout/kodhub_reporter_log_edit.xml create mode 100644 view/adminhtml/layout/kodhub_reporter_log_index.xml create mode 100644 view/adminhtml/layout/kodhub_reporter_log_new.xml create mode 100644 view/adminhtml/layout/kodhub_reporter_report_edit.xml create mode 100644 view/adminhtml/layout/kodhub_reporter_report_index.xml create mode 100644 view/adminhtml/layout/kodhub_reporter_report_new.xml create mode 100644 view/adminhtml/ui_component/kodhub_reporter_log_form.xml create mode 100644 view/adminhtml/ui_component/kodhub_reporter_log_listing.xml create mode 100644 view/adminhtml/ui_component/kodhub_reporter_report_form.xml create mode 100644 view/adminhtml/ui_component/kodhub_reporter_report_listing.xml diff --git a/Api/Data/LogInterface.php b/Api/Data/LogInterface.php new file mode 100644 index 0000000..824e942 --- /dev/null +++ b/Api/Data/LogInterface.php @@ -0,0 +1,197 @@ + __('Back'), + 'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()), + 'class' => 'back', + 'sort_order' => 10 + ]; + } + + /** + * Get URL for back (reset) button + * + * @return string + */ + public function getBackUrl() + { + return $this->getUrl('*/*/'); + } +} + diff --git a/Block/Adminhtml/Log/Edit/DeleteButton.php b/Block/Adminhtml/Log/Edit/DeleteButton.php new file mode 100644 index 0000000..dd997a9 --- /dev/null +++ b/Block/Adminhtml/Log/Edit/DeleteButton.php @@ -0,0 +1,44 @@ +getModelId()) { + $data = [ + 'label' => __('Delete Log'), + 'class' => 'delete', + 'on_click' => 'deleteConfirm(\'' . __( + 'Are you sure you want to do this?' + ) . '\', \'' . $this->getDeleteUrl() . '\')', + 'sort_order' => 20, + ]; + } + return $data; + } + + /** + * Get URL for delete button + * + * @return string + */ + public function getDeleteUrl() + { + return $this->getUrl('*/*/delete', ['log_id' => $this->getModelId()]); + } +} + diff --git a/Block/Adminhtml/Log/Edit/GenericButton.php b/Block/Adminhtml/Log/Edit/GenericButton.php new file mode 100644 index 0000000..f080269 --- /dev/null +++ b/Block/Adminhtml/Log/Edit/GenericButton.php @@ -0,0 +1,47 @@ +context = $context; + } + + /** + * Return model ID + * + * @return int|null + */ + public function getModelId() + { + return $this->context->getRequest()->getParam('log_id'); + } + + /** + * Generate url by route and parameters + * + * @param string $route + * @param array $params + * @return string + */ + public function getUrl($route = '', $params = []) + { + return $this->context->getUrlBuilder()->getUrl($route, $params); + } +} + diff --git a/Block/Adminhtml/Log/Edit/SaveAndContinueButton.php b/Block/Adminhtml/Log/Edit/SaveAndContinueButton.php new file mode 100644 index 0000000..c125547 --- /dev/null +++ b/Block/Adminhtml/Log/Edit/SaveAndContinueButton.php @@ -0,0 +1,32 @@ + __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => ['event' => 'saveAndContinueEdit'], + ], + ], + 'sort_order' => 80, + ]; + } +} + diff --git a/Block/Adminhtml/Log/Edit/SaveButton.php b/Block/Adminhtml/Log/Edit/SaveButton.php new file mode 100644 index 0000000..5804de2 --- /dev/null +++ b/Block/Adminhtml/Log/Edit/SaveButton.php @@ -0,0 +1,31 @@ + __('Save Log'), + 'class' => 'save primary', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save']], + 'form-role' => 'save', + ], + 'sort_order' => 90, + ]; + } +} + diff --git a/Block/Adminhtml/Report/Edit/BackButton.php b/Block/Adminhtml/Report/Edit/BackButton.php new file mode 100644 index 0000000..18b6240 --- /dev/null +++ b/Block/Adminhtml/Report/Edit/BackButton.php @@ -0,0 +1,38 @@ + __('Back'), + 'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()), + 'class' => 'back', + 'sort_order' => 10 + ]; + } + + /** + * Get URL for back (reset) button + * + * @return string + */ + public function getBackUrl() + { + return $this->getUrl('*/*/'); + } +} + diff --git a/Block/Adminhtml/Report/Edit/DeleteButton.php b/Block/Adminhtml/Report/Edit/DeleteButton.php new file mode 100644 index 0000000..97a402e --- /dev/null +++ b/Block/Adminhtml/Report/Edit/DeleteButton.php @@ -0,0 +1,44 @@ +getModelId()) { + $data = [ + 'label' => __('Delete Report'), + 'class' => 'delete', + 'on_click' => 'deleteConfirm(\'' . __( + 'Are you sure you want to do this?' + ) . '\', \'' . $this->getDeleteUrl() . '\')', + 'sort_order' => 20, + ]; + } + return $data; + } + + /** + * Get URL for delete button + * + * @return string + */ + public function getDeleteUrl() + { + return $this->getUrl('*/*/delete', ['report_id' => $this->getModelId()]); + } +} + diff --git a/Block/Adminhtml/Report/Edit/GenericButton.php b/Block/Adminhtml/Report/Edit/GenericButton.php new file mode 100644 index 0000000..18be4a7 --- /dev/null +++ b/Block/Adminhtml/Report/Edit/GenericButton.php @@ -0,0 +1,47 @@ +context = $context; + } + + /** + * Return model ID + * + * @return int|null + */ + public function getModelId() + { + return $this->context->getRequest()->getParam('report_id'); + } + + /** + * Generate url by route and parameters + * + * @param string $route + * @param array $params + * @return string + */ + public function getUrl($route = '', $params = []) + { + return $this->context->getUrlBuilder()->getUrl($route, $params); + } +} + diff --git a/Block/Adminhtml/Report/Edit/SaveAndContinueButton.php b/Block/Adminhtml/Report/Edit/SaveAndContinueButton.php new file mode 100644 index 0000000..ef0f3cd --- /dev/null +++ b/Block/Adminhtml/Report/Edit/SaveAndContinueButton.php @@ -0,0 +1,32 @@ + __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => ['event' => 'saveAndContinueEdit'], + ], + ], + 'sort_order' => 80, + ]; + } +} + diff --git a/Block/Adminhtml/Report/Edit/SaveButton.php b/Block/Adminhtml/Report/Edit/SaveButton.php new file mode 100644 index 0000000..e9900a2 --- /dev/null +++ b/Block/Adminhtml/Report/Edit/SaveButton.php @@ -0,0 +1,31 @@ + __('Save Report'), + 'class' => 'save primary', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save']], + 'form-role' => 'save', + ], + 'sort_order' => 90, + ]; + } +} + diff --git a/COPYING.txt b/COPYING.txt new file mode 100644 index 0000000..f7fce5d --- /dev/null +++ b/COPYING.txt @@ -0,0 +1,19 @@ +Copyright © 2020-present ismail cakir + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Console/Command/Export.php b/Console/Command/Export.php new file mode 100644 index 0000000..ad5f6b5 --- /dev/null +++ b/Console/Command/Export.php @@ -0,0 +1,48 @@ +getArgument(self::NAME_ARGUMENT); + $option = $input->getOption(self::NAME_OPTION); + $output->writeln("Hello " . $name); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName("kodhub_reporter:export"); + $this->setDescription("Export your Report"); + $this->setDefinition([ + new InputArgument(self::NAME_ARGUMENT, InputArgument::OPTIONAL, "Name"), + new InputOption(self::NAME_OPTION, "-a", InputOption::VALUE_NONE, "Option functionality") + ]); + parent::configure(); + } +} + diff --git a/Controller/Adminhtml/Log.php b/Controller/Adminhtml/Log.php new file mode 100644 index 0000000..f6d78be --- /dev/null +++ b/Controller/Adminhtml/Log.php @@ -0,0 +1,42 @@ +_coreRegistry = $coreRegistry; + parent::__construct($context); + } + + /** + * Init page + * + * @param \Magento\Backend\Model\View\Result\Page $resultPage + * @return \Magento\Backend\Model\View\Result\Page + */ + public function initPage($resultPage) + { + $resultPage->setActiveMenu(self::ADMIN_RESOURCE) + ->addBreadcrumb(__('Kodhub'), __('Kodhub')) + ->addBreadcrumb(__('Log'), __('Log')); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Log/Delete.php b/Controller/Adminhtml/Log/Delete.php new file mode 100644 index 0000000..2d9a690 --- /dev/null +++ b/Controller/Adminhtml/Log/Delete.php @@ -0,0 +1,47 @@ +resultRedirectFactory->create(); + // check if we know what should be deleted + $id = $this->getRequest()->getParam('log_id'); + if ($id) { + try { + // init model and delete + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Log::class); + $model->load($id); + $model->delete(); + // display success message + $this->messageManager->addSuccessMessage(__('You deleted the Log.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } catch (\Exception $e) { + // display error message + $this->messageManager->addErrorMessage($e->getMessage()); + // go back to edit form + return $resultRedirect->setPath('*/*/edit', ['log_id' => $id]); + } + } + // display error message + $this->messageManager->addErrorMessage(__('We can\'t find a Log to delete.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } +} + diff --git a/Controller/Adminhtml/Log/Edit.php b/Controller/Adminhtml/Log/Edit.php new file mode 100644 index 0000000..fb063ed --- /dev/null +++ b/Controller/Adminhtml/Log/Edit.php @@ -0,0 +1,64 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * Edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + // 1. Get ID and create model + $id = $this->getRequest()->getParam('log_id'); + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Log::class); + + // 2. Initial checking + if ($id) { + $model->load($id); + if (!$model->getId()) { + $this->messageManager->addErrorMessage(__('This Log no longer exists.')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*/'); + } + } + $this->_coreRegistry->register('kodhub_reporter_log', $model); + + // 3. Build edit form + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $this->initPage($resultPage)->addBreadcrumb( + $id ? __('Edit Log') : __('New Log'), + $id ? __('Edit Log') : __('New Log') + ); + $resultPage->getConfig()->getTitle()->prepend(__('Logs')); + $resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Log %1', $model->getId()) : __('New Log')); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Log/Index.php b/Controller/Adminhtml/Log/Index.php new file mode 100644 index 0000000..04de87d --- /dev/null +++ b/Controller/Adminhtml/Log/Index.php @@ -0,0 +1,41 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + + /** + * Index action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__("Log")); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Log/InlineEdit.php b/Controller/Adminhtml/Log/InlineEdit.php new file mode 100644 index 0000000..23c3499 --- /dev/null +++ b/Controller/Adminhtml/Log/InlineEdit.php @@ -0,0 +1,65 @@ +jsonFactory = $jsonFactory; + } + + /** + * Inline edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->jsonFactory->create(); + $error = false; + $messages = []; + + if ($this->getRequest()->getParam('isAjax')) { + $postItems = $this->getRequest()->getParam('items', []); + if (!count($postItems)) { + $messages[] = __('Please correct the data sent.'); + $error = true; + } else { + foreach (array_keys($postItems) as $modelid) { + /** @var \Kodhub\Reporter\Model\Log $model */ + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Log::class)->load($modelid); + try { + $model->setData(array_merge($model->getData(), $postItems[$modelid])); + $model->save(); + } catch (\Exception $e) { + $messages[] = "[Log ID: {$modelid}] {$e->getMessage()}"; + $error = true; + } + } + } + } + + return $resultJson->setData([ + 'messages' => $messages, + 'error' => $error + ]); + } +} + diff --git a/Controller/Adminhtml/Log/NewAction.php b/Controller/Adminhtml/Log/NewAction.php new file mode 100644 index 0000000..fefc1c2 --- /dev/null +++ b/Controller/Adminhtml/Log/NewAction.php @@ -0,0 +1,41 @@ +resultForwardFactory = $resultForwardFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * New action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('edit'); + } +} + diff --git a/Controller/Adminhtml/Log/Save.php b/Controller/Adminhtml/Log/Save.php new file mode 100644 index 0000000..3fbf0f6 --- /dev/null +++ b/Controller/Adminhtml/Log/Save.php @@ -0,0 +1,71 @@ +dataPersistor = $dataPersistor; + parent::__construct($context); + } + + /** + * Save action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $data = $this->getRequest()->getPostValue(); + if ($data) { + $id = $this->getRequest()->getParam('log_id'); + + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Log::class)->load($id); + if (!$model->getId() && $id) { + $this->messageManager->addErrorMessage(__('This Log no longer exists.')); + return $resultRedirect->setPath('*/*/'); + } + + $model->setData($data); + + try { + $model->save(); + $this->messageManager->addSuccessMessage(__('You saved the Log.')); + $this->dataPersistor->clear('kodhub_reporter_log'); + + if ($this->getRequest()->getParam('back')) { + return $resultRedirect->setPath('*/*/edit', ['log_id' => $model->getId()]); + } + return $resultRedirect->setPath('*/*/'); + } catch (LocalizedException $e) { + $this->messageManager->addErrorMessage($e->getMessage()); + } catch (\Exception $e) { + $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Log.')); + } + + $this->dataPersistor->set('kodhub_reporter_log', $data); + return $resultRedirect->setPath('*/*/edit', ['log_id' => $this->getRequest()->getParam('log_id')]); + } + return $resultRedirect->setPath('*/*/'); + } +} + diff --git a/Controller/Adminhtml/Report.php b/Controller/Adminhtml/Report.php new file mode 100644 index 0000000..437cd2e --- /dev/null +++ b/Controller/Adminhtml/Report.php @@ -0,0 +1,42 @@ +_coreRegistry = $coreRegistry; + parent::__construct($context); + } + + /** + * Init page + * + * @param \Magento\Backend\Model\View\Result\Page $resultPage + * @return \Magento\Backend\Model\View\Result\Page + */ + public function initPage($resultPage) + { + $resultPage->setActiveMenu(self::ADMIN_RESOURCE) + ->addBreadcrumb(__('Kodhub'), __('Kodhub')) + ->addBreadcrumb(__('Report'), __('Report')); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Report/Delete.php b/Controller/Adminhtml/Report/Delete.php new file mode 100644 index 0000000..d04ee2c --- /dev/null +++ b/Controller/Adminhtml/Report/Delete.php @@ -0,0 +1,47 @@ +resultRedirectFactory->create(); + // check if we know what should be deleted + $id = $this->getRequest()->getParam('report_id'); + if ($id) { + try { + // init model and delete + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Report::class); + $model->load($id); + $model->delete(); + // display success message + $this->messageManager->addSuccessMessage(__('You deleted the Report.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } catch (\Exception $e) { + // display error message + $this->messageManager->addErrorMessage($e->getMessage()); + // go back to edit form + return $resultRedirect->setPath('*/*/edit', ['report_id' => $id]); + } + } + // display error message + $this->messageManager->addErrorMessage(__('We can\'t find a Report to delete.')); + // go to grid + return $resultRedirect->setPath('*/*/'); + } +} + diff --git a/Controller/Adminhtml/Report/Edit.php b/Controller/Adminhtml/Report/Edit.php new file mode 100644 index 0000000..d031239 --- /dev/null +++ b/Controller/Adminhtml/Report/Edit.php @@ -0,0 +1,64 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * Edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + // 1. Get ID and create model + $id = $this->getRequest()->getParam('report_id'); + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Report::class); + + // 2. Initial checking + if ($id) { + $model->load($id); + if (!$model->getId()) { + $this->messageManager->addErrorMessage(__('This Report no longer exists.')); + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + return $resultRedirect->setPath('*/*/'); + } + } + $this->_coreRegistry->register('kodhub_reporter_report', $model); + + // 3. Build edit form + /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ + $resultPage = $this->resultPageFactory->create(); + $this->initPage($resultPage)->addBreadcrumb( + $id ? __('Edit Report') : __('New Report'), + $id ? __('Edit Report') : __('New Report') + ); + $resultPage->getConfig()->getTitle()->prepend(__('Reports')); + $resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Report %1', $model->getId()) : __('New Report')); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Report/Index.php b/Controller/Adminhtml/Report/Index.php new file mode 100644 index 0000000..8fba11f --- /dev/null +++ b/Controller/Adminhtml/Report/Index.php @@ -0,0 +1,41 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + + /** + * Index action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__("Report")); + return $resultPage; + } +} + diff --git a/Controller/Adminhtml/Report/InlineEdit.php b/Controller/Adminhtml/Report/InlineEdit.php new file mode 100644 index 0000000..3e87715 --- /dev/null +++ b/Controller/Adminhtml/Report/InlineEdit.php @@ -0,0 +1,65 @@ +jsonFactory = $jsonFactory; + } + + /** + * Inline edit action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + $resultJson = $this->jsonFactory->create(); + $error = false; + $messages = []; + + if ($this->getRequest()->getParam('isAjax')) { + $postItems = $this->getRequest()->getParam('items', []); + if (!count($postItems)) { + $messages[] = __('Please correct the data sent.'); + $error = true; + } else { + foreach (array_keys($postItems) as $modelid) { + /** @var \Kodhub\Reporter\Model\Report $model */ + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Report::class)->load($modelid); + try { + $model->setData(array_merge($model->getData(), $postItems[$modelid])); + $model->save(); + } catch (\Exception $e) { + $messages[] = "[Report ID: {$modelid}] {$e->getMessage()}"; + $error = true; + } + } + } + } + + return $resultJson->setData([ + 'messages' => $messages, + 'error' => $error + ]); + } +} + diff --git a/Controller/Adminhtml/Report/NewAction.php b/Controller/Adminhtml/Report/NewAction.php new file mode 100644 index 0000000..a143aa7 --- /dev/null +++ b/Controller/Adminhtml/Report/NewAction.php @@ -0,0 +1,41 @@ +resultForwardFactory = $resultForwardFactory; + parent::__construct($context, $coreRegistry); + } + + /** + * New action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ + $resultForward = $this->resultForwardFactory->create(); + return $resultForward->forward('edit'); + } +} + diff --git a/Controller/Adminhtml/Report/Save.php b/Controller/Adminhtml/Report/Save.php new file mode 100644 index 0000000..de884d9 --- /dev/null +++ b/Controller/Adminhtml/Report/Save.php @@ -0,0 +1,71 @@ +dataPersistor = $dataPersistor; + parent::__construct($context); + } + + /** + * Save action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultRedirectFactory->create(); + $data = $this->getRequest()->getPostValue(); + if ($data) { + $id = $this->getRequest()->getParam('report_id'); + + $model = $this->_objectManager->create(\Kodhub\Reporter\Model\Report::class)->load($id); + if (!$model->getId() && $id) { + $this->messageManager->addErrorMessage(__('This Report no longer exists.')); + return $resultRedirect->setPath('*/*/'); + } + + $model->setData($data); + + try { + $model->save(); + $this->messageManager->addSuccessMessage(__('You saved the Report.')); + $this->dataPersistor->clear('kodhub_reporter_report'); + + if ($this->getRequest()->getParam('back')) { + return $resultRedirect->setPath('*/*/edit', ['report_id' => $model->getId()]); + } + return $resultRedirect->setPath('*/*/'); + } catch (LocalizedException $e) { + $this->messageManager->addErrorMessage($e->getMessage()); + } catch (\Exception $e) { + $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Report.')); + } + + $this->dataPersistor->set('kodhub_reporter_report', $data); + return $resultRedirect->setPath('*/*/edit', ['report_id' => $this->getRequest()->getParam('report_id')]); + } + return $resultRedirect->setPath('*/*/'); + } +} + diff --git a/Cron/DeleteFile.php b/Cron/DeleteFile.php new file mode 100644 index 0000000..7498f3c --- /dev/null +++ b/Cron/DeleteFile.php @@ -0,0 +1,35 @@ +logger = $logger; + } + + /** + * Execute the cron + * + * @return void + */ + public function execute() + { + $this->logger->addInfo("Cronjob DeleteFile is executed."); + } +} + diff --git a/Cron/Email.php b/Cron/Email.php new file mode 100644 index 0000000..d1383a3 --- /dev/null +++ b/Cron/Email.php @@ -0,0 +1,35 @@ +logger = $logger; + } + + /** + * Execute the cron + * + * @return void + */ + public function execute() + { + $this->logger->addInfo("Cronjob Email is executed."); + } +} + diff --git a/Helper/Config.php b/Helper/Config.php new file mode 100644 index 0000000..a1a07ab --- /dev/null +++ b/Helper/Config.php @@ -0,0 +1,32 @@ +_get(self::LOG_ID); + } + + /** + * Set log_id + * @param string $logId + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setLogId($logId) + { + return $this->setData(self::LOG_ID, $logId); + } + + /** + * Get title + * @return string|null + */ + public function getTitle() + { + return $this->_get(self::TITLE); + } + + /** + * Set title + * @param string $title + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setTitle($title) + { + return $this->setData(self::TITLE, $title); + } + + /** + * Retrieve existing extension attributes object or create a new one. + * @return \Kodhub\Reporter\Api\Data\LogExtensionInterface|null + */ + public function getExtensionAttributes() + { + return $this->_getExtensionAttributes(); + } + + /** + * Set an extension attributes object. + * @param \Kodhub\Reporter\Api\Data\LogExtensionInterface $extensionAttributes + * @return $this + */ + public function setExtensionAttributes( + \Kodhub\Reporter\Api\Data\LogExtensionInterface $extensionAttributes + ) { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * Get message + * @return string|null + */ + public function getMessage() + { + return $this->_get(self::MESSAGE); + } + + /** + * Set message + * @param string $message + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setMessage($message) + { + return $this->setData(self::MESSAGE, $message); + } + + /** + * Get error + * @return string|null + */ + public function getError() + { + return $this->_get(self::ERROR); + } + + /** + * Set error + * @param string $error + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setError($error) + { + return $this->setData(self::ERROR, $error); + } + + /** + * Get trace + * @return string|null + */ + public function getTrace() + { + return $this->_get(self::TRACE); + } + + /** + * Set trace + * @param string $trace + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setTrace($trace) + { + return $this->setData(self::TRACE, $trace); + } + + /** + * Get query + * @return string|null + */ + public function getQuery() + { + return $this->_get(self::QUERY); + } + + /** + * Set query + * @param string $query + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setQuery($query) + { + return $this->setData(self::QUERY, $query); + } + + /** + * Get sent_list + * @return string|null + */ + public function getSentList() + { + return $this->_get(self::SENT_LIST); + } + + /** + * Set sent_list + * @param string $sentList + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setSentList($sentList) + { + return $this->setData(self::SENT_LIST, $sentList); + } + + /** + * Get cron_is_run + * @return string|null + */ + public function getCronIsRun() + { + return $this->_get(self::CRON_IS_RUN); + } + + /** + * Set cron_is_run + * @param string $cronIsRun + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setCronIsRun($cronIsRun) + { + return $this->setData(self::CRON_IS_RUN, $cronIsRun); + } + + /** + * Get last_run_date + * @return string|null + */ + public function getLastRunDate() + { + return $this->_get(self::LAST_RUN_DATE); + } + + /** + * Set last_run_date + * @param string $lastRunDate + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setLastRunDate($lastRunDate) + { + return $this->setData(self::LAST_RUN_DATE, $lastRunDate); + } + + /** + * Get work_time + * @return string|null + */ + public function getWorkTime() + { + return $this->_get(self::WORK_TIME); + } + + /** + * Set work_time + * @param string $workTime + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setWorkTime($workTime) + { + return $this->setData(self::WORK_TIME, $workTime); + } + + /** + * Get started_at + * @return string|null + */ + public function getStartedAt() + { + return $this->_get(self::STARTED_AT); + } + + /** + * Set started_at + * @param string $startedAt + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setStartedAt($startedAt) + { + return $this->setData(self::STARTED_AT, $startedAt); + } + + /** + * Get ended_at + * @return string|null + */ + public function getEndedAt() + { + return $this->_get(self::ENDED_AT); + } + + /** + * Set ended_at + * @param string $endedAt + * @return \Kodhub\Reporter\Api\Data\LogInterface + */ + public function setEndedAt($endedAt) + { + return $this->setData(self::ENDED_AT, $endedAt); + } +} + diff --git a/Model/Data/Report.php b/Model/Data/Report.php new file mode 100644 index 0000000..b9c61e2 --- /dev/null +++ b/Model/Data/Report.php @@ -0,0 +1,225 @@ +_get(self::REPORT_ID); + } + + /** + * Set report_id + * @param string $reportId + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setReportId($reportId) + { + return $this->setData(self::REPORT_ID, $reportId); + } + + /** + * Get name + * @return string|null + */ + public function getName() + { + return $this->_get(self::NAME); + } + + /** + * Set name + * @param string $name + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setName($name) + { + return $this->setData(self::NAME, $name); + } + + /** + * Retrieve existing extension attributes object or create a new one. + * @return \Kodhub\Reporter\Api\Data\ReportExtensionInterface|null + */ + public function getExtensionAttributes() + { + return $this->_getExtensionAttributes(); + } + + /** + * Set an extension attributes object. + * @param \Kodhub\Reporter\Api\Data\ReportExtensionInterface $extensionAttributes + * @return $this + */ + public function setExtensionAttributes( + \Kodhub\Reporter\Api\Data\ReportExtensionInterface $extensionAttributes + ) { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * Get query + * @return string|null + */ + public function getQuery() + { + return $this->_get(self::QUERY); + } + + /** + * Set query + * @param string $query + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setQuery($query) + { + return $this->setData(self::QUERY, $query); + } + + /** + * Get cron_status + * @return string|null + */ + public function getCronStatus() + { + return $this->_get(self::CRON_STATUS); + } + + /** + * Set cron_status + * @param string $cronStatus + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setCronStatus($cronStatus) + { + return $this->setData(self::CRON_STATUS, $cronStatus); + } + + /** + * Get cron_email_list + * @return string|null + */ + public function getCronEmailList() + { + return $this->_get(self::CRON_EMAIL_LIST); + } + + /** + * Set cron_email_list + * @param string $cronEmailList + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setCronEmailList($cronEmailList) + { + return $this->setData(self::CRON_EMAIL_LIST, $cronEmailList); + } + + /** + * Get cron_expression + * @return string|null + */ + public function getCronExpression() + { + return $this->_get(self::CRON_EXPRESSION); + } + + /** + * Set cron_expression + * @param string $cronExpression + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setCronExpression($cronExpression) + { + return $this->setData(self::CRON_EXPRESSION, $cronExpression); + } + + /** + * Get description + * @return string|null + */ + public function getDescription() + { + return $this->_get(self::DESCRIPTION); + } + + /** + * Set description + * @param string $description + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setDescription($description) + { + return $this->setData(self::DESCRIPTION, $description); + } + + /** + * Get status + * @return string|null + */ + public function getStatus() + { + return $this->_get(self::STATUS); + } + + /** + * Set status + * @param string $status + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setStatus($status) + { + return $this->setData(self::STATUS, $status); + } + + /** + * Get created_at + * @return string|null + */ + public function getCreatedAt() + { + return $this->_get(self::CREATED_AT); + } + + /** + * Set created_at + * @param string $createdAt + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setCreatedAt($createdAt) + { + return $this->setData(self::CREATED_AT, $createdAt); + } + + /** + * Get updated_at + * @return string|null + */ + public function getUpdatedAt() + { + return $this->_get(self::UPDATED_AT); + } + + /** + * Set updated_at + * @param string $updatedAt + * @return \Kodhub\Reporter\Api\Data\ReportInterface + */ + public function setUpdatedAt($updatedAt) + { + return $this->setData(self::UPDATED_AT, $updatedAt); + } +} + diff --git a/Model/ExportManagement.php b/Model/ExportManagement.php new file mode 100644 index 0000000..34eedc2 --- /dev/null +++ b/Model/ExportManagement.php @@ -0,0 +1,21 @@ +logDataFactory = $logDataFactory; + $this->dataObjectHelper = $dataObjectHelper; + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + } + + /** + * Retrieve log model with log data + * @return LogInterface + */ + public function getDataModel() + { + $logData = $this->getData(); + + $logDataObject = $this->logDataFactory->create(); + $this->dataObjectHelper->populateWithArray( + $logDataObject, + $logData, + LogInterface::class + ); + + return $logDataObject; + } +} + diff --git a/Model/Log/DataProvider.php b/Model/Log/DataProvider.php new file mode 100644 index 0000000..72d51aa --- /dev/null +++ b/Model/Log/DataProvider.php @@ -0,0 +1,73 @@ +collection = $collectionFactory->create(); + $this->dataPersistor = $dataPersistor; + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + if (isset($this->loadedData)) { + return $this->loadedData; + } + $items = $this->collection->getItems(); + foreach ($items as $model) { + $this->loadedData[$model->getId()] = $model->getData(); + } + $data = $this->dataPersistor->get('kodhub_reporter_log'); + + if (!empty($data)) { + $model = $this->collection->getNewEmptyItem(); + $model->setData($data); + $this->loadedData[$model->getId()] = $model->getData(); + $this->dataPersistor->clear('kodhub_reporter_log'); + } + + return $this->loadedData; + } +} + diff --git a/Model/LogRepository.php b/Model/LogRepository.php new file mode 100644 index 0000000..9a348de --- /dev/null +++ b/Model/LogRepository.php @@ -0,0 +1,187 @@ +resource = $resource; + $this->logFactory = $logFactory; + $this->logCollectionFactory = $logCollectionFactory; + $this->searchResultsFactory = $searchResultsFactory; + $this->dataObjectHelper = $dataObjectHelper; + $this->dataLogFactory = $dataLogFactory; + $this->dataObjectProcessor = $dataObjectProcessor; + $this->storeManager = $storeManager; + $this->collectionProcessor = $collectionProcessor; + $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; + $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; + } + + /** + * {@inheritdoc} + */ + public function save( + \Kodhub\Reporter\Api\Data\LogInterface $log + ) { + /* if (empty($log->getStoreId())) { + $storeId = $this->storeManager->getStore()->getId(); + $log->setStoreId($storeId); + } */ + + $logData = $this->extensibleDataObjectConverter->toNestedArray( + $log, + [], + \Kodhub\Reporter\Api\Data\LogInterface::class + ); + + $logModel = $this->logFactory->create()->setData($logData); + + try { + $this->resource->save($logModel); + } catch (\Exception $exception) { + throw new CouldNotSaveException(__( + 'Could not save the log: %1', + $exception->getMessage() + )); + } + return $logModel->getDataModel(); + } + + /** + * {@inheritdoc} + */ + public function get($logId) + { + $log = $this->logFactory->create(); + $this->resource->load($log, $logId); + if (!$log->getId()) { + throw new NoSuchEntityException(__('Log with id "%1" does not exist.', $logId)); + } + return $log->getDataModel(); + } + + /** + * {@inheritdoc} + */ + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $criteria + ) { + $collection = $this->logCollectionFactory->create(); + + $this->extensionAttributesJoinProcessor->process( + $collection, + \Kodhub\Reporter\Api\Data\LogInterface::class + ); + + $this->collectionProcessor->process($criteria, $collection); + + $searchResults = $this->searchResultsFactory->create(); + $searchResults->setSearchCriteria($criteria); + + $items = []; + foreach ($collection as $model) { + $items[] = $model->getDataModel(); + } + + $searchResults->setItems($items); + $searchResults->setTotalCount($collection->getSize()); + return $searchResults; + } + + /** + * {@inheritdoc} + */ + public function delete( + \Kodhub\Reporter\Api\Data\LogInterface $log + ) { + try { + $logModel = $this->logFactory->create(); + $this->resource->load($logModel, $log->getLogId()); + $this->resource->delete($logModel); + } catch (\Exception $exception) { + throw new CouldNotDeleteException(__( + 'Could not delete the Log: %1', + $exception->getMessage() + )); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($logId) + { + return $this->delete($this->get($logId)); + } +} + diff --git a/Model/Report.php b/Model/Report.php new file mode 100644 index 0000000..120f4ae --- /dev/null +++ b/Model/Report.php @@ -0,0 +1,64 @@ +reportDataFactory = $reportDataFactory; + $this->dataObjectHelper = $dataObjectHelper; + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + } + + /** + * Retrieve report model with report data + * @return ReportInterface + */ + public function getDataModel() + { + $reportData = $this->getData(); + + $reportDataObject = $this->reportDataFactory->create(); + $this->dataObjectHelper->populateWithArray( + $reportDataObject, + $reportData, + ReportInterface::class + ); + + return $reportDataObject; + } +} + diff --git a/Model/Report/DataProvider.php b/Model/Report/DataProvider.php new file mode 100644 index 0000000..daf3f88 --- /dev/null +++ b/Model/Report/DataProvider.php @@ -0,0 +1,73 @@ +collection = $collectionFactory->create(); + $this->dataPersistor = $dataPersistor; + parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); + } + + /** + * Get data + * + * @return array + */ + public function getData() + { + if (isset($this->loadedData)) { + return $this->loadedData; + } + $items = $this->collection->getItems(); + foreach ($items as $model) { + $this->loadedData[$model->getId()] = $model->getData(); + } + $data = $this->dataPersistor->get('kodhub_reporter_report'); + + if (!empty($data)) { + $model = $this->collection->getNewEmptyItem(); + $model->setData($data); + $this->loadedData[$model->getId()] = $model->getData(); + $this->dataPersistor->clear('kodhub_reporter_report'); + } + + return $this->loadedData; + } +} + diff --git a/Model/ReportRepository.php b/Model/ReportRepository.php new file mode 100644 index 0000000..35259ed --- /dev/null +++ b/Model/ReportRepository.php @@ -0,0 +1,187 @@ +resource = $resource; + $this->reportFactory = $reportFactory; + $this->reportCollectionFactory = $reportCollectionFactory; + $this->searchResultsFactory = $searchResultsFactory; + $this->dataObjectHelper = $dataObjectHelper; + $this->dataReportFactory = $dataReportFactory; + $this->dataObjectProcessor = $dataObjectProcessor; + $this->storeManager = $storeManager; + $this->collectionProcessor = $collectionProcessor; + $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; + $this->extensibleDataObjectConverter = $extensibleDataObjectConverter; + } + + /** + * {@inheritdoc} + */ + public function save( + \Kodhub\Reporter\Api\Data\ReportInterface $report + ) { + /* if (empty($report->getStoreId())) { + $storeId = $this->storeManager->getStore()->getId(); + $report->setStoreId($storeId); + } */ + + $reportData = $this->extensibleDataObjectConverter->toNestedArray( + $report, + [], + \Kodhub\Reporter\Api\Data\ReportInterface::class + ); + + $reportModel = $this->reportFactory->create()->setData($reportData); + + try { + $this->resource->save($reportModel); + } catch (\Exception $exception) { + throw new CouldNotSaveException(__( + 'Could not save the report: %1', + $exception->getMessage() + )); + } + return $reportModel->getDataModel(); + } + + /** + * {@inheritdoc} + */ + public function get($reportId) + { + $report = $this->reportFactory->create(); + $this->resource->load($report, $reportId); + if (!$report->getId()) { + throw new NoSuchEntityException(__('Report with id "%1" does not exist.', $reportId)); + } + return $report->getDataModel(); + } + + /** + * {@inheritdoc} + */ + public function getList( + \Magento\Framework\Api\SearchCriteriaInterface $criteria + ) { + $collection = $this->reportCollectionFactory->create(); + + $this->extensionAttributesJoinProcessor->process( + $collection, + \Kodhub\Reporter\Api\Data\ReportInterface::class + ); + + $this->collectionProcessor->process($criteria, $collection); + + $searchResults = $this->searchResultsFactory->create(); + $searchResults->setSearchCriteria($criteria); + + $items = []; + foreach ($collection as $model) { + $items[] = $model->getDataModel(); + } + + $searchResults->setItems($items); + $searchResults->setTotalCount($collection->getSize()); + return $searchResults; + } + + /** + * {@inheritdoc} + */ + public function delete( + \Kodhub\Reporter\Api\Data\ReportInterface $report + ) { + try { + $reportModel = $this->reportFactory->create(); + $this->resource->load($reportModel, $report->getReportId()); + $this->resource->delete($reportModel); + } catch (\Exception $exception) { + throw new CouldNotDeleteException(__( + 'Could not delete the Report: %1', + $exception->getMessage() + )); + } + return true; + } + + /** + * {@inheritdoc} + */ + public function deleteById($reportId) + { + return $this->delete($this->get($reportId)); + } +} + diff --git a/Model/ReportsManagement.php b/Model/ReportsManagement.php new file mode 100644 index 0000000..6398469 --- /dev/null +++ b/Model/ReportsManagement.php @@ -0,0 +1,21 @@ +_init('kodhub_reporter_log', 'log_id'); + } +} + diff --git a/Model/ResourceModel/Log/Collection.php b/Model/ResourceModel/Log/Collection.php new file mode 100644 index 0000000..5123f50 --- /dev/null +++ b/Model/ResourceModel/Log/Collection.php @@ -0,0 +1,31 @@ +_init( + \Kodhub\Reporter\Model\Log::class, + \Kodhub\Reporter\Model\ResourceModel\Log::class + ); + } +} + diff --git a/Model/ResourceModel/Report.php b/Model/ResourceModel/Report.php new file mode 100644 index 0000000..a746fb8 --- /dev/null +++ b/Model/ResourceModel/Report.php @@ -0,0 +1,23 @@ +_init('kodhub_reporter_report', 'report_id'); + } +} + diff --git a/Model/ResourceModel/Report/Collection.php b/Model/ResourceModel/Report/Collection.php new file mode 100644 index 0000000..622787e --- /dev/null +++ b/Model/ResourceModel/Report/Collection.php @@ -0,0 +1,31 @@ +_init( + \Kodhub\Reporter\Model\Report::class, + \Kodhub\Reporter\Model\ResourceModel\Report::class + ); + } +} + diff --git a/Observer/Export/ReportEnd.php b/Observer/Export/ReportEnd.php new file mode 100644 index 0000000..42c5f74 --- /dev/null +++ b/Observer/Export/ReportEnd.php @@ -0,0 +1,25 @@ + Kodhub\Reporter\Model\ExportManagement + + - API Endpoint + - GET - Kodhub\Reporter\Api\ReportsManagementInterface > Kodhub\Reporter\Model\ReportsManagement + + - Cronjob + - kodhub_reporter_email + + - Cronjob + - kodhub_reporter_deletefile + + - Helper + - Kodhub\Reporter\Helper\Export + + - Helper + - Kodhub\Reporter\Helper\Config + + - Helper + - Kodhub\Reporter\Helper\Functions + + - Crongroup + - kodhub + + - Observer + - export_report_start > Kodhub\Reporter\Observer\Export\ReportStart + + - Observer + - export_report_end > Kodhub\Reporter\Observer\Export\ReportEnd + + - Console Command + - Export + + - Model + - Report + + - Model + - Log + + +## Attributes + + + diff --git a/Ui/Component/Listing/Column/LogActions.php b/Ui/Component/Listing/Column/LogActions.php new file mode 100644 index 0000000..ddc3813 --- /dev/null +++ b/Ui/Component/Listing/Column/LogActions.php @@ -0,0 +1,78 @@ +urlBuilder = $urlBuilder; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare Data Source + * + * @param array $dataSource + * @return array + */ + public function prepareDataSource(array $dataSource) + { + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as & $item) { + if (isset($item['log_id'])) { + $item[$this->getData('name')] = [ + 'edit' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_EDIT, + [ + 'log_id' => $item['log_id'] + ] + ), + 'label' => __('Edit') + ], + 'delete' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_DELETE, + [ + 'log_id' => $item['log_id'] + ] + ), + 'label' => __('Delete'), + 'confirm' => [ + 'title' => __('Delete "${ $.$data.title }"'), + 'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?') + ] + ] + ]; + } + } + } + + return $dataSource; + } +} + diff --git a/Ui/Component/Listing/Column/ReportActions.php b/Ui/Component/Listing/Column/ReportActions.php new file mode 100644 index 0000000..772335a --- /dev/null +++ b/Ui/Component/Listing/Column/ReportActions.php @@ -0,0 +1,78 @@ +urlBuilder = $urlBuilder; + parent::__construct($context, $uiComponentFactory, $components, $data); + } + + /** + * Prepare Data Source + * + * @param array $dataSource + * @return array + */ + public function prepareDataSource(array $dataSource) + { + if (isset($dataSource['data']['items'])) { + foreach ($dataSource['data']['items'] as & $item) { + if (isset($item['report_id'])) { + $item[$this->getData('name')] = [ + 'edit' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_EDIT, + [ + 'report_id' => $item['report_id'] + ] + ), + 'label' => __('Edit') + ], + 'delete' => [ + 'href' => $this->urlBuilder->getUrl( + static::URL_PATH_DELETE, + [ + 'report_id' => $item['report_id'] + ] + ), + 'label' => __('Delete'), + 'confirm' => [ + 'title' => __('Delete "${ $.$data.title }"'), + 'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?') + ] + ] + ]; + } + } + } + + return $dataSource; + } +} + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bf3b12b --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "kodhub/module-reporter", + "description": "Reporter module for magento 2.4", + "type": "magento2-module", + "license": "MIT", + "authors": [ + { + "email": "ismailcakirnet@gmail.com", + "name": "ismail çakır" + } + ], + "minimum-stability": "dev", + "require": { + "kodhub/module-core": "~1.0.1" + }, + "autoload": { + "psr-4": { + "Kodhub\\Reporter\\": "" + }, + "files": [ + "registration.php" + ] + } +} diff --git a/etc/acl.xml b/etc/acl.xml new file mode 100644 index 0000000..aa41596 --- /dev/null +++ b/etc/acl.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml new file mode 100644 index 0000000..cb8992f --- /dev/null +++ b/etc/adminhtml/menu.xml @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/etc/adminhtml/routes.xml b/etc/adminhtml/routes.xml new file mode 100644 index 0000000..4299758 --- /dev/null +++ b/etc/adminhtml/routes.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..7192e48 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,35 @@ + + + +
+ + kodhub + Kodhub_Reporter::config_kodhub_reporter + + + + + + Magento\Config\Model\Config\Source\Enabledisable + + + + + + + + Magento\Config\Model\Config\Source\Enabledisable + + + + + Magento\Config\Model\Config\Source\Enabledisable + + + + + + +
+
+
diff --git a/etc/config.xml b/etc/config.xml new file mode 100644 index 0000000..9376c38 --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/etc/cron_groups.xml b/etc/cron_groups.xml new file mode 100644 index 0000000..703912d --- /dev/null +++ b/etc/cron_groups.xml @@ -0,0 +1,12 @@ + + + + 1 + 1 + 15 + 1 + 60 + 4320 + 1 + + diff --git a/etc/crontab.xml b/etc/crontab.xml new file mode 100644 index 0000000..0c7fc2b --- /dev/null +++ b/etc/crontab.xml @@ -0,0 +1,11 @@ + + + + + */5 * * * * + + + */5 * * * * + + + diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 0000000..fa504b8 --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+
diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..ccacc8e --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,38 @@ + + + + + + + + Kodhub\Reporter\Console\Command\Export + + + + + + + + + kodhub_reporter_report + Kodhub\Reporter\Model\ResourceModel\Report\Collection + + + + + + Kodhub\Reporter\Model\ResourceModel\Report\Grid\Collection + Kodhub\Reporter\Model\ResourceModel\Log\Grid\Collection + + + + + + + + + kodhub_reporter_log + Kodhub\Reporter\Model\ResourceModel\Log\Collection + + + diff --git a/etc/events.xml b/etc/events.xml new file mode 100644 index 0000000..32da35b --- /dev/null +++ b/etc/events.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..9242b10 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,4 @@ + + + + diff --git a/etc/webapi.xml b/etc/webapi.xml new file mode 100644 index 0000000..2bb5bc7 --- /dev/null +++ b/etc/webapi.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/i18n/en_US.csv b/i18n/en_US.csv new file mode 100644 index 0000000..6410f0d --- /dev/null +++ b/i18n/en_US.csv @@ -0,0 +1 @@ +"string","stringtranslated" \ No newline at end of file diff --git a/i18n/tr_TR.csv b/i18n/tr_TR.csv new file mode 100644 index 0000000..6410f0d --- /dev/null +++ b/i18n/tr_TR.csv @@ -0,0 +1 @@ +"string","stringtranslated" \ No newline at end of file diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..1651500 --- /dev/null +++ b/registration.php @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/view/adminhtml/layout/kodhub_reporter_log_index.xml b/view/adminhtml/layout/kodhub_reporter_log_index.xml new file mode 100644 index 0000000..db767e8 --- /dev/null +++ b/view/adminhtml/layout/kodhub_reporter_log_index.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/view/adminhtml/layout/kodhub_reporter_log_new.xml b/view/adminhtml/layout/kodhub_reporter_log_new.xml new file mode 100644 index 0000000..059ba93 --- /dev/null +++ b/view/adminhtml/layout/kodhub_reporter_log_new.xml @@ -0,0 +1,4 @@ + + + + diff --git a/view/adminhtml/layout/kodhub_reporter_report_edit.xml b/view/adminhtml/layout/kodhub_reporter_report_edit.xml new file mode 100644 index 0000000..f817fd1 --- /dev/null +++ b/view/adminhtml/layout/kodhub_reporter_report_edit.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/view/adminhtml/layout/kodhub_reporter_report_index.xml b/view/adminhtml/layout/kodhub_reporter_report_index.xml new file mode 100644 index 0000000..fd6086f --- /dev/null +++ b/view/adminhtml/layout/kodhub_reporter_report_index.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/view/adminhtml/layout/kodhub_reporter_report_new.xml b/view/adminhtml/layout/kodhub_reporter_report_new.xml new file mode 100644 index 0000000..69606e5 --- /dev/null +++ b/view/adminhtml/layout/kodhub_reporter_report_new.xml @@ -0,0 +1,4 @@ + + + + diff --git a/view/adminhtml/ui_component/kodhub_reporter_log_form.xml b/view/adminhtml/ui_component/kodhub_reporter_log_form.xml new file mode 100644 index 0000000..f7a5e23 --- /dev/null +++ b/view/adminhtml/ui_component/kodhub_reporter_log_form.xml @@ -0,0 +1,59 @@ + +
+ + + kodhub_reporter_log_form.log_form_data_source + + General Information + templates/form/collapsible + + + + + +
+ + + + + Kodhub_Reporter::Log + + + id + log_id + + + + + + true + + + + + + + + + + kodhub_reporter_log_listing.kodhub_reporter_log_listing.kodhub_reporter_log_columns.ids + true + log_id + + + false + + + + + kodhub_reporter_log_listing.kodhub_reporter_log_listing.kodhub_reporter_log_columns_editor + startEdit + + ${ $.$data.rowIndex } + true + + + + + + + log_id + + + + + text + asc + + + + + + text + + + date + + false + + + + + + + log_id + false + 107 + + + + diff --git a/view/adminhtml/ui_component/kodhub_reporter_report_form.xml b/view/adminhtml/ui_component/kodhub_reporter_report_form.xml new file mode 100644 index 0000000..8936917 --- /dev/null +++ b/view/adminhtml/ui_component/kodhub_reporter_report_form.xml @@ -0,0 +1,179 @@ + +
+ + + kodhub_reporter_report_form.report_form_data_source + + General Information + templates/form/collapsible + + + + + +
+ + + + + Kodhub_Reporter::Report + + + id + report_id + + + + + + true + + + + + + + + + + kodhub_reporter_report_listing.kodhub_reporter_report_listing.kodhub_reporter_report_columns.ids + true + report_id + + + false + + + + + kodhub_reporter_report_listing.kodhub_reporter_report_listing.kodhub_reporter_report_columns_editor + startEdit + + ${ $.$data.rowIndex } + true + + + + + + + report_id + + + + + text + asc + + + + + + text + + + text + + false + + + + + + + report_id + false + 107 + + + + + text + + + text + + false + + + + + + + text + + + text + + false + + + + + + + text + + + text + + false + + + + + + + text + + + text + + false + + + + + + + text + + + text + + false + + + + + + + text + + + text + + false + + + + + + + text + + + date + + false + + + + + + + text + + + date + + false + + + + + +