vendor/terminal42/notification_center/library/NotificationCenter/Model/Gateway.php line 90

Open in your IDE?
  1. <?php
  2. /**
  3. * notification_center extension for Contao Open Source CMS
  4. *
  5. * @copyright Copyright (c) 2008-2015, terminal42
  6. * @author terminal42 gmbh <info@terminal42.ch>
  7. * @license LGPL
  8. */
  9. namespace NotificationCenter\Model;
  10. use Contao\Model;
  11. use NotificationCenter\Gateway\GatewayInterface;
  12. class Gateway extends Model
  13. {
  14. /**
  15. * Name of the current table
  16. * @var string
  17. */
  18. protected static $strTable = 'tl_nc_gateway';
  19. /**
  20. * Gateway instance
  21. * @var GatewayInterface
  22. */
  23. protected $objGateway;
  24. /**
  25. * Get gateway instance
  26. * @return GatewayInterface|null
  27. */
  28. public function getGateway()
  29. {
  30. // We only need to build the gateway once, Model is cached by registry and Gateway does not change between messages
  31. if (null === $this->objGateway) {
  32. $strClass = $GLOBALS['NOTIFICATION_CENTER']['GATEWAY'][$this->type] ?? null;
  33. if (null === $strClass) {
  34. \System::log(sprintf('Could not find gateway "%s".', $this->type), __METHOD__, TL_ERROR);
  35. return null;
  36. }
  37. if (!class_exists($strClass)) {
  38. \System::log(sprintf('Could not find gateway class "%s".', $strClass), __METHOD__, TL_ERROR);
  39. return null;
  40. }
  41. try {
  42. $objGateway = new $strClass($this);
  43. if (!$objGateway instanceof GatewayInterface) {
  44. \System::log(sprintf('The gateway class "%s" must be an instance of GatewayInterface.', $strClass), __METHOD__, TL_ERROR);
  45. return null;
  46. }
  47. $this->objGateway = $objGateway;
  48. } catch (\Exception $e) {
  49. \System::log(sprintf('There was a general error building the gateway: "%s".', $e->getMessage()), __METHOD__, TL_ERROR);
  50. return null;
  51. }
  52. }
  53. return $this->objGateway;
  54. }
  55. /**
  56. * Find queues by interval.
  57. *
  58. * @param string $interval
  59. * @param array $options
  60. *
  61. * @return Gateway[]|null
  62. */
  63. public static function findQueuesByInterval($interval, $options = array())
  64. {
  65. $t = static::$strTable;
  66. $columns = array("$t.type=?", "$t.queue_cronEnable=?", "$t.queue_cronInterval=?");
  67. $values = array('queue', 1, $interval);
  68. return static::findBy($columns, $values, $options);
  69. }
  70. }