Guest User

Untitled

a guest
Aug 19th, 2019
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace MyModuleModelSave;
  3. use MyModuleModelResourceModelSaveCollectionFactory;
  4. class DataProvider extends MagentoUiDataProviderAbstractDataProvider
  5. {
  6. /**
  7. * @param string $name
  8. * @param string $primaryFieldName
  9. * @param string $requestFieldName
  10. * @param CollectionFactory $contactCollectionFactory
  11. * @param array $meta
  12. * @param array $data
  13. */
  14.  
  15. public function __construct(
  16. $name,
  17. $primaryFieldName,
  18. $requestFieldName,
  19. CollectionFactory $contactCollectionFactory,
  20. array $meta = [],
  21. array $data = []
  22. ) {
  23. $this->collection = $contactCollectionFactory->create();
  24.  
  25. parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
  26. }
  27.  
  28. public function getData()
  29. {
  30. if (isset($this->loadedData)) {
  31. return $this->loadedData;
  32. }
  33.  
  34. $items = $this->collection->getItems();
  35. $this->loadedData = array();
  36.  
  37. /** @var Customer $customer */
  38. foreach ($items as $contact) {
  39. // notre fieldset s'apelle "contact" d'ou ce tableau pour que magento puisse retrouver ses datas :
  40. $this->loadedData[$contact->getId()]['contact'] = $contact->getData();
  41. }
  42.  
  43.  
  44. return $this->loadedData;
  45.  
  46. }
  47. }
  48.  
  49. <?php
  50.  
  51. namespace MyModuleModelResourceModelSave;
  52.  
  53. use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
  54.  
  55. class Collection extends AbstractCollection
  56. {
  57. public function _construct()
  58. {
  59. $this->_init('MyModuleModelSave', 'MyModuleModelResourceModelSave');
  60.  
  61. }
  62. }
  63.  
  64. public function _initSelect()
  65. {
  66. parent::_initSelect();
  67.  
  68. $this->getSelect()->joinLeft(
  69. ['secondTable' => $this->getTable('SECOND_TABLE_NAME')],
  70. 'main_table.COULMN_NAME_TO_JOIN_TABLE1 = secondTable.COULMN_NAME_TO_JOIN_TABLE2',
  71. ['COLUMN_U_WANT_TO_ADD'=>'COLUMN_NAME_OF_NEW_COLUMN']
  72. );
  73. $this->addFilterToMap('COLUMN_U_WANT_TO_ADD', 'secondTable.COLUMN_NAME_OF_NEW_COLUMN');
  74. }
RAW Paste Data