Пример #1
0
 /**
  *
  * @return Oray_Dao_Recordset
  */
 public function getFilters()
 {
     if (null === self::$_daoRule) {
         return null;
     }
     if (null === $this->_filters) {
         $this->_filters = self::$_daoRule->getFiltersByRuleId($this->ruleId, array('isvalid' => 1));
     }
     return $this->_filters;
 }
Пример #2
0
 /**
  * 更新规则
  */
 public function updateAction()
 {
     $post = $this->_request->getPost();
     $ruleId = $this->_request->getPost('ruleid');
     /* @var $daoRule Dao_Td_Rule_Rule */
     $daoRule = $this->getDao('Dao_Td_Rule_Rule');
     $rule = $daoRule->getRuleById($ruleId);
     if (null === $rule) {
         return $this->json(false, $this->lang['rule_not_exists']);
     }
     $params = array('operation' => $post['operation'], 'isvalid' => $post['isvalid'] ? 1 : 0);
     if (!empty($post['value'])) {
         $params['value'] = $post['value'];
     }
     // 邮件提醒部分
     if (!empty($post['mailremind'])) {
         $remind = array('isvalid' => true);
         // 邮箱
         $vowels = array(',', ';', ',', '、');
         $mailbox = str_replace($vowels, ';', $post['mailbox']);
         $mailbox = explode(';', $mailbox);
         if (count($mailbox) <= 0) {
             return $this->json(false, $this->lang['mailbox_null_tips']);
         }
         foreach ($mailbox as $key => $item) {
             if (strlen($item) <= 0) {
                 unset($mailbox[$key]);
                 continue;
             }
             if (!Oray_Function::isEmail($item)) {
                 return $this->json(false, $this->lang['invalid_mailbox_address']);
             }
         }
         $remind['mailbox'] = $mailbox;
         // 应用板块
         $boards = array();
         foreach ($post['member'] as $key) {
             $boards[] = str_replace('_', '^', $post['boardid-' . $key]);
         }
         if (!empty($boards)) {
             $remind['boards'] = $boards;
         }
         $params['mailremind'] = json_encode($remind);
     } else {
         if (!empty($rule->mailRemind)) {
             $remind = $rule->mailRemind;
             $remind['isvalid'] = false;
             $params['mailremind'] = json_encode($remind);
         }
     }
     $filterIdx = $post['filters'];
     $filters = array();
     $subject = array();
     foreach ($filterIdx as $index) {
         $item = array('ruleid' => $ruleId);
         $item['action'] = isset($post['filterid-' . $index]) ? 'update' : 'create';
         $item['filterid'] = $item['action'] == 'update' ? $post['filterid-' . $index] : Dao_Td_Rule_Rule::getFilterId();
         $item['value'] = $post['value-' . $index];
         $item['type'] = $post['type-' . $index];
         $item['isvalid'] = isset($post['isvalid-' . $index]) ? $post['isvalid-' . $index] : false;
         $item['what'] = $post['what-' . $index];
         if ($item['action'] == 'create' && !$item['isvalid'] && empty($item['value'])) {
             continue;
         }
         // 生成规则描述内容
         $strValue = null;
         switch ($item['what']) {
             case 'from':
             case 'to':
             case 'cc':
                 $array = explode("\n", $item['value']);
                 $valueStr = array();
                 foreach ($array as $user) {
                     $arr = explode(' ', $user);
                     if (isset($arr[1])) {
                         $valueStr[] = $arr[1];
                     }
                 }
                 $strValue = implode(',', $valueStr);
                 break;
             case 'subject':
             default:
                 $strValue = str_replace("\t", '', $item['value']);
                 break;
         }
         if ($item['isvalid']) {
             $subject[] = implode("\t", array($item['what'], $item['type'], $strValue));
         }
         $filters[$index] = $item;
     }
     $params['description'] = implode("\n", $subject);
     $ret = $daoRule->updateRule($ruleId, $params);
     if (!$ret) {
         return $this->json(false, $this->lang['rule_update_failure']);
     }
     foreach ($filters as $filter) {
         if ($filter['action'] == 'create') {
             $daoRule->addFilter($filter);
         } else {
             $daoRule->updateFilter($filter['filterid'], $filter);
         }
     }
     //Memcache
     $rules = $this->cache->deleteCache(array($daoRule, 'getRulesByUniqueId'), array($rule->uniqueId, array('isvalid' => true)));
     return $this->json(true, $this->lang['rule_update_success'], array('ruleid' => $ruleId));
 }