Collection.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\ResourceModel\Form\Element;
  7. /**
  8. * Eav Form Element Resource Collection
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  14. {
  15. /**
  16. * Initialize collection model
  17. *
  18. * @return void
  19. * @codeCoverageIgnore
  20. */
  21. protected function _construct()
  22. {
  23. $this->_init(\Magento\Eav\Model\Form\Element::class, \Magento\Eav\Model\ResourceModel\Form\Element::class);
  24. }
  25. /**
  26. * Add Form Type filter to collection
  27. *
  28. * @param \Magento\Eav\Model\Form\Type|int $type
  29. * @return $this
  30. */
  31. public function addTypeFilter($type)
  32. {
  33. if ($type instanceof \Magento\Eav\Model\Form\Type) {
  34. $type = $type->getId();
  35. }
  36. return $this->addFieldToFilter('type_id', $type);
  37. }
  38. /**
  39. * Add Form Fieldset filter to collection
  40. *
  41. * @param \Magento\Eav\Model\Form\Fieldset|int $fieldset
  42. * @return $this
  43. */
  44. public function addFieldsetFilter($fieldset)
  45. {
  46. if ($fieldset instanceof \Magento\Eav\Model\Form\Fieldset) {
  47. $fieldset = $fieldset->getId();
  48. }
  49. return $this->addFieldToFilter('fieldset_id', $fieldset);
  50. }
  51. /**
  52. * Add Attribute filter to collection
  53. *
  54. * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|int $attribute
  55. *
  56. * @return $this
  57. */
  58. public function addAttributeFilter($attribute)
  59. {
  60. if ($attribute instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute) {
  61. $attribute = $attribute->getId();
  62. }
  63. return $this->addFieldToFilter('attribute_id', $attribute);
  64. }
  65. /**
  66. * Set order by element sort order
  67. *
  68. * @return $this
  69. * @codeCoverageIgnore
  70. */
  71. public function setSortOrder()
  72. {
  73. $this->setOrder('sort_order', self::SORT_ORDER_ASC);
  74. return $this;
  75. }
  76. /**
  77. * Join attribute data
  78. *
  79. * @return $this
  80. */
  81. protected function _joinAttributeData()
  82. {
  83. $this->getSelect()->join(
  84. ['eav_attribute' => $this->getTable('eav_attribute')],
  85. 'main_table.attribute_id = eav_attribute.attribute_id',
  86. ['attribute_code', 'entity_type_id']
  87. );
  88. return $this;
  89. }
  90. /**
  91. * Load data (join attribute data)
  92. *
  93. * @param bool $printQuery
  94. * @param bool $logQuery
  95. * @return $this
  96. */
  97. public function load($printQuery = false, $logQuery = false)
  98. {
  99. if (!$this->isLoaded()) {
  100. $this->_joinAttributeData();
  101. }
  102. return parent::load($printQuery, $logQuery);
  103. }
  104. }