/**
  * Filter & validate recipients
  */
 public function validate()
 {
     parent::validate();
     $recipients = explode("\n", str_replace("\r", '', $this->getData('recipients')));
     $recipients = array_unique(array_map('trim', $recipients));
     $recipients = array_filter($recipients, 'strlen');
     if (false === $recipients || count($recipients) < 1) {
         $this->addError('Recipients cannot be empty');
     }
     try {
         $startDate = new DateTime($this->getData('start_date'));
     } catch (Exception $e) {
         $this->addError('Invalid Start Date');
         return !$this->hasErrors();
     }
     // Get last errors & warnings
     $errors = DateTime::getLastErrors();
     if (!empty($errors['errors']) || !empty($errors['warnings'])) {
         $this->addError('Invalid Start Date');
     }
     // Set filtered & validated state
     $this->setData('recipients', $recipients);
     $this->setData('start_date', $startDate->format(Varien_Date::DATETIME_PHP_FORMAT));
     return !$this->hasErrors();
 }
 /**
  * Delete trigger using correct model
  *
  * @return self
  */
 public function delete()
 {
     $triggerId = $this->getId();
     $eventId = $this->getResource()->getEventIdByTriggerId($triggerId);
     $trigger = $this->getResource()->getTriggerModel($eventId);
     $trigger->setId($triggerId);
     if ($trigger instanceof Esendex_Sms_Model_Trigger) {
         parent::delete();
     } else {
         $trigger->delete();
     }
     return $this;
 }
 /**
  * @param Esendex_Sms_Model_TriggerAbstract $trigger
  * @return string
  */
 public function getEventName(Esendex_Sms_Model_TriggerAbstract $trigger)
 {
     $event = Mage::getModel('esendex_sms/event')->load($trigger->getEventId());
     return $event->getName();
 }
 /**
  * Get the recipients for this cron
  *
  * @param Esendex_Sms_Model_TriggerAbstract $trigger
  *
  * @return array
  */
 public function getRecipient(Esendex_Sms_Model_TriggerAbstract $trigger)
 {
     $recipients = $trigger->getData('recipients');
     if (!is_array($recipients)) {
         return array();
     }
     return $recipients;
 }