AbstractCollection.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Order\Comment\Collection;
  7. /**
  8. * Flat sales order abstract comments collection, used as parent for: invoice, shipment, creditmemo
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. abstract class AbstractCollection extends \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection
  15. {
  16. /**
  17. * Set filter on comments by their parent item
  18. *
  19. * @param \Magento\Framework\Model\AbstractModel|int $parent
  20. * @return $this
  21. */
  22. public function setParentFilter($parent)
  23. {
  24. if ($parent instanceof \Magento\Framework\Model\AbstractModel) {
  25. $parent = $parent->getId();
  26. }
  27. return $this->addFieldToFilter('parent_id', $parent);
  28. }
  29. /**
  30. * Adds filter to get only 'visible on front' comments
  31. *
  32. * @param int $flag
  33. * @return $this
  34. */
  35. public function addVisibleOnFrontFilter($flag = 1)
  36. {
  37. return $this->addFieldToFilter('is_visible_on_front', $flag);
  38. }
  39. /**
  40. * Set created_at sort order
  41. *
  42. * @param string $direction
  43. * @return $this
  44. */
  45. public function setCreatedAtOrder($direction = 'desc')
  46. {
  47. return $this->setOrder('created_at', $direction);
  48. }
  49. }