Collection.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Model\ResourceModel\Rating\Option;
  7. /**
  8. * Rating option collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  13. {
  14. /**
  15. * Rating votes table
  16. *
  17. * @var string
  18. */
  19. protected $_ratingVoteTable;
  20. /**
  21. * Define model
  22. *
  23. * @return void
  24. */
  25. protected function _construct()
  26. {
  27. $this->_init(
  28. \Magento\Review\Model\Rating\Option::class,
  29. \Magento\Review\Model\ResourceModel\Rating\Option::class
  30. );
  31. $this->_ratingVoteTable = $this->getTable('rating_option_vote');
  32. }
  33. /**
  34. * Add rating filter
  35. *
  36. * @param int|array $rating
  37. * @return $this
  38. */
  39. public function addRatingFilter($rating)
  40. {
  41. if (is_numeric($rating)) {
  42. $this->addFilter('rating_id', $rating);
  43. } elseif (is_array($rating)) {
  44. $this->addFilter('rating_id', $this->_getConditionSql('rating_id', ['in' => $rating]), 'string');
  45. }
  46. return $this;
  47. }
  48. /**
  49. * Set order by position field
  50. *
  51. * @param string $dir
  52. * @return $this
  53. */
  54. public function setPositionOrder($dir = 'ASC')
  55. {
  56. $this->setOrder('main_table.position', $dir);
  57. return $this;
  58. }
  59. }