Collection.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\ResourceModel\Importer;
  3. class Collection extends
  4. \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  5. {
  6. /**
  7. * @var string
  8. */
  9. protected $_idFieldName = 'id';
  10. /**
  11. * Initialize resource collection.
  12. *
  13. * @return null
  14. */
  15. public function _construct()
  16. {
  17. $this->_init(
  18. \Dotdigitalgroup\Email\Model\Importer::class,
  19. \Dotdigitalgroup\Email\Model\ResourceModel\Importer::class
  20. );
  21. }
  22. /**
  23. * Reset collection.
  24. *
  25. * @return null
  26. */
  27. public function reset()
  28. {
  29. $this->_reset();
  30. }
  31. /**
  32. * Get imports marked as importing.
  33. *
  34. * @param int $limit
  35. *
  36. * @return $this|boolean
  37. */
  38. public function getItemsWithImportingStatus($limit)
  39. {
  40. $collection = $this->addFieldToFilter(
  41. 'import_status',
  42. ['eq' => \Dotdigitalgroup\Email\Model\Importer::IMPORTING]
  43. )
  44. ->addFieldToFilter('import_id', ['neq' => ''])
  45. ->setPageSize($limit)
  46. ->setCurPage(1);
  47. if ($collection->getSize()) {
  48. return $collection;
  49. }
  50. return false;
  51. }
  52. /**
  53. * Get the imports by type and mode.
  54. *
  55. * @param string $importType
  56. * @param string $importMode
  57. * @param int $limit
  58. *
  59. * @return $this
  60. */
  61. public function getQueueByTypeAndMode($importType, $importMode, $limit)
  62. {
  63. if (is_array($importType)) {
  64. $condition = [];
  65. foreach ($importType as $type) {
  66. if ($type == 'Catalog') {
  67. $condition[] = ['like' => $type . '%'];
  68. } else {
  69. $condition[] = ['eq' => $type];
  70. }
  71. }
  72. $this->addFieldToFilter('import_type', $condition);
  73. } else {
  74. $this->addFieldToFilter(
  75. 'import_type',
  76. ['eq' => $importType]
  77. );
  78. }
  79. $this->addFieldToFilter('import_mode', ['eq' => $importMode])
  80. ->addFieldToFilter(
  81. 'import_status',
  82. ['eq' => \Dotdigitalgroup\Email\Model\Importer::NOT_IMPORTED]
  83. )
  84. ->setPageSize($limit)
  85. ->setCurPage(1);
  86. return $this;
  87. }
  88. }