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

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 NotificationCenter\Gateway\GatewayInterface;
  11. class Gateway extends \Model
  12. {
  13.     /**
  14.      * Name of the current table
  15.      * @var string
  16.      */
  17.     protected static $strTable 'tl_nc_gateway';
  18.     /**
  19.      * Gateway instance
  20.      * @var GatewayInterface
  21.      */
  22.     protected $objGateway;
  23.     /**
  24.      * Get gateway instance
  25.      * @return  GatewayInterface|null
  26.      */
  27.     public function getGateway()
  28.     {
  29.         // We only need to build the gateway once, Model is cached by registry and Gateway does not change between messages
  30.         if (null === $this->objGateway) {
  31.             $strClass $GLOBALS['NOTIFICATION_CENTER']['GATEWAY'][$this->type];
  32.             if (!class_exists($strClass)) {
  33.                 \System::log(sprintf('Could not find gateway class "%s".'$strClass), __METHOD__TL_ERROR);
  34.                 return null;
  35.             }
  36.             try {
  37.                 $objGateway = new $strClass($this);
  38.                 if (!$objGateway instanceof GatewayInterface) {
  39.                     \System::log(sprintf('The gateway class "%s" must be an instance of GatewayInterface.'$strClass), __METHOD__TL_ERROR);
  40.                     return null;
  41.                 }
  42.                 $this->objGateway $objGateway;
  43.             } catch (\Exception $e) {
  44.                 \System::log(sprintf('There was a general error building the gateway: "%s".'$e->getMessage()), __METHOD__TL_ERROR);
  45.                 return null;
  46.             }
  47.         }
  48.         return $this->objGateway;
  49.     }
  50.     /**
  51.      * Find queues by interval.
  52.      *
  53.      * @param   string $interval
  54.      * @param   array  $options
  55.      *
  56.      * @return Gateway[]|null
  57.      */
  58.     public static function findQueuesByInterval($interval$options = array())
  59.     {
  60.         $t = static::$strTable;
  61.         $columns = array("$t.type=?""$t.queue_cronEnable=?""$t.queue_cronInterval=?");
  62.         $values  = array('queue'1$interval);
  63.         return static::findBy($columns$values$options);
  64.     }
  65. }