Collection.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Report event collection
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Reports\Model\ResourceModel\Event;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  17. {
  18. /**
  19. * Store Ids
  20. *
  21. * @var array
  22. */
  23. protected $_storeIds;
  24. /**
  25. * Resource initializations
  26. *
  27. * @return void
  28. */
  29. protected function _construct()
  30. {
  31. $this->_init(\Magento\Reports\Model\Event::class, \Magento\Reports\Model\ResourceModel\Event::class);
  32. }
  33. /**
  34. * Add store ids filter
  35. * @codeCoverageIgnore
  36. *
  37. * @param array $storeIds
  38. * @return $this
  39. */
  40. public function addStoreFilter(array $storeIds)
  41. {
  42. $this->_storeIds = $storeIds;
  43. return $this;
  44. }
  45. /**
  46. * Add recently filter
  47. *
  48. * @param int $typeId
  49. * @param int $subjectId
  50. * @param int $subtype
  51. * @param null|int|array $ignore
  52. * @param int $limit
  53. * @return $this
  54. */
  55. public function addRecentlyFiler($typeId, $subjectId, $subtype = 0, $ignore = null, $limit = 15)
  56. {
  57. $stores = $this->getResource()->getCurrentStoreIds($this->_storeIds);
  58. $select = $this->getSelect();
  59. $select->where(
  60. 'event_type_id = ?',
  61. $typeId
  62. )->where(
  63. 'subject_id = ?',
  64. $subjectId
  65. )->where(
  66. 'subtype = ?',
  67. $subtype
  68. )->where(
  69. 'store_id IN(?)',
  70. $stores
  71. );
  72. if ($ignore) {
  73. if (is_array($ignore)) {
  74. $select->where('object_id NOT IN(?)', $ignore);
  75. } else {
  76. $select->where('object_id <> ?', $ignore);
  77. }
  78. }
  79. $select->group('object_id')->limit($limit);
  80. return $this;
  81. }
  82. }