Collection.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Widget\Model\ResourceModel\Widget\Instance;
  7. /**
  8. * Widget Instance Collection
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  14. {
  15. /**
  16. * Fields map for correlation names & real selected fields
  17. *
  18. * @var array
  19. */
  20. protected $_map = ['fields' => ['type' => 'instance_type']];
  21. /**
  22. * Constructor
  23. *
  24. * @return void
  25. */
  26. protected function _construct()
  27. {
  28. parent::_construct();
  29. $this->_init(
  30. \Magento\Widget\Model\Widget\Instance::class,
  31. \Magento\Widget\Model\ResourceModel\Widget\Instance::class
  32. );
  33. }
  34. /**
  35. * Filter by store ids
  36. *
  37. * @param array|int $storeIds
  38. * @param bool $withDefaultStore if TRUE also filter by store id '0'
  39. * @return $this
  40. */
  41. public function addStoreFilter($storeIds = [], $withDefaultStore = true)
  42. {
  43. if (!is_array($storeIds)) {
  44. $storeIds = [$storeIds];
  45. }
  46. if ($withDefaultStore && !in_array('0', $storeIds)) {
  47. array_unshift($storeIds, 0);
  48. }
  49. $where = [];
  50. foreach ($storeIds as $storeId) {
  51. $where[] = $this->_getConditionSql('store_ids', ['finset' => $storeId]);
  52. }
  53. $this->_select->where(implode(' OR ', $where));
  54. return $this;
  55. }
  56. }