/**
  * Display a list of all users in the system.
  *
  */
 public function indexAction()
 {
     $filterStatus = $this->_getParam('status', 'any');
     $filterTrigger = $this->_getParam('trigger', 'any');
     $filterSort = $this->_getParam('sort', 'queueDt');
     $filterDirection = $this->_getParam('direction', 'asc');
     $form = new Ot_Form_EmailqueueSearch();
     $form->populate($_GET);
     $eq = new Ot_Model_DbTable_EmailQueue();
     $select = new Zend_Db_Table_Select($eq);
     if ($filterStatus != '' && $filterStatus != 'any') {
         $select->where('status = ?', $filterStatus);
     }
     if ($filterTrigger != '' && $filterTrigger != 'any') {
         $select->where('attributeName = ?', 'triggerActionId');
         $select->where('attributeId = ?', $filterTrigger);
     }
     $select->order($filterSort . ' ' . $filterDirection);
     $adapter = new Zend_Paginator_Adapter_DbSelect($select);
     $paginator = new Zend_Paginator($adapter);
     $paginator->setCurrentPageNumber($this->_getParam('page', 1));
     $ta = new Ot_Model_DbTable_TriggerAction();
     $actions = $ta->fetchAll();
     $triggers = array();
     foreach ($actions as $a) {
         $triggers[$a->triggerActionId] = $a;
     }
     $this->_helper->pageTitle('ot-emailqueue-index:title');
     $this->view->assign(array('paginator' => $paginator, 'form' => $form, 'interface' => true, 'sort' => $filterSort, 'direction' => $filterDirection, 'triggers' => $triggers));
 }
 /**
  * Dispatches the trigger specified
  *
  * @param int $key
  */
 public function dispatch($key)
 {
     $vr = new Ot_Config_Register();
     $triggerSystem = $vr->getVar('triggerSystem');
     if (is_null($triggerSystem)) {
         $triggerSystem = false;
     } else {
         $triggerSystem = $triggerSystem->getValue();
     }
     // if the trigger system is globally disabled just return
     if ($triggerSystem == false) {
         return;
     }
     $action = new Ot_Model_DbTable_TriggerAction();
     $actions = $action->getActionsForTrigger($key);
     foreach ($actions as $a) {
         $helper = new $a->actionKey();
         $data = $helper->getDbTable()->find($a->triggerActionId);
         if (is_null($data)) {
             continue;
         }
         $data = $data->toArray();
         foreach ($data as &$d) {
             foreach ($this->_vars as $key => $value) {
                 if (is_array($value)) {
                     $value = implode(', ', $value);
                 }
                 $d = str_replace("[[{$key}]]", $value, $d);
             }
         }
         $helper->dispatch($data);
     }
 }
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->setAttrib('id', 'emailqueueSearchForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'well')), 'Form'))->setMethod(Zend_Form::METHOD_GET);
     $status = $this->createElement('select', 'status', array('label' => 'Sending Status:'));
     $status->addMultiOptions(array('any' => 'Any Status', 'waiting' => 'Waiting', 'sent' => 'Sent', 'error' => 'Error'));
     $trigger = $this->createElement('select', 'trigger', array('label' => 'From Trigger:'));
     $trigger->addMultiOption('any', 'Any Trigger');
     $ta = new Ot_Model_DbTable_TriggerAction();
     $actions = $ta->fetchAll(null, array('eventKey', 'name'));
     foreach ($actions as $a) {
         $trigger->addMultiOption($a->triggerActionId, $a->name);
     }
     $this->addElements(array($status, $trigger));
     $this->setElementDecorators(array('ViewHelper', array(array('wrapperField' => 'HtmlTag'), array('tag' => 'div', 'class' => 'elm')), array('Errors', array('placement' => 'append')), array('Label', array('placement' => 'prepend')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'criteria'))));
     $sort = $this->createElement('hidden', 'sort');
     $sort->setDecorators(array('ViewHelper'));
     $direction = $this->createElement('hidden', 'direction');
     $direction->setDecorators(array('ViewHelper'));
     $submit = $this->createElement('submit', 'submitButton', array('label' => 'Filter Results'));
     $submit->setAttrib('class', 'btn btn-danger');
     $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'submit')), array('HtmlTag', array('tag' => 'div', 'class' => 'clearfix'))));
     $this->addElements(array($submit, $sort, $direction));
     return $this;
 }
 /**
  * Allows users to enable/disable trigger action
  *
  */
 public function changeStatusAction()
 {
     $triggerActionId = $this->_getParam('triggerActionId', null);
     if (is_null($triggerActionId)) {
         throw new Ot_Exception_Input('msg-error-triggerActionIdNotFound');
     }
     $action = new Ot_Model_DbTable_TriggerAction();
     $thisTriggerAction = $action->find($triggerActionId);
     if (is_null($thisTriggerAction)) {
         throw new Ot_Exception_Data('msg-error-noTriggerActionId');
     }
     if ($this->_request->isPost()) {
         $data = array('triggerActionId' => $triggerActionId, 'enabled' => !$thisTriggerAction->enabled);
         $action->update($data, null);
         $logOptions = array('attributeName' => 'triggerActionId', 'attributeId' => $triggerActionId);
         $this->_helper->log(Zend_Log::INFO, 'Trigger Action deleted', $logOptions);
         $this->_helper->messenger->addWarning('msg-info-triggerActionStatus');
         $this->_helper->redirector->gotoRoute(array('controller' => 'trigger', 'action' => 'details', 'eventKey' => $thisTriggerAction->eventKey), 'ot', true);
     } else {
         throw new Ot_Exception_Access('You are not allowed to access this method directly');
     }
 }