Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Collection Class Reference
Inheritance diagram for Collection:
AbstractCollection AbstractDb SourceProviderInterface Collection ArrayInterface CollectionDataSourceInterface OptionSourceInterface ArgumentInterface

Public Member Functions

 setLinkModel (\Magento\Catalog\Model\Product\Link $linkModel)
 
 getLinkModel ()
 
 setProduct (\Magento\Catalog\Model\Product $product)
 
 getProduct ()
 
 addLinkTypeIdFilter ()
 
 addProductIdFilter ()
 
 joinAttributes ()
 
- Public Member Functions inherited from AbstractCollection
 __construct (\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null)
 
 getMainTable ()
 
 setMainTable ($table)
 
 getSelect ()
 
 addFieldToSelect ($field, $alias=null)
 
 addExpressionFieldToSelect ($alias, $expression, $fields)
 
 removeFieldFromSelect ($field, $isAlias=false)
 
 removeAllFieldsFromSelect ()
 
 setModel ($model)
 
 getModelName ()
 
 setResourceModel ($model)
 
 getResourceModelName ()
 
 getResource ()
 
 getTable ($table)
 
 getAllIds ()
 
 join ($table, $cond, $cols=' *')
 
 setResetItemsDataChanged ($flag)
 
 resetItemsDataChanged ()
 
 save ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractDb
 __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 ()
 
- Public Member Functions inherited from SourceProviderInterface
 getIdFieldName ()
 
 addFieldToFilter ($attribute, $condition=null)
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractCollection
 _construct ()
 
 _initSelect ()
 
 _initSelectFields ()
 
 _getInitialFieldsToSelect ()
 
 _initInitialFieldsToSelect ()
 
 _init ($model, $resourceModel)
 
 _beforeLoad ()
 
 _afterLoad ()
 
- Protected Member Functions inherited from AbstractDb
 _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

 $_product
 
 $_linkModel
 
 $_linkTypeId
 
- Protected Attributes inherited from AbstractCollection
 $_model
 
 $_resourceModel
 
 $_resource
 
 $_fieldsToSelect = null
 
 $_initialFieldsToSelect = null
 
 $_fieldsToSelectChanged = false
 
 $_joinedTables = []
 
 $_mainTable = null
 
 $_resetItemsDataChanged = false
 
 $_eventPrefix = ''
 
 $_eventObject = ''
 
 $_eventManager = null
 
- Protected Attributes inherited from AbstractDb
 $_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

Catalog product links collection

@api

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Since
100.0.2

Definition at line 15 of file Collection.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected

Resource initialization

Returns
void

Definition at line 43 of file Collection.php.

44  {
45  $this->_init(
46  \Magento\Catalog\Model\Product\Link::class,
47  \Magento\Catalog\Model\ResourceModel\Product\Link::class
48  );
49  }

◆ addLinkTypeIdFilter()

addLinkTypeIdFilter ( )

Add link's type to filter

Returns
$this

Definition at line 103 of file Collection.php.

104  {
105  if ($this->_linkTypeId) {
106  $this->addFieldToFilter('link_type_id', ['eq' => $this->_linkTypeId]);
107  }
108  return $this;
109  }

◆ addProductIdFilter()

addProductIdFilter ( )

Add product to filter

Returns
$this

Definition at line 116 of file Collection.php.

117  {
118  if ($this->getProduct() && $this->getProduct()->getId()) {
119  $this->addFieldToFilter('product_id', ['eq' => $this->getProduct()->getId()]);
120  }
121  return $this;
122  }

◆ getLinkModel()

getLinkModel ( )

Retrieve collection link model

Returns
\Magento\Catalog\Model\Product\Link

Definition at line 71 of file Collection.php.

◆ getProduct()

getProduct ( )

Retrieve collection base product object

Returns
\Magento\Catalog\Model\Product

Definition at line 93 of file Collection.php.

◆ joinAttributes()

joinAttributes ( )

Join attributes

Returns
$this

Definition at line 129 of file Collection.php.

130  {
131  if (!$this->getLinkModel()) {
132  return $this;
133  }
134  $attributes = $this->getLinkModel()->getAttributes();
135  $connection = $this->getConnection();
136  foreach ($attributes as $attribute) {
137  $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']);
138  $alias = sprintf('link_attribute_%s_%s', $attribute['code'], $attribute['type']);
139 
140  $aliasInCondition = $connection->quoteColumnAs($alias, null);
141  $this->getSelect()->joinLeft(
142  [$alias => $table],
143  $aliasInCondition .
144  '.link_id = main_table.link_id AND ' .
145  $aliasInCondition .
146  '.product_link_attribute_id = ' .
147  (int)$attribute['id'],
148  [$attribute['code'] => 'value']
149  );
150  }
151 
152  return $this;
153  }
$attributes
Definition: matrix.phtml:13
if(!trim($html)) $alias
Definition: details.phtml:20
$connection
Definition: bulk.php:13
$table
Definition: trigger.php:14

◆ setLinkModel()

setLinkModel ( \Magento\Catalog\Model\Product\Link  $linkModel)

Declare link model and initialize type attributes join

Parameters
\Magento\Catalog\Model\Product\Link$linkModel
Returns
$this

Definition at line 57 of file Collection.php.

58  {
59  $this->_linkModel = $linkModel;
60  if ($linkModel->hasLinkTypeId()) {
61  $this->_linkTypeId = $linkModel->getLinkTypeId();
62  }
63  return $this;
64  }

◆ setProduct()

setProduct ( \Magento\Catalog\Model\Product  $product)

Initialize collection parent product and add limitation join

Parameters
\Magento\Catalog\Model\Product$product
Returns
$this

Definition at line 82 of file Collection.php.

83  {
84  $this->_product = $product;
85  return $this;
86  }

Field Documentation

◆ $_linkModel

$_linkModel
protected

Definition at line 29 of file Collection.php.

◆ $_linkTypeId

$_linkTypeId
protected

Definition at line 36 of file Collection.php.

◆ $_product

$_product
protected

Definition at line 22 of file Collection.php.


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