Collection.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\Status;
  7. /**
  8. * Flat sales order status history collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Collection extends \Magento\Sales\Model\ResourceModel\Collection\AbstractCollection
  13. {
  14. /**
  15. * Internal constructor
  16. *
  17. * @return void
  18. */
  19. protected function _construct()
  20. {
  21. $this->_init(\Magento\Sales\Model\Order\Status::class, \Magento\Sales\Model\ResourceModel\Order\Status::class);
  22. }
  23. /**
  24. * Get collection data as options array
  25. *
  26. * @return array
  27. */
  28. public function toOptionArray()
  29. {
  30. return $this->_toOptionArray('status', 'label');
  31. }
  32. /**
  33. * Get collection data as options hash
  34. *
  35. * @return array
  36. */
  37. public function toOptionHash()
  38. {
  39. return $this->_toOptionHash('status', 'label');
  40. }
  41. /**
  42. * Join order states table
  43. *
  44. * @return $this
  45. */
  46. public function joinStates()
  47. {
  48. if (!$this->getFlag('states_joined')) {
  49. $this->_idFieldName = 'status_state';
  50. $this->getSelect()->joinLeft(
  51. ['state_table' => $this->getTable('sales_order_status_state')],
  52. 'main_table.status=state_table.status',
  53. ['state', 'is_default', 'visible_on_front']
  54. );
  55. $this->setFlag('states_joined', true);
  56. }
  57. return $this;
  58. }
  59. /**
  60. * Add state code filter to collection
  61. *
  62. * @param string $state
  63. * @return $this
  64. */
  65. public function addStateFilter($state)
  66. {
  67. $this->joinStates();
  68. $this->getSelect()->where('state_table.state=?', $state);
  69. return $this;
  70. }
  71. /**
  72. * Define label order
  73. *
  74. * @param string $dir
  75. * @return $this
  76. */
  77. public function orderByLabel($dir = 'ASC')
  78. {
  79. $this->getSelect()->order('main_table.label ' . $dir);
  80. return $this;
  81. }
  82. }