Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
GridStructure Class Reference
Inheritance diagram for GridStructure:
IndexStructureInterface

Public Member Functions

 __construct (ResourceConnection $resource, FlatScopeResolver $flatScopeResolver, array $columnTypesMap=[])
 
 delete ($index, array $dimensions=[])
 
 create ($index, array $fields, array $dimensions=[])
 

Protected Member Functions

 createFlatTable ($tableName, array $fields)
 

Protected Attributes

 $columnTypesMap
 

Detailed Description

Definition at line 14 of file GridStructure.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resource,
FlatScopeResolver  $flatScopeResolver,
array  $columnTypesMap = [] 
)
Parameters
ResourceConnection$resource
FlatScopeResolver$flatScopeResolver
array$columnTypesMap

Definition at line 44 of file GridStructure.php.

48  {
49  $this->resource = $resource;
50  $this->flatScopeResolver = $flatScopeResolver;
51  $this->columnTypesMap = array_merge($this->columnTypesMap, $columnTypesMap);
52  }

Member Function Documentation

◆ create()

create (   $index,
array  $fields,
array  $dimensions = [] 
)
Parameters
string$index
array$fields
Dimension[]$dimensions
Returns
void

Implements IndexStructureInterface.

Definition at line 74 of file GridStructure.php.

75  {
76  $this->createFlatTable($this->flatScopeResolver->resolve($index, $dimensions), $fields);
77  }
$fields
Definition: details.phtml:14
createFlatTable($tableName, array $fields)
$index
Definition: list.phtml:44

◆ createFlatTable()

createFlatTable (   $tableName,
array  $fields 
)
protected
Parameters
string$tableName
array$fields
Exceptions

Definition at line 85 of file GridStructure.php.

86  {
87  $adapter = $this->getAdapter();
88  $table = $adapter->newTable($tableName);
89  $table->addColumn(
90  'entity_id',
92  10,
93  ['unsigned' => true, 'nullable' => false, 'primary' => true],
94  'Entity ID'
95  );
96  $searchableFields = [];
97  foreach ($fields as $field) {
98  if ($field['type'] === 'searchable') {
99  $searchableFields[] = $field['name'];
100  }
101  $columnMap = isset($field['dataType']) && isset($this->columnTypesMap[$field['dataType']])
102  ? $this->columnTypesMap[$field['dataType']]
103  : ['type' => $field['dataType'], 'size' => isset($field['size']) ? $field['size'] : null];
104  $name = $field['name'];
105  $type = $columnMap['type'];
106  $size = $columnMap['size'];
107  if ($field['type'] === 'filterable') {
108  $table->addIndex(
109  $this->resource->getIdxName($tableName, $name, AdapterInterface::INDEX_TYPE_INDEX),
110  $name,
112  );
113  }
114  $table->addColumn($name, $type, $size);
115  }
116  $table->addIndex(
117  $this->resource->getIdxName(
118  $tableName,
119  $searchableFields,
121  ),
122  $searchableFields,
124  );
125  $adapter->createTable($table);
126  }
$tableName
Definition: trigger.php:13
$fields
Definition: details.phtml:14
$adapter
Definition: webapi_user.php:16
$type
Definition: item.phtml:13
$table
Definition: trigger.php:14
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ delete()

delete (   $index,
array  $dimensions = [] 
)
Parameters
string$index
Dimension[]$dimensions
Returns
void

Implements IndexStructureInterface.

Definition at line 59 of file GridStructure.php.

60  {
61  $adapter = $this->getAdapter();
62  $tableName = $this->flatScopeResolver->resolve($index, $dimensions);
63  if ($adapter->isTableExists($tableName)) {
64  $adapter->dropTable($tableName);
65  }
66  }
$tableName
Definition: trigger.php:13
$adapter
Definition: webapi_user.php:16
$index
Definition: list.phtml:44

Field Documentation

◆ $columnTypesMap

$columnTypesMap
protected
Initial value:
= [
'varchar' => ['type' => Table::TYPE_TEXT, 'size' => 255],
'mediumtext' => ['type' => Table::TYPE_TEXT, 'size' => 16777216],
'text' => ['type' => Table::TYPE_TEXT, 'size' => 65536],
'int' => ['type' => Table::TYPE_INTEGER, 'size' => null],
'date' => ['type' => Table::TYPE_DATE, 'size' => null],
'datetime' => ['type' => Table::TYPE_DATETIME, 'size' => null],
'timestamp' => ['type' => Table::TYPE_TIMESTAMP, 'size' => null],
]

Definition at line 29 of file GridStructure.php.


The documentation for this class was generated from the following file: