Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractDb Class Reference
Inheritance diagram for AbstractDb:
Collection ArrayInterface CollectionDataSourceInterface OptionSourceInterface ArgumentInterface AbstractCollection DbCollection AbstractCollection AbstractCollection AbstractCollection AbstractCollectionStub Collection Critical Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection ProductCollection Collection AbstractCollection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Uut SearchResult Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection LowQuantityCollection TableCollection MessageCollection MessageStatusCollection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection AbstractCollection Collection Collection Collection Collection Collection Collection Collection AbstractCollection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Scoped Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection UrlRewriteCollection Collection Collection Collection Collection Collection Collection Collection Collection Collection Collection

Public Member Functions

 __construct (EntityFactoryInterface $entityFactory, Logger $logger, FetchStrategyInterface $fetchStrategy, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
 
 getResource ()
 
 addBindParam ($name, $value)
 
 getIdFieldName ()
 
 setConnection (\Magento\Framework\DB\Adapter\AdapterInterface $conn)
 
 getSelect ()
 
 getConnection ()
 
 getSize ()
 
 getSelectCountSql ()
 
 getSelectSql ($stringMode=false)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 unshiftOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addFieldToFilter ($field, $condition=null)
 
 distinct ($flag)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 fetchItem ()
 
 getData ()
 
 resetData ()
 
 loadData ($printQuery=false, $logQuery=false)
 
 printLogQuery ($printQuery=false, $logQuery=false, $sql=null)
 
 addFilterToMap ($filter, $alias, $group='fields')
 
 __clone ()
 
 joinExtensionAttribute (JoinDataInterface $join, JoinProcessorInterface $extensionAttributesJoinProcessor)
 
 getItemObjectClass ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from Collection
 __construct (EntityFactoryInterface $entityFactory)
 
 addFilter ($field, $value, $type='and')
 
 addFieldToFilter ($field, $condition)
 
 getFilter ($field)
 
 isLoaded ()
 
 getCurPage ($displacement=0)
 
 getLastPageNumber ()
 
 getPageSize ()
 
 getSize ()
 
 getFirstItem ()
 
 getLastItem ()
 
 getItems ()
 
 getColumnValues ($colName)
 
 getItemsByColumnValue ($column, $value)
 
 getItemByColumnValue ($column, $value)
 
 addItem (\Magento\Framework\DataObject $item)
 
 getAllIds ()
 
 removeItemByKey ($key)
 
 removeAllItems ()
 
 clear ()
 
 walk ($callback, array $args=[])
 
 each ($objMethod, $args=[])
 
 setDataToAll ($key, $value=null)
 
 setCurPage ($page)
 
 setPageSize ($size)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 setItemObjectClass ($className)
 
 getNewEmptyItem ()
 
 distinct ($flag)
 
 loadData ($printQuery=false, $logQuery=false)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 toXml ()
 
 toArray ($arrRequiredFields=[])
 
 toOptionArray ()
 
 toOptionHash ()
 
 getItemById ($idValue)
 
 getIterator ()
 
 count ()
 
 getFlag ($flag)
 
 setFlag ($flag, $value=null)
 
 hasFlag ($flag)
 
 __sleep ()
 
 __wakeup ()
 

Protected Member Functions

 _setIdFieldName ($fieldName)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderFiltersBefore ()
 
 _translateCondition ($field, $condition)
 
 _getMappedField ($field)
 
 _getMapper ()
 
 _getConditionSql ($fieldName, $condition)
 
 _getConditionFieldName ($fieldName)
 
 _renderOrders ()
 
 _renderLimit ()
 
 _beforeLoad ()
 
 beforeAddLoadedItem (\Magento\Framework\DataObject $item)
 
 _toOptionArray ($valueField=null, $labelField='name', $additional=[])
 
 _toOptionHash ($valueField=null, $labelField='name')
 
 _afterLoadData ()
 
 _afterLoad ()
 
 _logQuery ($sql)
 
 _reset ()
 
 _fetchAll (Select $select)
 
 _initSelect ()
 
- Protected Member Functions inherited from Collection
 _setIsLoaded ($flag=true)
 
 _addItem ($item)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderOrders ()
 
 _renderLimit ()
 
 _toOptionArray ($valueField='id', $labelField='name', $additional=[])
 
 _toOptionHash ($valueField='id', $labelField='name')
 

Protected Attributes

 $_conn
 
 $_select
 
 $_idFieldName
 
 $_bindParams = []
 
 $_data = null
 
 $_map = null
 
 $_fetchStmt = null
 
 $_isOrdersRendered = false
 
 $_logger
 
 $extensionAttributesJoinProcessor
 
- Protected Attributes inherited from Collection
 $_items = []
 
 $_itemObjectClass = \Magento\Framework\DataObject::class
 
 $_orders = []
 
 $_filters = []
 
 $_isFiltersRendered = false
 
 $_curPage = 1
 
 $_pageSize = false
 
 $_totalRecords
 
 $_isCollectionLoaded
 
 $_flags = []
 
 $_entityFactory
 

Additional Inherited Members

- Data Fields inherited from Collection
const SORT_ORDER_ASC = 'ASC'
 
const SORT_ORDER_DESC = 'DESC'
 

Detailed Description

Base items collection class

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 23 of file AbstractDb.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( EntityFactoryInterface  $entityFactory,
Logger  $logger,
FetchStrategyInterface  $fetchStrategy,
\Magento\Framework\DB\Adapter\AdapterInterface  $connection = null 
)
Parameters
EntityFactoryInterface$entityFactory
Logger$logger
FetchStrategyInterface$fetchStrategy
\Magento\Framework\DB\Adapter\AdapterInterface$connection

Definition at line 107 of file AbstractDb.php.

112  {
113  parent::__construct($entityFactory);
114  $this->_fetchStrategy = $fetchStrategy;
115  if ($connection !== null) {
116  $this->setConnection($connection);
117  }
118  $this->_logger = $logger;
119  }
$logger
setConnection(\Magento\Framework\DB\Adapter\AdapterInterface $conn)
Definition: AbstractDb.php:184
$connection
Definition: bulk.php:13

Member Function Documentation

◆ __clone()

__clone ( )

Clone $this->_select during cloning collection, otherwise both collections will share the same $this->_select

Returns
void

Definition at line 815 of file AbstractDb.php.

816  {
817  if (is_object($this->_select)) {
818  $this->_select = clone $this->_select;
819  }
820  }

◆ __sleep()

__sleep ( )
Since
100.0.11

Definition at line 895 of file AbstractDb.php.

896  {
897  return array_diff(
898  parent::__sleep(),
899  ['_fetchStrategy', '_logger', '_conn', 'extensionAttributesJoinProcessor']
900  );
901  }

◆ __wakeup()

__wakeup ( )
Since
100.0.11

Definition at line 907 of file AbstractDb.php.

908  {
911  $this->_logger = $objectManager->get(Logger::class);
912  $this->_fetchStrategy = $objectManager->get(FetchStrategyInterface::class);
913  $this->_conn = $objectManager->get(ResourceConnection::class)->getConnection();
914  }
$objectManager
Definition: bootstrap.php:17

◆ _afterLoad()

_afterLoad ( )
protected

Process loaded collection

Returns
$this

Definition at line 706 of file AbstractDb.php.

707  {
708  return $this;
709  }

◆ _afterLoadData()

_afterLoadData ( )
protected

Process loaded collection data

Returns
$this

Definition at line 685 of file AbstractDb.php.

686  {
687  return $this;
688  }

◆ _beforeLoad()

_beforeLoad ( )
protected

Before load action

Returns
$this

Definition at line 544 of file AbstractDb.php.

545  {
546  return $this;
547  }

◆ _fetchAll()

_fetchAll ( Select  $select)
protected

Fetch collection data

Parameters
Select$select
Returns
array

Definition at line 776 of file AbstractDb.php.

777  {
778  $data = $this->_fetchStrategy->fetchAll($select, $this->_bindParams);
779  if ($this->extensionAttributesJoinProcessor) {
780  foreach ($data as $key => $dataItem) {
781  $data[$key] = $this->extensionAttributesJoinProcessor->extractExtensionAttributes(
782  $this->_itemObjectClass,
783  $dataItem
784  );
785  }
786  }
787  return $data;
788  }

◆ _getConditionFieldName()

_getConditionFieldName (   $fieldName)
protected

Return the field name for the condition.

Parameters
string$fieldName
Returns
string

Definition at line 491 of file AbstractDb.php.

492  {
493  return $fieldName;
494  }

◆ _getConditionSql()

_getConditionSql (   $fieldName,
  $condition 
)
protected

Build SQL statement for condition

If $condition integer or string - exact value will be filtered ('eq' condition)

If $condition is array - one of the following structures is expected:

  • array("from" => $fromValue, "to" => $toValue)
  • array("eq" => $equalValue)
  • array("neq" => $notEqualValue)
  • array("like" => $likeValue)
  • array("in" => array($inValues))
  • array("nin" => array($notInValues))
  • array("notnull" => $valueIsNotNull)
  • array("null" => $valueIsNull)
  • array("moreq" => $moreOrEqualValue)
  • array("gt" => $greaterValue)
  • array("lt" => $lessValue)
  • array("gteq" => $greaterOrEqualValue)
  • array("lteq" => $lessOrEqualValue)
  • array("finset" => $valueInSet)
  • array("regexp" => $regularExpression)
  • array("seq" => $stringValue)
  • array("sneq" => $stringValue)

If non matched - sequential array is expected and OR conditions will be built using above mentioned structure

Parameters
string$fieldName
integer | string | array$condition
Returns
string

Definition at line 480 of file AbstractDb.php.

481  {
482  return $this->getConnection()->prepareSqlCondition($fieldName, $condition);
483  }

◆ _getItemId()

_getItemId ( \Magento\Framework\DataObject  $item)
protected

Get collection item identifier

Parameters
\Magento\Framework\DataObject$item
Returns
mixed

Definition at line 169 of file AbstractDb.php.

170  {
171  if ($field = $this->getIdFieldName()) {
172  return $item->getData($field);
173  }
174  return parent::_getItemId($item);
175  }

◆ _getMappedField()

_getMappedField (   $field)
protected

Try to get mapped field name for filter to collection

Parameters
string$field
Returns
string

Definition at line 422 of file AbstractDb.php.

423  {
424  $mapper = $this->_getMapper();
425 
426  if (isset($mapper['fields'][$field])) {
427  $mappedField = $mapper['fields'][$field];
428  } else {
429  $mappedField = $field;
430  }
431 
432  return $mappedField;
433  }

◆ _getMapper()

_getMapper ( )
protected

Retrieve mapper data

Returns
array|bool|null

Definition at line 440 of file AbstractDb.php.

441  {
442  if (isset($this->_map)) {
443  return $this->_map;
444  } else {
445  return false;
446  }
447  }

◆ _initSelect()

_initSelect ( )
protected

Init select

Returns
void

Definition at line 827 of file AbstractDb.php.

828  {
829  // no implementation, should be overridden in children classes
830  }

◆ _logQuery()

_logQuery (   $sql)
protected

Log query

Parameters
string$sql
Returns
void

Definition at line 749 of file AbstractDb.php.

750  {
751  $this->_logger->info($sql === null ? $this->getSelect()->__toString() : $sql);
752  }

◆ _renderFilters()

_renderFilters ( )
protected

Render sql select conditions

Returns
$this

Definition at line 336 of file AbstractDb.php.

337  {
338  if ($this->_isFiltersRendered) {
339  return $this;
340  }
341 
342  $this->_renderFiltersBefore();
343 
344  foreach ($this->_filters as $filter) {
345  switch ($filter['type']) {
346  case 'or':
347  $condition = $this->_conn->quoteInto($filter['field'] . '=?', $filter['value']);
348  $this->_select->orWhere($condition);
349  break;
350  case 'string':
351  $this->_select->where($filter['value']);
352  break;
353  case 'public':
354  $field = $this->_getMappedField($filter['field']);
355  $condition = $filter['value'];
356  $this->_select->where($this->_getConditionSql($field, $condition), null, Select::TYPE_CONDITION);
357  break;
358  default:
359  $condition = $this->_conn->quoteInto($filter['field'] . '=?', $filter['value']);
360  $this->_select->where($condition);
361  }
362  }
363  $this->_isFiltersRendered = true;
364  return $this;
365  }

◆ _renderFiltersBefore()

_renderFiltersBefore ( )
protected

Hook for operations before rendering filters

Returns
void

Definition at line 372 of file AbstractDb.php.

373  {
374  }

◆ _renderLimit()

_renderLimit ( )
protected

Render sql select limit

Returns
$this

Definition at line 518 of file AbstractDb.php.

519  {
520  if ($this->_pageSize) {
521  $this->_select->limitPage($this->getCurPage(), $this->_pageSize);
522  }
523 
524  return $this;
525  }

◆ _renderOrders()

_renderOrders ( )
protected

Render sql select orders

Returns
$this

Definition at line 501 of file AbstractDb.php.

502  {
503  if (!$this->_isOrdersRendered) {
504  foreach ($this->_orders as $field => $direction) {
505  $this->_select->order(new \Zend_Db_Expr($field . ' ' . $direction));
506  }
507  $this->_isOrdersRendered = true;
508  }
509 
510  return $this;
511  }

◆ _reset()

_reset ( )
protected

Reset collection

Returns
$this

Definition at line 759 of file AbstractDb.php.

760  {
761  $this->getSelect()->reset();
762  $this->_initSelect();
763  $this->_setIsLoaded(false);
764  $this->_items = [];
765  $this->_data = null;
766  $this->extensionAttributesJoinProcessor = null;
767  return $this;
768  }

◆ _setIdFieldName()

_setIdFieldName (   $fieldName)
protected

Specify collection objects id field name

Parameters
string$fieldName
Returns
$this

Definition at line 147 of file AbstractDb.php.

148  {
149  $this->_idFieldName = $fieldName;
150  return $this;
151  }

◆ _toOptionArray()

_toOptionArray (   $valueField = null,
  $labelField = 'name',
  $additional = [] 
)
protected

Overridden to use _idFieldName by default.

Parameters
string | null$valueField
string$labelField
array$additional
Returns
array

Definition at line 641 of file AbstractDb.php.

642  {
643  if ($valueField === null) {
644  $valueField = $this->getIdFieldName();
645  }
646  return parent::_toOptionArray($valueField, $labelField, $additional);
647  }

◆ _toOptionHash()

_toOptionHash (   $valueField = null,
  $labelField = 'name' 
)
protected

Overridden to use _idFieldName by default.

Parameters
string$valueField
string$labelField
Returns
array

Definition at line 656 of file AbstractDb.php.

657  {
658  if ($valueField === null) {
659  $valueField = $this->getIdFieldName();
660  }
661  return parent::_toOptionHash($valueField, $labelField);
662  }

◆ _translateCondition()

_translateCondition (   $field,
  $condition 
)
protected

Build sql where condition part

Parameters
string | array$field
null | string | array$condition
Returns
string

Definition at line 410 of file AbstractDb.php.

411  {
412  $field = $this->_getMappedField($field);
413  return $this->_getConditionSql($this->getConnection()->quoteIdentifier($field), $condition);
414  }

◆ addBindParam()

addBindParam (   $name,
  $value 
)

Add variable to bind list

Parameters
string$name
mixed$value
Returns
$this

Definition at line 135 of file AbstractDb.php.

136  {
137  $this->_bindParams[$name] = $value;
138  return $this;
139  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ addFieldToFilter()

addFieldToFilter (   $field,
  $condition = null 
)

Add field filter to collection

See also
self::_getConditionSql for $condition
Parameters
string | array$field
null | string | array$condition
Returns
$this

Definition at line 385 of file AbstractDb.php.

386  {
387  if (is_array($field)) {
388  $conditions = [];
389  foreach ($field as $key => $value) {
390  $conditions[] = $this->_translateCondition($value, isset($condition[$key]) ? $condition[$key] : null);
391  }
392 
393  $resultCondition = '(' . implode(') ' . \Magento\Framework\DB\Select::SQL_OR . ' (', $conditions) . ')';
394  } else {
395  $resultCondition = $this->_translateCondition($field, $condition);
396  }
397 
398  $this->_select->where($resultCondition, null, Select::TYPE_CONDITION);
399 
400  return $this;
401  }
$value
Definition: gender.phtml:16
const SQL_OR
Definition: Select.php:79

◆ addFilterToMap()

addFilterToMap (   $filter,
  $alias,
  $group = 'fields' 
)

Add filter to Map

Parameters
string$filter
string$alias
string$groupdefault 'fields'
Returns
$this

Definition at line 798 of file AbstractDb.php.

799  {
800  if ($this->_map === null) {
801  $this->_map = [$group => []];
802  } elseif (empty($this->_map[$group])) {
803  $this->_map[$group] = [];
804  }
805  $this->_map[$group][$filter] = $alias;
806 
807  return $this;
808  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$group
Definition: sections.phtml:16
if(!trim($html)) $alias
Definition: details.phtml:20

◆ addOrder()

addOrder (   $field,
  $direction = self::SORT_ORDER_DESC 
)

Sets order and direction.

Parameters
string$field
string$direction
Returns
$this

Definition at line 286 of file AbstractDb.php.

287  {
288  return $this->_setOrder($field, $direction);
289  }

◆ beforeAddLoadedItem()

beforeAddLoadedItem ( \Magento\Framework\DataObject  $item)
protected

Let do something before add loaded item in collection

Parameters
\Magento\Framework\DataObject$item
Returns
\Magento\Framework\DataObject

Definition at line 601 of file AbstractDb.php.

602  {
603  return $item;
604  }

◆ distinct()

distinct (   $flag)

Set select distinct

Parameters
bool$flag
Returns
$this

Definition at line 533 of file AbstractDb.php.

534  {
535  $this->_select->distinct($flag);
536  return $this;
537  }

◆ fetchItem()

fetchItem ( )

Returns an items collection. Returns a collection item that corresponds to the fetched row and moves the internal data pointer ahead

Returns
\Magento\Framework\Model\AbstractModel|bool

Definition at line 613 of file AbstractDb.php.

614  {
615  if (null === $this->_fetchStmt) {
616  $this->_renderOrders()->_renderLimit();
617 
618  $this->_fetchStmt = $this->getConnection()->query($this->getSelect());
619  }
620  $data = $this->_fetchStmt->fetch();
621  if (!empty($data) && is_array($data)) {
622  $item = $this->getNewEmptyItem();
623  if ($this->getIdFieldName()) {
624  $item->setIdFieldName($this->getIdFieldName());
625  }
626  $item->setData($data);
627 
628  return $item;
629  }
630  return false;
631  }

◆ getConnection()

getConnection ( )

Retrieve connection object

Returns
AdapterInterface

Definition at line 207 of file AbstractDb.php.

◆ getData()

getData ( )

Get all data array for collection

Returns
array

Definition at line 669 of file AbstractDb.php.

670  {
671  if ($this->_data === null) {
672  $this->_renderFilters()->_renderOrders()->_renderLimit();
673  $select = $this->getSelect();
674  $this->_data = $this->_fetchAll($select);
675  $this->_afterLoadData();
676  }
677  return $this->_data;
678  }

◆ getIdFieldName()

getIdFieldName ( )

Id field name getter

Returns
string

Definition at line 158 of file AbstractDb.php.

◆ getItemObjectClass()

getItemObjectClass ( )

Get collection item object class name.

Returns
string

Definition at line 870 of file AbstractDb.php.

871  {
873  }

◆ getResource()

getResource ( )
abstract

Get resource instance.

Returns
\Magento\Framework\Model\ResourceModel\Db\AbstractDb

◆ getSelect()

getSelect ( )

Get \Magento\Framework\DB\Select instance

Returns
Select

Definition at line 197 of file AbstractDb.php.

◆ getSelectCountSql()

getSelectCountSql ( )

Get SQL for get record count

Returns
Select

Definition at line 231 of file AbstractDb.php.

232  {
233  $this->_renderFilters();
234 
235  $countSelect = clone $this->getSelect();
236  $countSelect->reset(\Magento\Framework\DB\Select::ORDER);
237  $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
238  $countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
239  $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
240 
241  $part = $this->getSelect()->getPart(\Magento\Framework\DB\Select::GROUP);
242  if (!is_array($part) || !count($part)) {
243  $countSelect->columns(new \Zend_Db_Expr('COUNT(*)'));
244  return $countSelect;
245  }
246 
247  $countSelect->reset(\Magento\Framework\DB\Select::GROUP);
248  $group = $this->getSelect()->getPart(\Magento\Framework\DB\Select::GROUP);
249  $countSelect->columns(new \Zend_Db_Expr(("COUNT(DISTINCT ".implode(", ", $group).")")));
250  return $countSelect;
251  }
const ORDER
Definition: Select.php:54
$group
Definition: sections.phtml:16
const COLUMNS
Definition: Select.php:48
const LIMIT_OFFSET
Definition: Select.php:56
const GROUP
Definition: Select.php:52
const LIMIT_COUNT
Definition: Select.php:55

◆ getSelectSql()

getSelectSql (   $stringMode = false)

Get sql select string or object

Parameters
bool$stringMode
Returns
string|\Magento\Framework\DB\Select

Definition at line 259 of file AbstractDb.php.

260  {
261  if ($stringMode) {
262  return $this->_select->__toString();
263  }
264  return $this->_select;
265  }

◆ getSize()

getSize ( )

Get collection size

Returns
int

Definition at line 217 of file AbstractDb.php.

218  {
219  if ($this->_totalRecords === null) {
220  $sql = $this->getSelectCountSql();
221  $this->_totalRecords = $this->getConnection()->fetchOne($sql, $this->_bindParams);
222  }
223  return (int)$this->_totalRecords;
224  }

◆ joinExtensionAttribute()

joinExtensionAttribute ( JoinDataInterface  $join,
JoinProcessorInterface  $extensionAttributesJoinProcessor 
)

Join extension attribute.

Parameters
JoinDataInterface$join
JoinProcessorInterface$extensionAttributesJoinProcessor
Returns
$this

Definition at line 839 of file AbstractDb.php.

842  {
843  $selectFrom = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
844  $joinRequired = !isset($selectFrom[$join->getReferenceTableAlias()]);
845  if ($joinRequired) {
846  $joinOn = $this->getMainTableAlias() . '.' . $join->getJoinField()
847  . ' = ' . $join->getReferenceTableAlias() . '.' . $join->getReferenceField();
848  $this->getSelect()->joinLeft(
849  [$join->getReferenceTableAlias() => $this->getResource()->getTable($join->getReferenceTable())],
850  $joinOn,
851  []
852  );
853  }
854  $columns = [];
855  foreach ($join->getSelectFields() as $selectField) {
856  $fieldWIthDbPrefix = $selectField[JoinDataInterface::SELECT_FIELD_WITH_DB_PREFIX];
857  $columns[$selectField[JoinDataInterface::SELECT_FIELD_INTERNAL_ALIAS]] = $fieldWIthDbPrefix;
858  $this->addFilterToMap($selectField[JoinDataInterface::SELECT_FIELD_EXTERNAL_ALIAS], $fieldWIthDbPrefix);
859  }
860  $this->getSelect()->columns($columns);
861  $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
862  return $this;
863  }
addFilterToMap($filter, $alias, $group='fields')
Definition: AbstractDb.php:798
const FROM
Definition: Select.php:49
$columns
Definition: default.phtml:15

◆ load()

load (   $printQuery = false,
  $logQuery = false 
)

Load data

Parameters
bool$printQuery
bool$logQuery
Returns
$this

Definition at line 556 of file AbstractDb.php.

557  {
558  if ($this->isLoaded()) {
559  return $this;
560  }
561 
562  return $this->loadWithFilter($printQuery, $logQuery);
563  }
loadWithFilter($printQuery=false, $logQuery=false)
Definition: AbstractDb.php:572

◆ loadData()

loadData (   $printQuery = false,
  $logQuery = false 
)

Load the data.

Parameters
bool$printQuery
bool$logQuery
Returns
$this

Definition at line 718 of file AbstractDb.php.

719  {
720  return $this->load($printQuery, $logQuery);
721  }
load($printQuery=false, $logQuery=false)
Definition: AbstractDb.php:556

◆ loadWithFilter()

loadWithFilter (   $printQuery = false,
  $logQuery = false 
)

Load data with filter in place

Parameters
bool$printQuery
bool$logQuery
Returns
$this

Definition at line 572 of file AbstractDb.php.

573  {
574  $this->_beforeLoad();
575  $this->_renderFilters()->_renderOrders()->_renderLimit();
576  $this->printLogQuery($printQuery, $logQuery);
577  $data = $this->getData();
578  $this->resetData();
579  if (is_array($data)) {
580  foreach ($data as $row) {
581  $item = $this->getNewEmptyItem();
582  if ($this->getIdFieldName()) {
583  $item->setIdFieldName($this->getIdFieldName());
584  }
585  $item->addData($row);
586  $this->beforeAddLoadedItem($item);
587  $this->addItem($item);
588  }
589  }
590  $this->_setIsLoaded();
591  $this->_afterLoad();
592  return $this;
593  }
printLogQuery($printQuery=false, $logQuery=false, $sql=null)
Definition: AbstractDb.php:731
beforeAddLoadedItem(\Magento\Framework\DataObject $item)
Definition: AbstractDb.php:601
addItem(\Magento\Framework\DataObject $item)
Definition: Collection.php:399

◆ printLogQuery()

printLogQuery (   $printQuery = false,
  $logQuery = false,
  $sql = null 
)

Print and/or log query

Parameters
bool$printQuery
bool$logQuery
string$sql
Returns
$this

Definition at line 731 of file AbstractDb.php.

732  {
733  if ($printQuery || $this->getFlag('print_query')) {
734  echo $sql === null ? $this->getSelect()->__toString() : $sql;
735  }
736 
737  if ($logQuery || $this->getFlag('log_query')) {
738  $this->_logQuery($sql);
739  }
740  return $this;
741  }

◆ resetData()

resetData ( )

Reset loaded for collection data array

Returns
$this

Definition at line 695 of file AbstractDb.php.

696  {
697  $this->_data = null;
698  return $this;
699  }

◆ setConnection()

Set database connection adapter

Parameters
\Magento\Framework\DB\Adapter\AdapterInterface$conn
Returns
$this
Exceptions

Definition at line 184 of file AbstractDb.php.

185  {
186  $this->_conn = $conn;
187  $this->_select = $this->_conn->select();
188  $this->_isOrdersRendered = false;
189  return $this;
190  }

◆ setOrder()

setOrder (   $field,
  $direction = self::SORT_ORDER_DESC 
)

Add select order

Parameters
string$field
string$direction
Returns
$this

Definition at line 274 of file AbstractDb.php.

275  {
276  return $this->_setOrder($field, $direction);
277  }

◆ unshiftOrder()

unshiftOrder (   $field,
  $direction = self::SORT_ORDER_DESC 
)

Add select order to the beginning

Parameters
string$field
string$direction
Returns
$this

Definition at line 298 of file AbstractDb.php.

299  {
300  return $this->_setOrder($field, $direction, true);
301  }

Field Documentation

◆ $_bindParams

$_bindParams = []
protected

Definition at line 53 of file AbstractDb.php.

◆ $_conn

$_conn
protected

Definition at line 30 of file AbstractDb.php.

◆ $_data

$_data = null
protected

Definition at line 61 of file AbstractDb.php.

◆ $_fetchStmt

$_fetchStmt = null
protected

Definition at line 75 of file AbstractDb.php.

◆ $_idFieldName

$_idFieldName
protected

Definition at line 46 of file AbstractDb.php.

◆ $_isOrdersRendered

$_isOrdersRendered = false
protected

Definition at line 82 of file AbstractDb.php.

◆ $_logger

$_logger
protected

Definition at line 87 of file AbstractDb.php.

◆ $_map

$_map = null
protected

Definition at line 68 of file AbstractDb.php.

◆ $_select

$_select
protected

Definition at line 37 of file AbstractDb.php.

◆ $extensionAttributesJoinProcessor

$extensionAttributesJoinProcessor
protected

Definition at line 99 of file AbstractDb.php.


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