/** * 创建规则 */ public function createAction() { $post = $this->_request->getPost(); /* @var $daoRule Dao_Td_Rule_Rule */ $daoRule = $this->getDao('Dao_Td_Rule_Rule'); $ruleId = Dao_Td_Rule_Rule::getRuleId(); $params = array('ruleid' => $ruleId, 'uniqueid' => $this->_user->uniqueId, '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); } $filterIdx = $post['filters']; $filters = array(); foreach ($filterIdx as $index) { $item = array('ruleid' => $ruleId); $item['filterid'] = 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['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); $ruleId = $daoRule->createRule($params); if (!$ruleId) { return $this->json(true, $this->lang['rule_create_failure']); } foreach ($filters as $filter) { $daoRule->addFilter($filter); } //Memcache $rule = $daoRule->getRuleById($ruleId); $uniqueId = $rule->uniqueId; $rules = $this->cache->deleteCache(array($daoRule, 'getRulesByUniqueId'), array($uniqueId, array('isvalid' => true))); return $this->json(true, $this->lang['rule_create_success'], array('ruleid' => $ruleId)); }