Options.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Model\BulkDescription;
  7. use Magento\Framework\Bulk\BulkSummaryInterface;
  8. /**
  9. * Class for grid options
  10. */
  11. class Options implements \Magento\Framework\Data\OptionSourceInterface
  12. {
  13. /**
  14. * @var \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory
  15. */
  16. private $bulkCollectionFactory;
  17. /**
  18. * @var \Magento\Authorization\Model\UserContextInterface
  19. */
  20. private $userContext;
  21. /**
  22. * Options constructor.
  23. * @param \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory $bulkCollection
  24. * @param \Magento\Authorization\Model\UserContextInterface $userContext
  25. */
  26. public function __construct(
  27. \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\CollectionFactory $bulkCollection,
  28. \Magento\Authorization\Model\UserContextInterface $userContext
  29. ) {
  30. $this->bulkCollectionFactory = $bulkCollection;
  31. $this->userContext = $userContext;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function toOptionArray()
  37. {
  38. /** @var \Magento\AsynchronousOperations\Model\ResourceModel\Bulk\Collection $collection */
  39. $collection = $this->bulkCollectionFactory->create();
  40. /** @var \Magento\Framework\DB\Select $select */
  41. $select = $collection->getSelect();
  42. $select->reset();
  43. $select->distinct(true);
  44. $select->from($collection->getMainTable(), ['description']);
  45. $select->where('user_id = ?', $this->userContext->getUserId());
  46. $options = [];
  47. /** @var BulkSummaryInterface $item */
  48. foreach ($collection->getItems() as $item) {
  49. $options[] = [
  50. 'value' => $item->getDescription(),
  51. 'label' => $item->getDescription()
  52. ];
  53. }
  54. return $options;
  55. }
  56. }