Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Helper.php
Go to the documentation of this file.
1 <?php
7 
15 {
23  public function __construct(\Magento\Framework\App\ResourceConnection $resource, $modulePrefix = 'Magento_Eav')
24  {
25  parent::__construct($resource, $modulePrefix);
26  }
27 
33  protected $_ddlColumnTypes = [
47  ];
48 
60  private $_groupableTypes = ['varchar', 'text', 'decimal', 'datetime', 'int'];
61 
68  public function getDdlTypeByColumnType($columnType)
69  {
70  switch ($columnType) {
71  case 'char':
72  case 'varchar':
73  $columnType = 'text';
74  break;
75  case 'tinyint':
76  $columnType = 'smallint';
77  break;
78  default:
79  break;
80  }
81 
82  return array_search($columnType, $this->_ddlColumnTypes);
83  }
84 
105  public function getLoadAttributesSelectGroups($selects)
106  {
107  $mainGroup = [];
108 
109  foreach ($selects as $dataType => $selectGroup) {
110  if (in_array($dataType, $this->_groupableTypes)) {
111  $mainGroup['all'][] = $selectGroup;
112  continue;
113  }
114 
115  $mainGroup[$dataType] = $selectGroup;
116  }
117 
118  if (array_key_exists('all', $mainGroup)) {
119  // it is better to call array_merge once after loop instead of calling it on each loop
120  $mainGroup['all'] = array_merge(...$mainGroup['all']);
121  }
122 
123  return array_values($mainGroup);
124  }
125 }
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\App\ResourceConnection $resource, $modulePrefix='Magento_Eav')
Definition: Helper.php:23