Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.84 KB | None | 0 0
  1. use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
  2.  
  3. /**
  4. * Class BackButton
  5. */
  6. class BackButton extends GenericButton implements ButtonProviderInterface
  7. {
  8. /**
  9. * @return array
  10. */
  11. public function getButtonData()
  12. {
  13. return [
  14. 'label' => __('Back'),
  15. 'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
  16. 'class' => 'back',
  17. 'sort_order' => 10
  18. ];
  19. }
  20.  
  21. /**
  22. * Get URL for back (reset) button
  23. *
  24. * @return string
  25. */
  26. public function getBackUrl()
  27. {
  28. return $this->getUrl('*/*/');
  29. }
  30. }
  31.  
  32. namespace XXSuccessBlockAdminhtmlExpressionInfoEdit;
  33.  
  34. use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
  35.  
  36. /**
  37. * Class DeleteButton
  38. */
  39. class DeleteButton extends GenericButton implements ButtonProviderInterface
  40. {
  41. /**
  42. * @return array
  43. */
  44. public function getButtonData()
  45. {
  46. $data = [];
  47. if ($this->getId()) {
  48. $data = [
  49. 'label' => __('Delete'),
  50. 'class' => 'delete',
  51. 'on_click' => 'deleteConfirm(''
  52. . __('Are you sure you want to delete this expression info?')
  53. . '', '' . $this->getDeleteUrl() . '')',
  54. 'sort_order' => 20,
  55. ];
  56. }
  57. return $data;
  58. }
  59.  
  60. /**
  61. * @return string
  62. */
  63. public function getDeleteUrl()
  64. {
  65. return $this->getUrl('*/*/delete', ['id' => $this->getId()]);
  66. }
  67. }
  68.  
  69. <?php
  70.  
  71. namespace XXxXSuccessBlockAdminhtmlExpressionInfoEdit;
  72.  
  73. use MagentoBackendBlockWidgetContext;
  74. use MagentoFrameworkRegistry;
  75.  
  76. /**
  77. * Class GenericButton
  78. */
  79. class GenericButton
  80. {
  81. /**
  82. * @var Context
  83. */
  84. protected $context;
  85. protected $coreRegistry;
  86.  
  87. /**
  88. * @param Context $context
  89. */
  90. public function __construct(Context $context, Registry $registry)
  91. {
  92. $this->context = $context;
  93. $this->coreRegistry = $registry;
  94. }
  95.  
  96. /**
  97. * Return Cushion Id
  98. *
  99. * @return int|null
  100. */
  101. public function getId()
  102. {
  103. $model = $this->coreRegistry->registry('current_expression_info');
  104. //Loads the model and get collection and id
  105. if (isset($model) && $model->getId()) {
  106. // Return id to delete button
  107. return $model->getId();
  108. }
  109. return false;
  110. }
  111.  
  112. /**
  113. * Generate url by route and parameters
  114. *
  115. * @param string $route
  116. * @param array $params
  117. * @return string
  118. */
  119. public function getUrl($route = '', $params = [])
  120. {
  121. return $this->context->getUrlBuilder()->getUrl($route, $params);
  122. }
  123. }
  124.  
  125. <?php
  126.  
  127. namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
  128.  
  129. use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
  130.  
  131. /**
  132. * Class ResetButton
  133. */
  134. class ResetButton implements ButtonProviderInterface
  135. {
  136. /**
  137. * @return array
  138. */
  139. public function getButtonData()
  140. {
  141. return [
  142. 'label' => __('Reset'),
  143. 'class' => 'reset',
  144. 'on_click' => 'location.reload();',
  145. 'sort_order' => 30
  146. ];
  147. }
  148. }
  149.  
  150. <?php
  151.  
  152. namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
  153.  
  154. use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
  155.  
  156. /**
  157. * Class SaveAndContinueButton
  158. */
  159. class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
  160. {
  161. /**
  162. * @return array
  163. */
  164. public function getButtonData()
  165. {
  166. $data = [
  167. 'label' => __('Save and Continue Edit'),
  168. 'class' => 'save',
  169. 'data_attribute' => [
  170. 'mage-init' => [
  171. 'button' => ['event' => 'saveAndContinueEdit'],
  172. ],
  173. ],
  174. 'sort_order' => 80,
  175. ];
  176. return $data;
  177. }
  178.  
  179. <?php
  180.  
  181. namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEdit;
  182.  
  183. use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;
  184.  
  185. /**
  186. * Class SaveButton
  187. */
  188. class SaveButton extends GenericButton implements ButtonProviderInterface
  189. {
  190. /**
  191. * @return array
  192. */
  193. public function getButtonData()
  194. {
  195. return [
  196. 'label' => __('Save'),
  197. 'class' => 'save primary',
  198. 'data_attribute' => [
  199. 'mage-init' => ['button' => ['event' => 'save']],
  200. 'form-role' => 'save',
  201. ],
  202. 'on_click' => '',
  203. 'sort_order' => 40,
  204. ];
  205. }
  206.  
  207. /**
  208. * @return string
  209. */
  210. public function getSaveUrl()
  211. {
  212. return $this->getUrl('*/*/save', ['id' => $this->getId()]);
  213. }
  214. }
  215.  
  216. <?php
  217.  
  218. /**
  219. * Copyright © Magento, Inc. All rights reserved.
  220. * See COPYING.txt for license details.
  221. */
  222.  
  223. namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEditTab;
  224.  
  225. use MagentoUiComponentLayoutTabsTabInterface;
  226. use MagentoBackendBlockTemplateContext;
  227. use MagentoFrameworkRegistry;
  228.  
  229. /**
  230. * Additional Information form block
  231. */
  232. class View extends MagentoBackendBlockTemplate implements TabInterface
  233. {
  234. /**
  235. * Core registry
  236. *
  237. * @var MagentoFrameworkRegistry
  238. */
  239. protected $coreRegistry;
  240.  
  241. /**
  242. * @param MagentoBackendBlockTemplateContext $context
  243. * @param MagentoFrameworkRegistry $registry
  244. * @param array $data
  245. */
  246. public function __construct(Context $context, Registry $registry, array $data = [])
  247. {
  248. $this->coreRegistry = $registry;
  249. parent::__construct($context, $data);
  250. }
  251.  
  252. /**
  253. * @return MagentoFrameworkPhrase
  254. */
  255. public function getTabLabel()
  256. {
  257. return __('Additional Information');
  258. }
  259.  
  260. /**
  261. * @return MagentoFrameworkPhrase
  262. */
  263. public function getTabTitle()
  264. {
  265. return __('Additional Information');
  266. }
  267.  
  268. /**
  269. * @return bool
  270. */
  271. public function canShowTab()
  272. {
  273. if ($this->getId()) {
  274. return true;
  275. }
  276. return false;
  277. }
  278.  
  279. /**
  280. * @return string|null
  281. */
  282. public function getId()
  283. {
  284. $postModel = $this->coreRegistry->registry('current_expression_info');
  285. if (isset($postModel) && $postModel->getId()) {
  286. return true;
  287. }
  288. return false;
  289. }
  290.  
  291. /**
  292. * @return bool
  293. */
  294. public function isHidden()
  295. {
  296. if ($this->getId()) {
  297. return false;
  298. }
  299. return true;
  300. }
  301.  
  302. /**
  303. * Tab class getter
  304. *
  305. * @return string
  306. */
  307. public function getTabClass()
  308. {
  309. return '';
  310. }
  311.  
  312. /**
  313. * Return URL link to Tab content
  314. *
  315. * @return string
  316. */
  317. public function getTabUrl()
  318. {
  319. return '';
  320. }
  321.  
  322. /**
  323. * Tab should be loaded trough Ajax call
  324. *
  325. * @return bool
  326. */
  327. public function isAjaxLoaded()
  328. {
  329. return false;
  330. }
  331. }
  332.  
  333. <?php
  334.  
  335. /**
  336. * Copyright © Magento, Inc. All rights reserved.
  337. * See COPYING.txt for license details.
  338. */
  339.  
  340. namespace OXSuccessPageFeedbackBlockAdminhtmlExpressionInfoEditTabView;
  341.  
  342. use MagentoBackendBlockTemplateContext;
  343. use MagentoFrameworkRegistry;
  344. use MagentoFrameworkStdlibDateTimeTimezoneInterface;
  345.  
  346. class AdditionalInfo extends MagentoBackendBlockTemplate
  347. {
  348. protected $coreRegistry;
  349. protected $timezone;
  350.  
  351. public function __construct(Context $context, Registry $registry, TimezoneInterface $timezone, array $data = [])
  352. {
  353. $this->coreRegistry = $registry;
  354. $this->timezone = $timezone;
  355. parent::__construct($context, $data);
  356. }
  357.  
  358. public function getCreatedBy()
  359. {
  360. return $createdBy = $this->coreRegistry->registry('current_expression_info')->getCreatedBy();
  361. }
  362.  
  363. public function getCreatedAt()
  364. {
  365. $createdAt = $this->coreRegistry->registry('current_expression_info')->getCreatedAt();
  366. return $date = $this->timezone->date($createdAt)->format('M d, Y, h:i:s A');
  367. }
  368.  
  369. public function getUpdatedBy()
  370. {
  371. return $updatedBy = $this->coreRegistry->registry('current_expression_info')->getUpdatedBy();
  372. }
  373.  
  374. public function getUpdatedAt()
  375. {
  376. $updatedAt = $this->coreRegistry->registry('current_expression_info')->getUpdatedAt();
  377. return $date = $this->timezone->date($updatedAt)->format('M d, Y, h:i:s A');
  378. }
  379. }
  380.  
  381. <?php
  382.  
  383. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  384.  
  385. use MagentoBackendAppAction;
  386. use OXSuccessPageFeedbackModelExpressionInfoFactory;
  387. use MagentoBackendAppActionContext;
  388. use MagentoBackendModelViewResultRedirectFactory;
  389.  
  390. class Delete extends Action
  391. {
  392. protected $expressionInfoFactory;
  393.  
  394. public function __construct(Context $context, RedirectFactory $resultRedirectFactory, ExpressionInfoFactory $expressionInfoFactory)
  395. {
  396. $this->expressionInfoFactory = $expressionInfoFactory;
  397. $this->resultRedirectFactory = $resultRedirectFactory;
  398. parent::__construct($context);
  399. }
  400.  
  401. public function execute()
  402. {
  403. $id = $this->getRequest()->getParam('id');
  404. $resultRedirect = $this->resultRedirectFactory->create();
  405. $model = $this->expressionInfoFactory->create()->load($id);
  406. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  407. if (!($model)) {
  408. $this->messageManager->addError(__('Unable to proceed. Please, try again.'));
  409. return $resultRedirect->setPath('*/*/index', array('_current' => true));
  410. }
  411.  
  412. if ($id) {
  413. try {
  414. $model = $this->expressionInfoFactory->create();
  415. $model->load($id);
  416. $model->delete();
  417. $this->messageManager->addSuccess(__('Your expression has been deleted!'));
  418. return $resultRedirect->setPath('*/*/');
  419. } catch (Exception $e) {
  420. $this->messageManager->addError($e->getMessage());
  421. return $resultRedirect->setPath('*/*/index', array('_current' => true));
  422. }
  423. $this->messageManager->addError(__('We can't find a expression details to delete.'));
  424. return $resultRedirect->setPath('*/*/index', array('_current' => true));
  425. }
  426. }
  427. }
  428.  
  429. }
  430.  
  431. <?php
  432.  
  433. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  434.  
  435. use MagentoBackendAppAction;
  436. use MagentoBackendAppActionContext;
  437. use MagentoFrameworkRegistry;
  438. use MagentoFrameworkViewResultPageFactory;
  439. use OXSuccessPageFeedbackModelExpressionInfoFactory;
  440.  
  441. class Edit extends Action
  442. {
  443. protected $resultPage;
  444. protected $resultPageFactory = false;
  445. protected $coreRegistry;
  446. protected $model;
  447.  
  448. public function __construct(Context $context, PageFactory $resultPageFactory, Registry $coreRegistry, ExpressionInfoFactory $model)
  449. {
  450. parent::__construct($context);
  451. $this->resultPageFactory = $resultPageFactory;
  452. $this->coreRegistry = $coreRegistry;
  453. $this->model = $model;
  454. }
  455.  
  456. public function execute()
  457. {
  458. $id = $this->getRequest()->getParam('id');
  459. $post = $this->model->create();
  460. if ($id) {
  461. $post = $post->load($id);
  462. if ($post->getId()) {
  463. $this->coreRegistry->register('current_expression_info', $post);
  464. }
  465. }
  466. $resultPage = $this->getResultPage();
  467. $resultPage->getConfig()->getTitle()->prepend($post->getId() ? __('Edit Expression Details') : __('New Expression Details'));
  468. return $resultPage;
  469. }
  470.  
  471. public function getResultPage()
  472. {
  473. $this->resultPage = $this->resultPageFactory->create();
  474. return $this->resultPage;
  475. }
  476. }
  477.  
  478. <?php
  479.  
  480. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  481.  
  482. use MagentoBackendAppActionContext;
  483. use MagentoFrameworkViewResultPageFactory;
  484. use MagentoBackendAppAction;
  485.  
  486. class Index extends Action
  487. {
  488. protected $resultPage;
  489. protected $resultPageFactory = false;
  490.  
  491. public function __construct(Context $context, PageFactory $resultPageFactory)
  492. {
  493. parent::__construct($context);
  494. $this->resultPageFactory = $resultPageFactory;
  495. }
  496.  
  497. public function execute()
  498. {
  499. //Call page factory to render layout and page content
  500. $resultPage = $this->resultPageFactory->create();
  501. /**
  502. * Set active menu item
  503. */
  504. $resultPage->setActiveMenu('OX_SuccessPageFeedback::manage_expressions');
  505. $resultPage->getConfig()->getTitle()->prepend((__('Manage Expressions')));
  506. //Add bread crumb
  507. $resultPage->addBreadcrumb(__('OX'), __('OX'));
  508. $resultPage->addBreadcrumb(__('SuccessPageFeedback'), __('SuccessPageFeedback'));
  509. return $resultPage;
  510. }
  511.  
  512. /*
  513. * Check permission via ACL resource
  514. */
  515. protected function _isAllowed()
  516. {
  517. return $this->_authorization->isAllowed('OX_SuccessPageFeedback::manage_expressions');
  518. }
  519. }
  520.  
  521. <?php
  522.  
  523. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  524.  
  525. use MagentoBackendAppActionContext;
  526. use MagentoUiComponentMassActionFilter;
  527. use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
  528. use MagentoFrameworkControllerResultFactory;
  529. use MagentoBackendAppAction;
  530.  
  531. class MassDelete extends Action
  532. {
  533. /**
  534. * @var Filter
  535. */
  536. protected $filter;
  537.  
  538. /**
  539. * @var CollectionFactory
  540. */
  541. protected $collectionFactory;
  542.  
  543. /**
  544. * @param Context $context
  545. * @param Filter $filter
  546. * @param CollectionFactory $collectionFactory
  547. */
  548. public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
  549. {
  550. $this->filter = $filter;
  551. $this->collectionFactory = $collectionFactory;
  552. parent::__construct($context);
  553. }
  554.  
  555. /**
  556. * Dispatch request
  557. *
  558. * @return MagentoFrameworkControllerResultInterface|ResponseInterface
  559. * @throws MagentoFrameworkExceptionNotFoundException
  560. */
  561. public function execute()
  562. {
  563. $collection = $this->filter->getCollection($this->collectionFactory->create());
  564. $collectionSize = $collection->getSize();
  565. foreach ($collection as $item) {
  566. $item->delete();
  567. }
  568. $this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
  569. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  570. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  571. return $resultRedirect->setPath('*/*/index');
  572. }
  573. }
  574.  
  575. <?php
  576.  
  577. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  578.  
  579. use MagentoBackendAppActionContext;
  580. use MagentoUiComponentMassActionFilter;
  581. use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
  582. use MagentoFrameworkControllerResultFactory;
  583. use MagentoBackendAppAction;
  584.  
  585. /**
  586. * Class MassStatus
  587. */
  588. class MassStatus extends Action
  589. {
  590. /**
  591. * @var Filter
  592. */
  593. protected $filter;
  594.  
  595. /**
  596. * @var CollectionFactory
  597. */
  598. protected $collectionFactory;
  599.  
  600. /**
  601. * @param Context $context
  602. * @param Filter $filter
  603. * @param CollectionFactory $collectionFactory
  604. */
  605. public function __construct(Context $context, Filter $filter, CollectionFactory $collectionFactory)
  606. {
  607. $this->filter = $filter;
  608. $this->collectionFactory = $collectionFactory;
  609. parent::__construct($context);
  610. }
  611.  
  612. /**
  613. * Execute action
  614. *
  615. * @return MagentoBackendModelViewResultRedirect
  616. * @throws MagentoFrameworkExceptionLocalizedException|Exception
  617. */
  618. public function execute()
  619. {
  620. $statusValue = $this->getRequest()->getParam('status');
  621. $collection = $this->filter->getCollection($this->collectionFactory->create());
  622. foreach ($collection as $item) {
  623. $item->setStatus($statusValue);
  624. $item->save();
  625. }
  626. $this->messageManager->addSuccess(__('A total of %1 record(s) have been modified.', $collection->getSize()));
  627. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  628. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  629. return $resultRedirect->setPath('*/*/index');
  630. }
  631. }
  632.  
  633. <?php
  634.  
  635. /**
  636. * Copyright © Magento, Inc. All rights reserved.
  637. * See COPYING.txt for license details.
  638. */
  639.  
  640. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  641.  
  642. use MagentoBackendAppActionContext;
  643. use MagentoBackendAppAction;
  644. use MagentoBackendModelViewResultForwardFactory;
  645.  
  646. class NewAction extends Action
  647. {
  648. /**
  649. * Create new cushion action
  650. *
  651. * @return MagentoBackendModelViewResultForward
  652. */
  653. protected $resultForwardFactory;
  654.  
  655. public function __construct(Context $context, ForwardFactory $resultForwardFactory)
  656. {
  657. $this->resultForwardFactory = $resultForwardFactory;
  658. parent::__construct($context);
  659. }
  660.  
  661. public function execute()
  662. {
  663. $resultForward = $this->resultForwardFactory->create();
  664. $resultForward->forward('edit');
  665. return $resultForward;
  666. }
  667. }
  668.  
  669. <?php
  670.  
  671. namespace OXSuccessPageFeedbackControllerAdminhtmlExpressionInfo;
  672.  
  673. use MagentoBackendAppActionContext;
  674. use MagentoBackendAppAction;
  675. use MagentoBackendModelViewResultRedirectFactory;
  676. use MagentoBackendModelAuthSession;
  677. use OXSuccessPageFeedbackModelExpressionInfoFactory;
  678.  
  679. class Save extends Action
  680. {
  681. protected $model;
  682.  
  683. public function __construct(Context $context, RedirectFactory $resultRedirectFactory, Session $authSession, ExpressionInfoFactory $model)
  684. {
  685. $this->resultRedirectFactory = $resultRedirectFactory;
  686. $this->authSession = $authSession;
  687. $this->model = $model;
  688. parent::__construct($context);
  689. }
  690.  
  691. public function execute()
  692. {
  693. try {
  694. $expressionInfo = $this->model->create();
  695. $post = $this->getRequest()->getParam('general');
  696.  
  697. $expressionCollection = $expressionInfo->getCollection()->addFieldToFilter('expression_name', $post['expression_name'])->getFirstItem();
  698. if ($expressionCollection->getId()) {
  699. $post['id'] = $expressionCollection->getId();
  700. $expressionInfo = $expressionInfo->load($expressionCollection->getId());
  701. }
  702.  
  703. $user = $this->getCurrentUser();
  704. if (empty($post['id'])) {
  705. $post['id'] = null;
  706. $post['created_by'] = $user;
  707. $post['updated_by'] = $user;
  708. }
  709. $post['updated_by'] = $user;
  710. $expressionInfo->setData($post);
  711. $expressionInfo->save();
  712. $this->messageManager->addSuccess(__('You saved the expression details.'));
  713. } catch (Exception $e) {
  714. $this->messageManager->addError($e->getMessage());
  715. }
  716. $resultRedirect = $this->resultRedirectFactory->create();
  717. if ($this->getRequest()->getParam('back')) {
  718. return $resultRedirect->setPath('*/*/edit', ['id' => $expressionInfo->getId(), '_current' => true]);
  719. }
  720. //Result redirected to index controller
  721. $resultRedirect = $this->resultRedirectFactory->create()->setPath('successpagefeedback/expressioninfo/index');
  722. return $resultRedirect;
  723. }
  724.  
  725. public function getCurrentUser()
  726. {
  727. return $this->authSession->getUser()->getUsername();
  728. }
  729. }
  730.  
  731. <?php
  732.  
  733. namespace OXSuccessPageFeedbackModel;
  734.  
  735. use MagentoFrameworkModelAbstractModel;
  736.  
  737. class ExpressionInfo extends AbstractModel
  738. {
  739. /**
  740. * Define resource model
  741. */
  742. protected function _construct()
  743. {
  744. $this->_init('OXSuccessPageFeedbackModelResourceModelExpressionInfo');
  745. }
  746. }
  747.  
  748. <?php
  749.  
  750. namespace OXSuccessPageFeedbackModelResourceModel;
  751.  
  752. use MagentoFrameworkModelResourceModelDbAbstractDb;
  753.  
  754. class ExpressionInfo extends AbstractDb
  755. {
  756. /**
  757. * Date model
  758. *
  759. * @var MagentoFrameworkStdlibDateTimeDateTime
  760. */
  761. protected $date;
  762.  
  763. /**
  764. * constructor
  765. *
  766. * @param MagentoFrameworkStdlibDateTimeDateTime $date
  767. * @param MagentoFrameworkModelResourceModelDbContext $context
  768. */
  769. public function __construct(
  770. MagentoFrameworkStdlibDateTimeDateTime $date,
  771. MagentoFrameworkModelResourceModelDbContext $context
  772. )
  773. {
  774. $this->date = $date;
  775. parent::__construct($context);
  776. }
  777.  
  778. /**
  779. * Define main table
  780. */
  781. protected function _construct()
  782. {
  783. $this->_init('ox_expression_detail', 'id');
  784. }
  785.  
  786. protected function _beforeSave(MagentoFrameworkModelAbstractModel $object)
  787. {
  788. $object->setUpdatedAt($this->date->date());
  789. if ($object->isObjectNew()) {
  790. $object->setCreatedAt($this->date->date());
  791. }
  792. return parent::_beforeSave($object);
  793. }
  794. }
  795.  
  796. <?php
  797.  
  798. namespace OXSuccessPageFeedbackModelResourceModelExpressionInfo;
  799.  
  800. use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
  801.  
  802. class Collection extends AbstractCollection
  803. {
  804. protected $_idFieldName = 'id';
  805. protected $_eventPrefix = 'successpagefeedback_expressioninfo_grid_collection';
  806. protected $_eventObject = 'expressioninfo_grid_collection';
  807.  
  808. /**
  809. * Define model & resource model
  810. */
  811. protected function _construct()
  812. {
  813. $this->_init('OXSuccessPageFeedbackModelExpressionInfo', 'OXSuccessPageFeedbackModelResourceModelExpressionInfo');
  814. }
  815. }
  816.  
  817. <?php
  818.  
  819. namespace OXSuccessPageFeedbackModelResourceModelExpressionInfoGrid;
  820.  
  821. class Collection extends OXSuccessPageFeedbackModelResourceModelExpressionInfoCollection implements MagentoFrameworkApiSearchSearchResultInterface
  822. {
  823. protected $_aggregations;
  824.  
  825. public function __construct(MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory, PsrLogLoggerInterface $logger, MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy, MagentoFrameworkEventManagerInterface $eventManager, $mainTable = 'ox_expression_detail', $eventPrefix, $eventObject, $resourceModel, $model = 'MagentoFrameworkViewElementUiComponentDataProviderDocument')
  826. {
  827. parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager);
  828. $this->_eventPrefix = $eventPrefix;
  829. $this->_eventObject = $eventObject;
  830. $this->_init($model, $resourceModel);
  831. $this->setMainTable($mainTable);
  832. }
  833.  
  834. public function getAggregations()
  835. {
  836. return $this->_aggregations;
  837. }
  838.  
  839. public function setAggregations($aggregations)
  840. {
  841. $this->_aggregations = $aggregations;
  842. }
  843.  
  844. public function getAllIds($limit = null, $offset = null)
  845. {
  846. return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
  847. }
  848.  
  849. public function getSearchCriteria()
  850. {
  851. return null;
  852. }
  853.  
  854. public function setSearchCriteria(MagentoFrameworkApiSearchCriteriaInterface $searchCriteria = null)
  855. {
  856. return $this;
  857. }
  858.  
  859. public function getTotalCount()
  860. {
  861. return $this->getSize();
  862. }
  863.  
  864. public function setTotalCount($totalCount)
  865. {
  866. return $this;
  867. }
  868.  
  869. public function setItems(array $items = null)
  870. {
  871. return $this;
  872. }
  873. }
  874.  
  875. <?php
  876.  
  877. namespace OXSuccessPageFeedbackModelDataExpressionInfo;
  878.  
  879. use OXSuccessPageFeedbackModelResourceModelExpressionInfoCollectionFactory;
  880. use MagentoStoreModelStoreManagerInterface;
  881. use MagentoUiDataProviderAbstractDataProvider;
  882.  
  883. class DataProvider extends AbstractDataProvider
  884. {
  885. protected $collection;
  886. protected $loadedData;
  887. protected $storeManager;
  888.  
  889. public function __construct(
  890. $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, StoreManagerInterface $storeManager, array $meta = [], array $data = []
  891. )
  892. {
  893. $this->collection = $collectionFactory->create();
  894. $this->storeManager = $storeManager;
  895. parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
  896. }
  897.  
  898. public function getData()
  899. {
  900. if (isset($this->loadedData)) {
  901. return $this->loadedData;
  902. }
  903. $items = $this->collection->getItems();
  904. foreach ($items as $item) {
  905. $this->loadedData[$item->getId()]['general'] = $item->getData();
  906. }
  907. return $this->loadedData;
  908. }
  909. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement