/**
  * the singleton pattern
  *
  * @return Calendar_Controller_EventNotifications
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Calendar_Controller_EventNotifications();
     }
     return self::$_instance;
 }
 /**
  * (non-PHPdoc)
  * @see tests/tine20/Calendar/Calendar_TestCase::setUp()
  */
 public function setUp()
 {
     parent::setUp();
     $smtpConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::SMTP);
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $this->_eventController = Calendar_Controller_Event::getInstance();
     $this->_notificationController = Calendar_Controller_EventNotifications::getInstance();
     $this->_setupPreferences();
 }
 /**
  * (non-PHPdoc)
  * @see tests/tine20/Calendar/Calendar_TestCase::setUp()
  */
 public function setUp()
 {
     parent::setUp();
     Calendar_Controller_Event::getInstance()->sendNotifications(true);
     $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP, new Tinebase_Config_Struct())->toArray();
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $this->_eventController = Calendar_Controller_Event::getInstance();
     $this->_notificationController = Calendar_Controller_EventNotifications::getInstance();
     $this->_setupPreferences();
     Calendar_Config::getInstance()->set(Calendar_Config::MAX_NOTIFICATION_PERIOD_FROM, 52 * 10);
 }
 /**
  * send notifications 
  * 
  * @param Calendar_Model_Event       $_event
  * @param Tinebase_Model_FullAccount $_updater
  * @param Sting                      $_action
  * @param Calendar_Model_Event       $_oldEvent
  * @return void
  */
 public function sendEventNotifications($_event, $_updater, $_action, $_oldEvent = NULL)
 {
     Calendar_Controller_EventNotifications::getInstance()->doSendNotifications($_event, $_updater, $_action, $_oldEvent);
 }
 /**
  * send an alarm
  *
  * @param  Tinebase_Model_Alarm $_alarm
  * @return void
  * 
  * NOTE: the given alarm is raw and has not passed _inspectAlarmGet
  *  
  * @todo throw exception on error
  */
 public function sendAlarm(Tinebase_Model_Alarm $_alarm)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " About to send alarm " . print_r($_alarm->toArray(), TRUE));
     }
     $doContainerACLChecks = $this->doContainerACLChecks(FALSE);
     try {
         $event = $this->get($_alarm->record_id);
         $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array($_alarm));
         $this->_inspectAlarmGet($event);
     } catch (Exception $e) {
         $this->doContainerACLChecks($doContainerACLChecks);
         throw $e;
     }
     $this->doContainerACLChecks($doContainerACLChecks);
     if ($event->rrule) {
         $recurid = $_alarm->getOption('recurid');
         // adopts the (referenced) alarm and sets alarm time to next occurance
         parent::_inspectAlarmSet($event, $_alarm);
         $this->adoptAlarmTime($event, $_alarm, 'instance');
         // sent_status might have changed in adoptAlarmTime()
         if ($_alarm->sent_status !== Tinebase_Model_Alarm::STATUS_PENDING) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Not sending alarm for event at ' . $event->dtstart->toString() . ' with status ' . $_alarm->sent_status);
             }
             return;
         }
         if ($recurid) {
             // NOTE: In case of recuring events $event is always the baseEvent,
             //       so we might need to adopt event time to recur instance.
             $diff = $event->dtstart->diff($event->dtend);
             $event->dtstart = new Tinebase_DateTime(substr($recurid, -19));
             $event->dtend = clone $event->dtstart;
             $event->dtend->add($diff);
         }
         if ($event->exdate && in_array($event->dtstart, $event->exdate)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Not sending alarm because instance at " . $event->dtstart->toString() . ' is an exception.');
             }
             return;
         }
     }
     Calendar_Controller_EventNotifications::getInstance()->doSendNotifications($event, Tinebase_Core::getUser(), 'alarm', NULL, $_alarm);
 }