示例#1
0
 private function _initTriggers($force = false)
 {
     if (null === ($triggers = $this->_cacheHelper->load(__CLASS__)) || $force) {
         $triggers = Application_Model_Mappers_EmailTriggersMapper::getInstance()->getTriggers();
         $this->_cacheHelper->save(__CLASS__, $triggers, '', array('plugins'));
     }
     $this->_triggers = $triggers;
 }
 protected function _runOnCreate()
 {
     Tools_Plugins_Tools::registerPluginsIncludePath(true);
     Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerTriggers($this->_object->getName());
     Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerRecipients($this->_object->getName());
 }
 public function actionmailsAction()
 {
     if ($this->getRequest()->isPost()) {
         $actions = $this->getRequest()->getParam('actions', false);
         if ($actions !== false) {
             $removeActions = array();
             foreach ($actions as $action) {
                 if (isset($action['delete']) && $action['delete'] === "true") {
                     array_push($removeActions, $action['id']);
                     continue;
                 }
                 //add trigger automatically if not exists
                 //if(($exists = Application_Model_Mappers_EmailTriggersMapper::getInstance()->findByTriggerName($action['trigger'])->current()) === null) {
                 //    Application_Model_Mappers_EmailTriggersMapper::getInstance()->registerTrigger($action['trigger']);
                 // }
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->save($action);
             }
             if (!empty($removeActions)) {
                 Application_Model_Mappers_EmailTriggersMapper::getInstance()->delete($removeActions);
             }
             $this->_helper->response->success($this->_helper->language->translate('Changes saved'));
             return true;
         }
     }
     $pluginsTriggers = Tools_Plugins_Tools::fetchPluginsTriggers();
     $systemTriggers = Tools_System_Tools::fetchSystemtriggers();
     $triggers = is_array($pluginsTriggers) ? array_merge($systemTriggers, $pluginsTriggers) : $systemTriggers;
     $recipients = Application_Model_Mappers_EmailTriggersMapper::getInstance()->getReceivers(true);
     $this->view->recipients = array_combine($recipients, $recipients);
     $this->view->mailTemplates = Tools_Mail_Tools::getMailTemplatesHash();
     $this->view->triggers = $triggers;
     $this->view->actionsOptions = array_merge(array('0' => $this->_helper->language->translate('Select event area')), array_combine(array_keys($triggers), array_map(function ($trigger) {
         return str_replace('-', ' ', ucfirst($trigger));
     }, array_keys($triggers))));
     $this->view->actions = Application_Model_Mappers_EmailTriggersMapper::getInstance()->fetchArray();
 }