LogEntrySearchResult.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Repository;
  7. use Magento\Framework\Api\SearchCriteriaInterface;
  8. use Vertex\Tax\Api\Data\LogEntrySearchResultsInterface;
  9. /**
  10. * Search result implementation for repository lookup.
  11. *
  12. * Methods duplicated from SearchResults and AbstractSimpleObject as they are not in the public API
  13. */
  14. class LogEntrySearchResult implements LogEntrySearchResultsInterface
  15. {
  16. const KEY_ITEMS = 'items';
  17. const KEY_SEARCH_CRITERIA = 'search_criteria';
  18. const KEY_TOTAL_COUNT = 'total_count';
  19. /**
  20. * @var array
  21. */
  22. private $data;
  23. /**
  24. * Initialize internal storage
  25. *
  26. * @param array $data
  27. */
  28. public function __construct(array $data = [])
  29. {
  30. $this->data = $data;
  31. }
  32. /**
  33. * Retrieves a value from the data array if set, or null otherwise.
  34. *
  35. * @param string $key
  36. * @return mixed|null
  37. */
  38. private function getData($key)
  39. {
  40. return isset($this->data[$key]) ? $this->data[$key] : null;
  41. }
  42. /**
  43. * Set value for the given key
  44. *
  45. * @param string $key
  46. * @param mixed $value
  47. * @return $this
  48. */
  49. private function setData($key, $value)
  50. {
  51. $this->data[$key] = $value;
  52. return $this;
  53. }
  54. /**
  55. * Get items
  56. *
  57. * @return \Magento\Framework\Api\AbstractExtensibleObject[]
  58. */
  59. public function getItems()
  60. {
  61. return $this->getData(self::KEY_ITEMS) === null ? [] : $this->getData(self::KEY_ITEMS);
  62. }
  63. /**
  64. * Set items
  65. *
  66. * @param \Magento\Framework\Api\AbstractExtensibleObject[] $items
  67. * @return $this
  68. */
  69. public function setItems(array $items)
  70. {
  71. return $this->setData(self::KEY_ITEMS, $items);
  72. }
  73. /**
  74. * Get search criteria
  75. *
  76. * @return \Magento\Framework\Api\SearchCriteria
  77. */
  78. public function getSearchCriteria()
  79. {
  80. return $this->getData(self::KEY_SEARCH_CRITERIA);
  81. }
  82. /**
  83. * Set search criteria
  84. *
  85. * @param SearchCriteriaInterface $searchCriteria
  86. * @return $this
  87. */
  88. public function setSearchCriteria(SearchCriteriaInterface $searchCriteria)
  89. {
  90. return $this->setData(self::KEY_SEARCH_CRITERIA, $searchCriteria);
  91. }
  92. /**
  93. * Get total count
  94. *
  95. * @return int
  96. */
  97. public function getTotalCount()
  98. {
  99. return $this->getData(self::KEY_TOTAL_COUNT);
  100. }
  101. /**
  102. * Set total count
  103. *
  104. * @param int $count
  105. * @return $this
  106. */
  107. public function setTotalCount($count)
  108. {
  109. return $this->setData(self::KEY_TOTAL_COUNT, $count);
  110. }
  111. }