Program.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Config\Source\Automation;
  3. class Program implements \Magento\Framework\Data\OptionSourceInterface
  4. {
  5. /**
  6. * @var \Dotdigitalgroup\Email\Helper\Data
  7. */
  8. private $helper;
  9. /**
  10. * @var \Magento\Framework\App\RequestInterface
  11. */
  12. private $request;
  13. /**
  14. * @var \Magento\Store\Model\StoreManagerInterface
  15. */
  16. private $storeManager;
  17. /**
  18. * @var \Magento\Framework\Registry
  19. */
  20. private $registry;
  21. /**
  22. * Program constructor.
  23. *
  24. * @param \Magento\Framework\App\RequestInterface $requestInterface
  25. * @param \Magento\Framework\Registry $registry
  26. * @param \Dotdigitalgroup\Email\Helper\Data $data
  27. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  28. */
  29. public function __construct(
  30. \Magento\Framework\App\RequestInterface $requestInterface,
  31. \Magento\Framework\Registry $registry,
  32. \Dotdigitalgroup\Email\Helper\Data $data,
  33. \Magento\Store\Model\StoreManagerInterface $storeManager
  34. ) {
  35. $this->helper = $data;
  36. $this->registry = $registry;
  37. $this->request = $requestInterface;
  38. $this->storeManager = $storeManager;
  39. }
  40. /**
  41. * Get options.
  42. *
  43. * @return array
  44. */
  45. public function toOptionArray()
  46. {
  47. $fields = [];
  48. $fields[] = ['value' => '0', 'label' => __('-- Disabled --')];
  49. $websiteName = $this->request->getParam('website', false);
  50. $website = ($websiteName)
  51. ? $this->storeManager->getWebsite($websiteName) : 0;
  52. //api client is enabled
  53. $apiEnabled = $this->helper->isEnabled($website);
  54. if ($apiEnabled) {
  55. $client = $this->helper->getWebsiteApiClient($website);
  56. $programs = $client->getPrograms();
  57. foreach ($programs as $one) {
  58. if (isset($one->id)) {
  59. if ($one->status == 'Active') {
  60. $fields[] = [
  61. 'value' => $one->id,
  62. 'label' => $one->name,
  63. ];
  64. }
  65. }
  66. }
  67. }
  68. return $fields;
  69. }
  70. }