Collection.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\ResourceModel\Theme\File;
  7. /**
  8. * Theme files collection
  9. */
  10. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection implements
  11. \Magento\Framework\View\Design\Theme\File\CollectionInterface
  12. {
  13. /**
  14. * Collection initialization
  15. *
  16. * @return void
  17. */
  18. protected function _construct()
  19. {
  20. $this->_init(\Magento\Theme\Model\Theme\File::class, \Magento\Theme\Model\ResourceModel\Theme\File::class);
  21. }
  22. /**
  23. * Add select order
  24. *
  25. * The $field parameter is properly quoted, lately it was treated field "order" as special SQL
  26. * word and was not working
  27. *
  28. * @param string $field
  29. * @param string $direction
  30. * @return $this
  31. */
  32. public function setOrder($field, $direction = self::SORT_ORDER_DESC)
  33. {
  34. return parent::setOrder($this->getConnection()->quoteIdentifier($field), $direction);
  35. }
  36. /**
  37. * Set default order
  38. *
  39. * @param string $direction
  40. * @return $this
  41. */
  42. public function setDefaultOrder($direction = self::SORT_ORDER_ASC)
  43. {
  44. return $this->setOrder('sort_order', $direction);
  45. }
  46. /**
  47. * Filter out files that do not belong to a theme
  48. *
  49. * @param \Magento\Framework\View\Design\ThemeInterface $theme
  50. * @return $this
  51. */
  52. public function addThemeFilter(\Magento\Framework\View\Design\ThemeInterface $theme)
  53. {
  54. $this->addFieldToFilter('theme_id', $theme->getId());
  55. return $this;
  56. }
  57. }