Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
- /**
- * Class BackButton
- */
- class BackButton extends GenericButton implements ButtonProviderInterface
- {
- /**
- * @return array
- */
- public function getButtonData()
- {
- return [
- 'label' => __('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('*/*/');
- }
- }
- namespace XXSuccessBlockAdminhtmlExpressionInfoEdit;
- use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
- /**
- * Class DeleteButton
- */
- class DeleteButton extends GenericButton implements ButtonProviderInterface
- {
- /**
- * @return array
- */
- public function getButtonData()
- {
- $data = [];
- if ($this->getId()) {
- $data = [
- 'label' => __('Delete'),
- 'class' => 'delete',
- 'on_click' => 'deleteConfirm(''
- . __('Are you sure you want to delete this expression info?')
- . '', '' . $this->getDeleteUrl() . '')',
- 'sort_order' => 20,
- ];
- }
- return $data;
- }
- /**
- * @return string
- */
- public function getDeleteUrl()
- {
- return $this->getUrl('*/*/delete', ['id' => $this->getId()]);
- }
- }
- <?php
- namespace XXxXSuccessBlockAdminhtmlExpressionInfoEdit;
- use MagentoBackendBlockWidgetContext;
- use MagentoFrameworkRegistry;
- /**
- * Class GenericButton
- */
- class GenericButton
- {
- /**
- * @var Context
- */
- protected $context;
- protected $coreRegistry;
- /**
- * @param Context $context
- */
- public function __construct(Context $context, Registry $registry)
- {
- $this->context = $context;
- $this->coreRegistry = $registry;
- }
- /**
- * Return Cushion Id
- *
- * @return int|null
- */
- public function getId()
- {
- $model = $this->coreRegistry->registry('current_expression_info');
- //Loads the model and get collection and id
- if (isset($model) && $model->getId()) {
- // Return id to delete button
- return $model->getId();
- }
- return false;
- }
- /**
- * 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);
- }
- }
- <?php
- namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
- use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
- /**
- * Class ResetButton
- */
- class ResetButton implements ButtonProviderInterface
- {
- /**
- * @return array
- */
- public function getButtonData()
- {
- return [
- 'label' => __('Reset'),
- 'class' => 'reset',
- 'on_click' => 'location.reload();',
- 'sort_order' => 30
- ];
- }
- }
- <?php
- namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
- use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
- /**
- * Class SaveAndContinueButton
- */
- class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
- {
- /**
- * @return array
- */
- public function getButtonData()
- {
- $data = [
- 'label' => __('Save and Continue Edit'),
- 'class' => 'save',
- 'data_attribute' => [
- 'mage-init' => [
- 'button' => ['event' => 'saveAndContinueEdit'],
- ],
- ],
- 'sort_order' => 80,
- ];
- return $data;
- }
- <?php
- namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
- use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
- /**
- * Class SaveButton
- */
- class SaveButton extends GenericButton implements ButtonProviderInterface
- {
- /**
- * @return array
- */
- public function getButtonData()
- {
- return [
- 'label' => __('Save'),
- 'class' => 'save primary',
- 'data_attribute' => [
- 'mage-init' => ['button' => ['event' => 'save']],
- 'form-role' => 'save',
- ],
- 'on_click' => '',
- 'sort_order' => 40,
- ];
- }
- /**
- * @return string
- */
- public function getSaveUrl()
- {
- return $this->getUrl('*/*/save', ['id' => $this->getId()]);
- }
- }
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEditTab;
- use MagentoUiComponentLayoutTabsTabInterface;
- use MagentoBackendBlockTemplateContext;
- use MagentoFrameworkRegistry;
- /**
- * Additional Information form block
- */
- class View extends MagentoBackendBlockTemplate implements TabInterface
- {
- /**
- * Core registry
- *
- * @var MagentoFrameworkRegistry
- */
- protected $coreRegistry;
- /**
- * @param MagentoBackendBlockTemplateContext $context
- * @param MagentoFrameworkRegistry $registry
- * @param array $data
- */
- public function __construct(Context $context, Registry $registry, array $data = [])
- {
- $this->coreRegistry = $registry;
- parent::__construct($context, $data);
- }
- /**
- * @return MagentoFrameworkPhrase
- */
- public function getTabLabel()
- {
- return __('Additional Information');
- }
- /**
- * @return MagentoFrameworkPhrase
- */
- public function getTabTitle()
- {
- return __('Additional Information');
- }
- /**
- * @return bool
- */
- public function canShowTab()
- {
- if ($this->getId()) {
- return true;
- }
- return false;
- }
- /**
- * @return string|null
- */
- public function getId()
- {
- $postModel = $this->coreRegistry->registry('current_expression_info');
- if (isset($postModel) && $postModel->getId()) {
- return true;
- }
- return false;
- }
- /**
- * @return bool
- */
- public function isHidden()
- {
- if ($this->getId()) {
- return false;
- }
- return true;
- }
- /**
- * Tab class getter
- *
- * @return string
- */
- public function getTabClass()
- {
- return '';
- }
- /**
- * Return URL link to Tab content
- *
- * @return string
- */
- public function getTabUrl()
- {
- return '';
- }
- /**
- * Tab should be loaded trough Ajax call
- *
- * @return bool
- */
- public function isAjaxLoaded()
- {
- return false;
- }
- }
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEditTabView;
- use MagentoBackendBlockTemplateContext;
- use MagentoFrameworkRegistry;
- use MagentoFrameworkStdlibDateTimeTimezoneInterface;
- class AdditionalInfo extends MagentoBackendBlockTemplate
- {
- protected $coreRegistry;
- protected $timezone;
- public function __construct(Context $context, Registry $registry, TimezoneInterface $timezone, array $data = [])
- {
- $this->coreRegistry = $registry;
- $this->timezone = $timezone;
- parent::__construct($context, $data);
- }
- public function getCreatedBy()
- {
- return $createdBy = $this->coreRegistry->registry('current_expression_info')->getCreatedBy();
- }
- public function getCreatedAt()
- {
- $createdAt = $this->coreRegistry->registry('current_expression_info')->getCreatedAt();
- return $date = $this->timezone->date($createdAt)->format('M d, Y, h:i:s A');
- }
- public function getUpdatedBy()
- {
- return $updatedBy = $this->coreRegistry->registry('current_expression_info')->getUpdatedBy();
- }
- public function getUpdatedAt()
- {
- $updatedAt = $this->coreRegistry->registry('current_expression_info')->getUpdatedAt();
- return $date = $this->timezone->date($updatedAt)->format('M d, Y, h:i:s A');
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppAction;
- use OXSuccessPageFeedbackModelExpressionInfoFactory;
- use MagentoBackendAppActionContext;
- use MagentoBackendModelViewResultRedirectFactory;
- class Delete extends Action
- {
- protected $expressionInfoFactory;
- public function __construct(Context $context, RedirectFactory $resultRedirectFactory, ExpressionInfoFactory $expressionInfoFactory)
- {
- $this->expressionInfoFactory = $expressionInfoFactory;
- $this->resultRedirectFactory = $resultRedirectFactory;
- parent::__construct($context);
- }
- public function execute()
- {
- $id = $this->getRequest()->getParam('id');
- $resultRedirect = $this->resultRedirectFactory->create();
- $model = $this->expressionInfoFactory->create()->load($id);
- /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
- if (!($model)) {
- $this->messageManager->addError(__('Unable to proceed. Please, try again.'));
- return $resultRedirect->setPath('*/*/index', array('_current' => true));
- }
- if ($id) {
- try {
- $model = $this->expressionInfoFactory->create();
- $model->load($id);
- $model->delete();
- $this->messageManager->addSuccess(__('Your expression has been deleted!'));
- return $resultRedirect->setPath('*/*/');
- } catch (Exception $e) {
- $this->messageManager->addError($e->getMessage());
- return $resultRedirect->setPath('*/*/index', array('_current' => true));
- }
- $this->messageManager->addError(__('We can't find a expression details to delete.'));
- return $resultRedirect->setPath('*/*/index', array('_current' => true));
- }
- }
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppAction;
- use MagentoBackendAppActionContext;
- use MagentoFrameworkRegistry;
- use MagentoFrameworkViewResultPageFactory;
- use OXSuccessPageFeedbackModelExpressionInfoFactory;
- class Edit extends Action
- {
- protected $resultPage;
- protected $resultPageFactory = false;
- protected $coreRegistry;
- protected $model;
- public function __construct(Context $context, PageFactory $resultPageFactory, Registry $coreRegistry, ExpressionInfoFactory $model)
- {
- parent::__construct($context);
- $this->resultPageFactory = $resultPageFactory;
- $this->coreRegistry = $coreRegistry;
- $this->model = $model;
- }
- public function execute()
- {
- $id = $this->getRequest()->getParam('id');
- $post = $this->model->create();
- if ($id) {
- $post = $post->load($id);
- if ($post->getId()) {
- $this->coreRegistry->register('current_expression_info', $post);
- }
- }
- $resultPage = $this->getResultPage();
- $resultPage->getConfig()->getTitle()->prepend($post->getId() ? __('Edit Expression Details') : __('New Expression Details'));
- return $resultPage;
- }
- public function getResultPage()
- {
- $this->resultPage = $this->resultPageFactory->create();
- return $this->resultPage;
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppActionContext;
- use MagentoFrameworkViewResultPageFactory;
- use MagentoBackendAppAction;
- class Index extends Action
- {
- protected $resultPage;
- protected $resultPageFactory = false;
- public function __construct(Context $context, PageFactory $resultPageFactory)
- {
- parent::__construct($context);
- $this->resultPageFactory = $resultPageFactory;
- }
- public function execute()
- {
- //Call page factory to render layout and page content
- $resultPage = $this->resultPageFactory->create();
- /**
- * Set active menu item
- */
- $resultPage->setActiveMenu('OX_SuccessPageFeedback::manage_expressions');
- $resultPage->getConfig()->getTitle()->prepend((__('Manage Expressions')));
- //Add bread crumb
- $resultPage->addBreadcrumb(__('OX'), __('OX'));
- $resultPage->addBreadcrumb(__('SuccessPageFeedback'), __('SuccessPageFeedback'));
- return $resultPage;
- }
- /*
- * Check permission via ACL resource
- */
- protected function _isAllowed()
- {
- return $this->_authorization->isAllowed('OX_SuccessPageFeedback::manage_expressions');
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppActionContext;
- use MagentoUiComponentMassActionFilter;
- use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
- use MagentoFrameworkControllerResultFactory;
- use MagentoBackendAppAction;
- class MassDelete extends Action
- {
- /**
- * @var Filter
- */
- protected $filter;
- /**
- * @var CollectionFactory
- */
- protected $collectionFactory;
- /**
- * @param Context $context
- * @param Filter $filter
- * @param CollectionFactory $collectionFactory
- */
- public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
- {
- $this->filter = $filter;
- $this->collectionFactory = $collectionFactory;
- parent::__construct($context);
- }
- /**
- * Dispatch request
- *
- * @return MagentoFrameworkControllerResultInterface|ResponseInterface
- * @throws MagentoFrameworkExceptionNotFoundException
- */
- public function execute()
- {
- $collection = $this->filter->getCollection($this->collectionFactory->create());
- $collectionSize = $collection->getSize();
- foreach ($collection as $item) {
- $item->delete();
- }
- $this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
- /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
- $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
- return $resultRedirect->setPath('*/*/index');
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppActionContext;
- use MagentoUiComponentMassActionFilter;
- use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
- use MagentoFrameworkControllerResultFactory;
- use MagentoBackendAppAction;
- /**
- * Class MassStatus
- */
- class MassStatus extends Action
- {
- /**
- * @var Filter
- */
- protected $filter;
- /**
- * @var CollectionFactory
- */
- protected $collectionFactory;
- /**
- * @param Context $context
- * @param Filter $filter
- * @param CollectionFactory $collectionFactory
- */
- public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
- {
- $this->filter = $filter;
- $this->collectionFactory = $collectionFactory;
- parent::__construct($context);
- }
- /**
- * Execute action
- *
- * @return MagentoBackendModelViewResultRedirect
- * @throws MagentoFrameworkExceptionLocalizedException|Exception
- */
- public function execute()
- {
- $statusValue = $this->getRequest()->getParam('status');
- $collection = $this->filter->getCollection($this->collectionFactory->create());
- foreach ($collection as $item) {
- $item->setStatus($statusValue);
- $item->save();
- }
- $this->messageManager->addSuccess(__('A total of %1 record(s) have been modified.', $collection->getSize()));
- /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
- $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
- return $resultRedirect->setPath('*/*/index');
- }
- }
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppActionContext;
- use MagentoBackendAppAction;
- use MagentoBackendModelViewResultForwardFactory;
- class NewAction extends Action
- {
- /**
- * Create new cushion action
- *
- * @return MagentoBackendModelViewResultForward
- */
- protected $resultForwardFactory;
- public function __construct(Context $context, ForwardFactory $resultForwardFactory)
- {
- $this->resultForwardFactory = $resultForwardFactory;
- parent::__construct($context);
- }
- public function execute()
- {
- $resultForward = $this->resultForwardFactory->create();
- $resultForward->forward('edit');
- return $resultForward;
- }
- }
- <?php
- namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
- use MagentoBackendAppActionContext;
- use MagentoBackendAppAction;
- use MagentoBackendModelViewResultRedirectFactory;
- use MagentoBackendModelAuthSession;
- use OXSuccessPageFeedbackModelExpressionInfoFactory;
- class Save extends Action
- {
- protected $model;
- public function __construct(Context $context, RedirectFactory $resultRedirectFactory, Session $authSession, ExpressionInfoFactory $model)
- {
- $this->resultRedirectFactory = $resultRedirectFactory;
- $this->authSession = $authSession;
- $this->model = $model;
- parent::__construct($context);
- }
- public function execute()
- {
- try {
- $expressionInfo = $this->model->create();
- $post = $this->getRequest()->getParam('general');
- $expressionCollection = $expressionInfo->getCollection()->addFieldToFilter('expression_name', $post['expression_name'])->getFirstItem();
- if ($expressionCollection->getId()) {
- $post['id'] = $expressionCollection->getId();
- $expressionInfo = $expressionInfo->load($expressionCollection->getId());
- }
- $user = $this->getCurrentUser();
- if (empty($post['id'])) {
- $post['id'] = null;
- $post['created_by'] = $user;
- $post['updated_by'] = $user;
- }
- $post['updated_by'] = $user;
- $expressionInfo->setData($post);
- $expressionInfo->save();
- $this->messageManager->addSuccess(__('You saved the expression details.'));
- } catch (Exception $e) {
- $this->messageManager->addError($e->getMessage());
- }
- $resultRedirect = $this->resultRedirectFactory->create();
- if ($this->getRequest()->getParam('back')) {
- return $resultRedirect->setPath('*/*/edit', ['id' => $expressionInfo->getId(), '_current' => true]);
- }
- //Result redirected to index controller
- $resultRedirect = $this->resultRedirectFactory->create()->setPath('successpagefeedback/expressioninfo/index');
- return $resultRedirect;
- }
- public function getCurrentUser()
- {
- return $this->authSession->getUser()->getUsername();
- }
- }
- <?php
- namespace OXSuccessPageFeedbackModel;
- use MagentoFrameworkModelAbstractModel;
- class ExpressionInfo extends AbstractModel
- {
- /**
- * Define resource model
- */
- protected function _construct()
- {
- $this->_init('OXSuccessPageFeedbackModelResourceModelExpressionInfo');
- }
- }
- <?php
- namespace OXSuccessPageFeedbackModelResourceModel;
- use MagentoFrameworkModelResourceModelDbAbstractDb;
- class ExpressionInfo extends AbstractDb
- {
- /**
- * Date model
- *
- * @var MagentoFrameworkStdlibDateTimeDateTime
- */
- protected $date;
- /**
- * constructor
- *
- * @param MagentoFrameworkStdlibDateTimeDateTime $date
- * @param MagentoFrameworkModelResourceModelDbContext $context
- */
- public function __construct(
- MagentoFrameworkStdlibDateTimeDateTime $date,
- MagentoFrameworkModelResourceModelDbContext $context
- )
- {
- $this->date = $date;
- parent::__construct($context);
- }
- /**
- * Define main table
- */
- protected function _construct()
- {
- $this->_init('ox_expression_detail', 'id');
- }
- protected function _beforeSave(MagentoFrameworkModelAbstractModel $object)
- {
- $object->setUpdatedAt($this->date->date());
- if ($object->isObjectNew()) {
- $object->setCreatedAt($this->date->date());
- }
- return parent::_beforeSave($object);
- }
- }
- <?php
- namespace OXSuccessPageFeedbackModelResourceModelExpressionInfo;
- use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
- class Collection extends AbstractCollection
- {
- protected $_idFieldName = 'id';
- protected $_eventPrefix = 'successpagefeedback_expressioninfo_grid_collection';
- protected $_eventObject = 'expressioninfo_grid_collection';
- /**
- * Define model & resource model
- */
- protected function _construct()
- {
- $this->_init('OXSuccessPageFeedbackModelExpressionInfo', 'OXSuccessPageFeedbackModelResourceModelExpressionInfo');
- }
- }
- <?php
- namespace OXSuccessPageFeedbackModelResourceModelExpressionInfoGrid;
- class Collection extends OXSuccessPageFeedbackModelResourceModelExpressionInfoCollection implements MagentoFrameworkApiSearchSearchResultInterface
- {
- protected $_aggregations;
- public function __construct(MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory, PsrLogLoggerInterface $logger, MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy, MagentoFrameworkEventManagerInterface $eventManager, $mainTable = 'ox_expression_detail', $eventPrefix, $eventObject, $resourceModel, $model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument')
- {
- parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager);
- $this->_eventPrefix = $eventPrefix;
- $this->_eventObject = $eventObject;
- $this->_init($model, $resourceModel);
- $this->setMainTable($mainTable);
- }
- public function getAggregations()
- {
- return $this->_aggregations;
- }
- public function setAggregations($aggregations)
- {
- $this->_aggregations = $aggregations;
- }
- public function getAllIds($limit = null, $offset = null)
- {
- return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
- }
- public function getSearchCriteria()
- {
- return null;
- }
- public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)
- {
- return $this;
- }
- public function getTotalCount()
- {
- return $this->getSize();
- }
- public function setTotalCount($totalCount)
- {
- return $this;
- }
- public function setItems(array $items = null)
- {
- return $this;
- }
- }
- <?php
- namespace OXSuccessPageFeedbackModelDataExpressionInfo;
- use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
- use MagentoStoreModelStoreManagerInterface;
- use MagentoUiDataProviderAbstractDataProvider;
- class DataProvider extends AbstractDataProvider
- {
- protected $collection;
- protected $loadedData;
- protected $storeManager;
- public function __construct(
- $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, StoreManagerInterface $storeManager, array $meta = [], array $data = []
- )
- {
- $this->collection = $collectionFactory->create();
- $this->storeManager = $storeManager;
- parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
- }
- public function getData()
- {
- if (isset($this->loadedData)) {
- return $this->loadedData;
- }
- $items = $this->collection->getItems();
- foreach ($items as $item) {
- $this->loadedData[$item->getId()]['general'] = $item->getData();
- }
- return $this->loadedData;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement