/** * doAddTask * 添加任务 * @param mixed $map 任务内容 * @param mixed $feed 是否发送动态 * @access public * @return void */ public function doAddTask($map, $import) { $map['cTime'] = isset($map['cTime']) ? $map['cTime'] : time(); $map['mTime'] = $map['cTime']; $map['type'] = isset($map['type']) ? $map['type'] : $this->_type; $map['tags'] = $map['tags']; $map['private'] = $map['private']; $map['private_data'] = md5($map['password']); $map['category_title'] = M('task_category')->where("`id`={$map['category']}")->getField('name'); $content = $map['content']; // 用于发通知截取 //$map['content'] = t(h($map['content'])); $map['content'] = $map['content']; unset($map['password']); $friendsId = isset($map['mention']) ? explode(',', $map['mention']) : null; //解析提到的好友 unset($map['mention']); $map['share_type'] = isset($map['share_type']) ? $map['share_type'] : $this->_share_type; $map['share_source'] = isset($map['share_source']) ? $map['share_source'] : $this->_share_source; $map['share_target'] = isset($map['share_target']) ? $map['share_target'] : $this->_share_target; $map['parent_id'] = isset($map['parent_id']) ? $map['parent_id'] : $this->_parent_id; $map['level'] = isset($map['level']) ? $map['level'] : $this->_level; $map['task_type'] = isset($map['task_type']) ? $map['task_type'] : $this->_task_type; $map['task_status'] = isset($map['task_status']) ? $map['task_status'] : $this->_task_status; $map['task_priority'] = isset($map['task_priority']) ? $map['task_priority'] : $this->_task_priority; $map['start_date'] = isset($map['start_date']) ? $map['start_date'] : $this->_start_date; $map['due_date'] = isset($map['due_date']) ? $map['due_date'] : $this->_due_date; $map['estimated_time'] = isset($map['estimated_time']) ? $map['estimated_time'] : $this->_estimated_time; $map['spent_time'] = isset($map['spent_time']) ? $map['spent_time'] : $this->_spent_time; $map['done_ratio'] = isset($map['done_ratio']) ? $map['done_ratio'] : $this->_done_ratio; $map['detail_summary'] = isset($map['detail_summary']) ? $map['detail_summary'] : $this->_detail_summary; $map['rel_digest'] = isset($map['rel_digest']) ? $map['rel_digest'] : $this->_rel_digest; $map['rel_tasks'] = isset($map['rel_tasks']) ? $map['rel_tasks'] : $this->_rel_tasks; $map = $this->merge($map); $addId = $this->add($map); $temp = array_filter($friendsId); //$appid = A('Index')->getAppId(); //添加任务提到的好友 if (!empty($friendsId) && !empty($temp)) { $mention = self::factoryModel('mention'); $result = $mention->addMention($addId, $temp); for ($i = 0; $i < count($temp); $i++) { setScore($map['uid'], 'mention'); } //发送通知给提到的好友 $body['content'] = getTaskShort(t($content), 40); $url = sprintf("%s/Index/show/id/%s/mid/%s", '{' . $appid . '}', $addId, $map['uid']); $title_data['title'] = sprintf("<a href='%s'>%s</a>", $url, $map['title']); $this->doNotify($temp, "task_mention", $title_data, $body, $url); } if (!$addId) { return false; } //获得配置信息 $config = $this->config->delete; if ($config) { //修改空间中的计数 $count = $this->where('uid =' . $map['uid'])->count(); } else { //修改空间中的计数 $count = $this->where('uid =' . $map['uid'] . ' AND status <> 2')->count(); } //$this->api->space_changeCount( 'task',$count ); //发送动态 if ($import) { //$title['title'] = sprintf("<a href=\"%s/Index/show/id/%s/mid/%s\">%s</a>",__APP__,$addId,$map['uid'],$map['title']); $title['title'] = sprintf("<a href=\"%s/Index/show/id/%s/mid/%s\">%s</a>", '{SITE_URL}', $addId, $map['uid'], $map['title']); $title['title'] = stripslashes($title['title']); //setScore($map['uid'],'add_task'); $body['content'] = getTaskShort($this->replaceSpecialChar(t($map['content'])), 80); $body['title'] = stripslashes($body['title']); $this->doFeed("task", $title, $body); } else { //setScore($map['uid'],'add_task'); $result['appid'] = $addId; $result['title'] = sprintf("<a href=\"%s/Index/show/id/%s/mid/%s\">%s</a>", '{SITE_URL}', $addId, $map['uid'], $map['title']); return $result; } return $addId; }
/** * replace * 对数据集进行追加处理 * @param array $data 数据集 * @param array $mention 需要被追加的值 * @access protected * @return void */ protected function replace($data, $mentiondata = null) { $result = $data; $categoryname = $this->getCategory(null); //获取所有的分类 //如果$mention为空就需要从数据库中取出数据 if (empty($mentiondata)) { $mention = self::factoryModel('mention'); $mentioncontent = $mention->getUserMention(); } //TODO 配置信息,截取字数控制 foreach ($result as &$value) { if (3 == $value['private']) { // if(Cookie::get($value['id'].'password') == $value['private_data']) { // $value['private'] = 0; // } Change } $value['content'] = str_replace("&nbsp;", "", h($value['content'])); // $value['category'] = array( // "name" => $categoryname[$value['category']]['name'], // "id" => $value['category']); //替换任务类型 //追加任务中提到的内容 $value['mention'] = !isset($mentiondata) ? $mentioncontent[$value['id']] : $mentiondata[$value['id']]; //任务截断 $short = $this->config->titleshort == 0 ? 4000 : $this->config->titleshort; $suffix = StrLenW($value['content']) > $short ? $this->config->suffix : ''; $value['content'] = getTaskShort($value['content'], $short) . $suffix; //任务标题 $value['title'] = stripslashes($value['title']); } return $result; }