예제 #1
0
 /**
  * 默认(图度列表)
  */
 public function indexAction()
 {
     $page = max(1, (int) $this->_request->getQuery('page'));
     $search = $this->_request->getQuery('search');
     $chart = $this->_request->getQuery('chart');
     $query = $this->_request->getQuery();
     $pageSize = $this->_user->option['pagesize'];
     $params = array();
     $coreseek = false;
     $config = $this->bootstrap->getOption('tudu');
     $labels = $this->getLabels();
     //gantt
     if ($chart == 'gantt') {
         $type = $this->_request->getQuery('type');
         $startDate = $this->_request->getQuery('sd');
         if (!$startDate) {
             $startDate = $this->_timestamp;
         }
         // 本周
         if ($type == 'week') {
             $startDate = $startDate - (int) date('w', $startDate) * 86400;
             $startDate = strtotime(date('Y-m-d', $startDate));
             $endDate = $startDate + 6 * 86400;
             $weekNum = (int) date('W', $startDate) - (int) date('W', strtotime(date('Y-m-1', $startDate))) + 1;
             $this->view->weeknum = $weekNum;
             // 本月
         } else {
             $startDate = strtotime(date('Y-m-1', $startDate));
             $endDate = strtotime(date('Y-m-t', $startDate));
         }
         $headers = array();
         for ($md = $startDate; $md <= $endDate; $md += 86400) {
             $headers[] = $md;
         }
     }
     $isSearch = in_array($search, array('query', 'adv'));
     $reLoad = false;
     $isUnread = false;
     // 检查系统标签是否存在
     $daoLabel = $this->getDao('Dao_Td_Tudu_Label');
     foreach ($config['label'] as $alias => $id) {
         if (!isset($labels[$alias])) {
             $daoLabel->createLabel(array('uniqueid' => $this->_user->uniqueId, 'labelalias' => $alias, 'labelid' => $id, 'isshow' => isset($this->_labelDefaultSetting[$alias]['isshow']) ? $this->_labelDefaultSetting[$alias]['isshow'] : 1, 'issystem' => true, 'ordernum' => $this->_labelDefaultSetting[$alias]['ordernum']));
             $daoLabel->calculateLabel($this->_user->uniqueId, $id);
             $reLoad = true;
         }
     }
     if ($reLoad) {
         $this->_labels = null;
         $labels = $this->getLabels();
     }
     $params['search'] = $search;
     if ('cat' == $search || $isSearch) {
         $cat = $this->_request->getQuery('cat');
         $params['cat'] = $cat;
     } else {
         if (array_key_exists($search, $config['label'])) {
             $cat = $search;
         }
     }
     if ($isSearch) {
         $coreseek = $this->_request->getQuery('coreseek');
     }
     if (isset($cat) && isset($labels[$cat])) {
         $label = $labels[$cat];
     }
     if (!isset($label)) {
         return;
     }
     $isInbox = $label['labelalias'] == 'inbox';
     $isTodo = $label['labelalias'] == 'todo';
     $isReview = $label['labelalias'] == 'review';
     if ($label['issystem']) {
         $label['displayname'] = $this->lang['label_' . $label['labelalias']];
     } else {
         $label['displayname'] = $label['labelalias'];
     }
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = $this->getDao('Dao_Td_Tudu_Tudu');
     $condition = array();
     $condition['label'] = $label['labelid'];
     $condition['uniqueid'] = $this->_user->uniqueId;
     if ($chart == 'gantt') {
         $condition['startdate'] = $startDate;
         $condition['enddate'] = $endDate;
     }
     // 是否需要重新统计图度数量
     $isReCount = false;
     if (isset($query['unread']) && $query['unread'] != '') {
         $condition['isread'] = !(bool) $query['unread'];
         $isUnread = !$condition['isread'];
         $params['unread'] = $query['unread'];
     }
     if (!empty($query['undone'])) {
         $condition['type'] = 'task';
         $condition['status'] = 2;
         $condition['isdone'] = 0;
         $isReCount = true;
         $params['undone'] = $query['undone'];
         $this->view->undone = true;
     }
     if (!empty($query['cid'])) {
         $condition['classid'] = $query['cid'];
         $isReCount = true;
     }
     // 普通搜索、高级搜索
     if ($isSearch && !$coreseek) {
         if (!empty($query['from'])) {
             $condition['from'] = $query['from'];
             $params['from'] = $condition['from'];
         }
         if (!empty($query['to'])) {
             $condition['to'] = $query['to'];
             $params['to'] = $condition['to'];
         }
         if (!empty($query['keyword'])) {
             $condition['keyword'] = $query['keyword'];
             $params['keyword'] = $query['keyword'];
         }
         if (!empty($query['bid'])) {
             $condition['boardid'] = $query['bid'];
             $params['bid'] = $query['bid'];
         }
         if (!empty($query['classid'])) {
             $condition['classid'] = $query['classid'];
             $params['classid'] = $query['classid'];
         }
         if (isset($query['status']) && $query['status'] != '') {
             $condition['status'] = (int) $query['status'];
             $params['status'] = $condition['status'];
         }
         if (!empty($query['createtime']) && (!is_array($query['createtime']) || !empty($query['createtime']['start']) || !empty($query['createtime']['end']))) {
             if (strpos($query['createtime']['start'], '-') !== false) {
                 $query['createtime']['start'] = strtotime($query['createtime']['start']);
             }
             $condition['createtime'] = $query['createtime'];
             $params['createtime'] = $condition['createtime'];
         }
         if (!empty($query['endtime']) && (!is_array($query['endtime']) || !empty($query['endtime']['start']) || !empty($query['endtime']['end']))) {
             if (strpos($query['endtime']['start'], '-') !== false) {
                 $query['endtime']['start'] = strtotime($query['endtime']['start']);
             }
             $condition['endtime'] = $query['endtime'];
             $params['endtime'] = $condition['endtime'];
         }
         $isReCount = true;
         // 全文搜索
     } elseif ($isSearch && $coreseek) {
         $sortType = (int) $this->_request->getQuery('sorttype');
         $sortAsc = (int) $this->_request->getQuery('sortasc');
         $sortMode = $sortAsc ? Oray_Search_Sphinx_Option::SORT_ATTR_ASC : Oray_Search_Sphinx_Option::SORT_ATTR_DESC;
         $sortBy = $this->_sortTypes[$sortType];
         $config = $this->options['sphinx'];
         switch ($sortBy) {
             case 'lastposttime':
                 $sortBy = 'last_post_time';
                 break;
             case 'endtime':
                 $sortBy = 'end_time';
                 break;
             case 'starttime':
                 $sortBy = 'start_time';
                 break;
         }
         $sphinx = new Oray_Search_Sphinx_Client($config);
         $option = new Oray_Search_Sphinx_Option(array('sort' => $sortMode, 'sortby' => $sortBy, 'groupsort' => '', 'mode' => Oray_Search_Sphinx_Option::MATCH_EXTENDED2, 'offset' => ($page - 1) * $pageSize, 'limit' => $pageSize));
         $params['sorttype'] = $sortType;
         $params['sortasc'] = $sortAsc;
         $params['keyword'] = $query['keyword'];
         $params['coreseek'] = 1;
         $arr = preg_split('/[\\s\\+\\/]+/', $query['keyword']);
         foreach ($arr as $i => $word) {
             if (!$word) {
                 unset($arr[$i]);
                 continue;
             }
             $arr[$i] = $sphinx->escapeString($word);
         }
         $keyword = $words = implode('|', $arr);
         $keyword = "@(subject,body,users) {$keyword}";
         $keyword = "@org_id {$this->_user->orgId} @uniqueid {$this->_user->uniqueId} {$keyword}";
         $result = $sphinx->query($keyword, $option, $config['indexes']['tudu'] . ' ' . $config['indexes']['tuduinc']);
         $matches = $result->getMatches();
         $total = $result->getTotal();
         //$words   = $result->getWords();
         $tudus = array();
         if (count($matches)) {
             $tuduIndexNum = array();
             foreach ($matches as $match) {
                 $tuduIndexNum[] = $match['id'];
             }
             $condition['tuduindexnum'] = $tuduIndexNum;
             $tudus = $daoTudu->getTuduPage($condition, '', null, null)->toArray();
         }
         $this->view->columns = array('sender', 'subject', 'accepter_endtime', 'reply', 'lastpost', 'star', 'note');
         $this->view->labels = $labels;
         $this->view->tudus = $tudus;
         $this->view->label = $label;
         $this->view->sort = array($sortType, $sortAsc ^ 1);
         $this->view->query = http_build_query($params);
         $params['words'] = $words;
         $this->view->params = $params;
         $this->view->boards = $this->getBoards();
         $this->view->coreseek = $coreseek;
         $this->view->pageinfo = array('query' => $params, 'currpage' => $page, 'pagecount' => ($total - 1) / $pageSize + 1, 'recordcount' => $total, 'url' => '/tudu/');
         $this->view->registFunction('format_label', array($this, 'formatLabels'));
         return $this->render('search');
     }
     // 过滤 x 天前的图度
     $filterExpired = isset($this->_user->option['expiredfilter']) && $this->_user->option['expiredfilter'] > 0 && in_array($label['labelalias'], array('inbox'));
     if ($filterExpired) {
         $expireDate = strtotime('today') - 86400 * $this->_user->option['expiredfilter'];
         // 公告,忽略
         /*if (in_array($label['labelalias'], array('ignore', 'notice'))) {
               $condition['createtime'] = $expireDate;
           } else {
               $condition['expiredate'] = $expireDate;
           }*/
         if ($isInbox && !$isSearch) {
             $condition['starttime']['start'] = $expireDate;
             //$condition['expiredate'] = $expireDate;
         }
         $isReCount = true;
     }
     if (($params['search'] == 'sent' || $params['search'] == 'cat') && !empty($query['unfinish'])) {
         $condition['status'] = array(0, 1);
         $condition['type'] = 'task';
         $params['unfinish'] = $condition['status'];
         $params['type'] = $condition['type'];
         $isReCount = false;
         $this->view->unfinish = true;
     }
     /*
     if (!isset($_SESSION['sort']) || !is_array($_SESSION['sort'])) {
         $_SESSION['sort'] = array(0, 0);
     }
     
     $sortType = $this->_request->getQuery('sorttype', $_SESSION['sort'][0]);
     $sortAsc  = $this->_request->getQuery('sortasc', $_SESSION['sort'][1]);
     $isSort   = isset($_GET['sorttype']) || isset($_GET['sortasc']);
     
     if ($sortType != $_SESSION['sort'][0] && isset($this->_sortTypes[$sortType])) {
         $_SESSION['sort'][0] = $sortType;
     }
     if ($sortAsc != $_SESSION['sort'][1]) {
         $_SESSION['sort'][1] = $sortAsc;
     }
     
     $sort = $this->_sortTypes[$_SESSION['sort'][0]] . ' ' . ($_SESSION['sort'][1] ? 'ASC' : 'DESC');
     */
     $sortType = (int) $this->_request->getQuery('sorttype');
     $sortAsc = (int) $this->_request->getQuery('sortasc');
     $isSort = isset($_GET['sorttype']) || isset($_GET['sortasc']);
     if ($sortType > 0 && isset($this->_sortTypes[$sortType])) {
         $params['sorttype'] = $sortType;
     }
     if ($sortAsc > 0 && isset($this->_sortTypes[$sortType])) {
         $params['sortasc'] = $sortAsc;
     }
     $sort = array();
     if (!$isInbox && !$isSearch && !$isTodo && !$isReview) {
         $sort[] = 'istop DESC';
     }
     $sort[] = $this->_sortTypes[$sortType] . ' ' . ($sortAsc ? 'ASC' : 'DESC');
     if ($isReCount) {
         $recordCount = $daoTudu->countTudu($condition);
         if ($filterExpired) {
             $label['totalnum'] = $recordCount;
             $label['unreadnum'] = $daoTudu->countTudu(array_merge(array('isread' => 0), $condition));
         }
     } else {
         $recordCount = $isUnread ? $label['unreadnum'] : $label['totalnum'];
     }
     // 我发起  未完成图度数
     if ($label['labelalias'] == 'sent' || !$label['issystem']) {
         $unFinishCount = $daoTudu->getTuduCount(array('orgid' => $this->_user->orgId, 'labelid' => $label['labelid'], 'uniqueid' => $this->_user->uniqueId, 'type' => 'task', 'status' => array(0, 1)));
         $label['unfinish'] = $unFinishCount;
         if (!empty($query['unfinish'])) {
             $recordCount = $unFinishCount;
         }
     }
     if ($isInbox || $isTodo || $isReview) {
         $page = $pageSize = $pageCount = null;
     } else {
         $pageCount = ($recordCount - 1) / $pageSize + 1;
     }
     if (null !== $pageCount && $page > $pageCount) {
         $page = $pageCount;
     }
     $tudus = $daoTudu->getTuduPage($condition, $sort, $page, $pageSize)->toArray();
     if ($chart == 'gantt') {
         foreach ($tudus as $key => $tudu) {
             if ($tudu['isexpired'] && time() < $startDate) {
                 unset($tudus[$key]);
             }
         }
     }
     if ($label['labelalias'] == 'ignore') {
         $label['unreadnum'] = 0;
     }
     // 列表项
     $columns = array();
     switch ($label['labelalias']) {
         case 'notice':
         case 'discuss':
             $columns = array('sender', 'subject', 'replynum_viewnum', 'lastpost', 'star', 'note');
             break;
         case 'meeting':
             $columns = array('sender', 'subject', 'starttime', 'replynum_viewnum', 'lastpost', 'star', 'note');
             break;
         case 'drafts':
             $columns = array('subject', 'accepter_endtime');
             break;
         case 'sent':
             $columns = array('subject', 'accepter_endtime', 'reply', 'lastpost', 'star', 'note');
             break;
         case 'todo':
             $columns = array('sender', 'subject', 'endtime', 'reply', 'lastpost', 'star', 'note');
             break;
         default:
             $columns = array('sender', 'subject', 'accepter_endtime', 'reply', 'lastpost', 'star', 'note');
             break;
     }
     $unUpdateOther = false;
     $unUpdateDiscuss = false;
     $unUpdateTodo = array();
     // 图度箱分组显示处理
     if (($isInbox || $isTodo || $isReview) && $tudus && !$isSearch) {
         if (!$isSort) {
             $today = strtotime('today');
             if ($isInbox) {
                 $group = array('meeting' => array(), 'notice' => array(), 'await' => array(), 'doing' => array(), 'discuss' => array(), 'waitconfirm' => array(), 'other' => array());
             } elseif ($isTodo) {
                 $group = array('unaccept' => array(), 'noendtime' => array(), 'today' => array(), '7day' => array(), 'later' => array());
             } else {
                 $group = array('await_review' => array(), 'done_review' => array());
             }
             $threeMonthAgoDate = mktime(0, 0, 0, date("m") - 3, date("d"), date("Y"));
             foreach ($tudus as $tudu) {
                 if ($isInbox) {
                     // 公告
                     if ($tudu['type'] == 'notice' && !in_array('^e', $tudu['labels']) && $tudu['steptype'] != 1) {
                         $group['notice'][] = $tudu;
                         continue;
                     }
                     // 会议
                     if ($tudu['type'] == 'meeting') {
                         $group['meeting'][] = $tudu;
                         continue;
                     }
                     // 讨论
                     if ($tudu['type'] == 'discuss') {
                         if ($tudu['lastposttime'] <= $threeMonthAgoDate && !$isUnread) {
                             $tudu['far'] = true;
                             $unUpdateDiscuss = true;
                         }
                         $group['discuss'][] = $tudu;
                         continue;
                     }
                     // 待办 & 进行中
                     $isAccepter = in_array($this->_user->address, $tudu['accepter'], true) || in_array($this->_user->userName, $tudu['accepter'], true);
                     $isSender = $tudu['sender'] == $this->_user->address || $tudu['sender'] == $this->_user->userName;
                     if ($isSender || $isAccepter) {
                         if ($tudu['status'] >= Dao_Td_Tudu_Tudu::STATUS_DONE && !$tudu['isdone']) {
                             $group['waitconfirm'][] = $tudu;
                         } elseif (($isAccepter && !$tudu['selfaccepttime'] || $isSender && !$tudu['accepttime'] || in_array('^e', $tudu['labels'])) && $tudu['type'] !== 'discuss' && !$tudu['istudugroup']) {
                             $group['await'][] = $tudu;
                         } else {
                             $group['doing'][] = $tudu;
                         }
                         continue;
                     } elseif (in_array('^e', $tudu['labels'])) {
                         $group['await'][] = $tudu;
                         continue;
                     }
                     // 其他 (被转发)
                     if ($tudu['lastposttime'] <= $threeMonthAgoDate && !$isUnread) {
                         $tudu['far'] = true;
                         $unUpdateOther = true;
                     }
                     $group['other'][] = $tudu;
                 }
                 if ($isTodo) {
                     $threeDayAgoDate = mktime(0, 0, 0, date("m"), date("d") - 3, date("Y"));
                     if (!$tudu['selfaccepttime'] && $tudu['selftudustatus'] < 3) {
                         $group['unaccept'][] = $tudu;
                         continue;
                     }
                     $k = null;
                     if (empty($tudu['endtime'])) {
                         $k = 'noendtime';
                     } elseif ($tudu['endtime'] - $today < 86400) {
                         $k = 'today';
                     } elseif ($tudu['endtime'] - $today <= 7 * 86400) {
                         $k = '7day';
                     } else {
                         $k = 'later';
                     }
                     if ($tudu['lastposttime'] <= $threeDayAgoDate && !$isUnread && $tudu['status'] >= 2) {
                         $tudu['far'] = true;
                         $unUpdateTodo[$k] = true;
                     }
                     if ($tudu['selftudustatus'] >= 2) {
                         if ($tudu['selftudustatus'] == 3) {
                             $k = 'today';
                         }
                         $group[$k]['done'][] = $tudu;
                     } else {
                         $group[$k]['undone'][] = $tudu;
                     }
                 }
                 if ($isReview) {
                     if (null !== $tudu['selfstepstatus'] && $tudu['selfstepstatus'] < 2) {
                         $group['await_review'][] = $tudu;
                     } else {
                         $group['done_review'][] = $tudu;
                     }
                 }
             }
             if ($chart == 'gantt') {
                 unset($group['notice'], $group['discuss']);
             }
             if ($isTodo) {
                 foreach ($group as $k => $g) {
                     if (array_key_exists('done', $group[$k]) || array_key_exists('undone', $group[$k])) {
                         if (!isset($group[$k]['done'])) {
                             $group[$k]['done'] = array();
                         }
                         if (!isset($group[$k]['undone'])) {
                             $group[$k]['undone'] = array();
                         }
                         $group[$k] = array_merge($group[$k]['undone'], $group[$k]['done']);
                         unset($group[$k]['undone'], $group[$k]['done']);
                     }
                 }
             }
         } else {
             $group = array();
             $sortCol = $this->_sortTypes[$sortType];
             $currYear = date('Y');
             $currWeek = date('W');
             $today = strtotime('today');
             $tomorrow = $today + 86400;
             foreach ($tudus as $tudu) {
                 $groupkey = $tudu[$sortCol];
                 if ($sortCol == 'lastposttime' || $sortCol == 'endtime') {
                     $year = date('Y', $tudu[$sortCol]);
                     $week = date('W', $tudu[$sortCol]);
                     if ($tudu[$sortCol] >= $tomorrow) {
                         $groupkey = date('Y-m-d', $tudu[$sortCol]);
                     } elseif ($tudu[$sortCol] >= $today) {
                         $groupkey = 'today';
                     } elseif ($year == $currYear && $week == $currWeek) {
                         $groupkey = date('Y-m-d', $tudu[$sortCol]);
                     } elseif ($year == $currYear && $currWeek - $week == 1) {
                         $groupkey = 'last_week';
                     } else {
                         $groupkey = 'more_early';
                     }
                 }
                 if ($sortCol == 'from') {
                     $groupkey = isset($tudu[$sortCol][0]) ? $tudu[$sortCol][0] : 'contact_null';
                 }
                 if ($sortCol == 'to') {
                     if (!$tudu['accepter']) {
                         $groupkey = 'contact_null';
                     } else {
                         $to = reset($tudu['to']);
                         $groupkey = count($tudu['accepter']) > 1 ? 'multi' : $to[0];
                     }
                 }
                 if ($sortCol == 'percent') {
                     if ($tudu['type'] == 'task' && $groupkey === null) {
                         $groupkey = 0;
                     }
                     if (($tudu['type'] == 'notice' || $tudu['type'] == 'meeting' || $tudu['type'] == 'discuss') && $groupkey == 0) {
                         $groupkey = null;
                     }
                     if ($groupkey === null) {
                         $groupkey = '-';
                     }
                 }
                 $group[$groupkey][] = $tudu;
             }
             if ($sortAsc && $sortCol == 'percent') {
                 $null = isset($group['-']) ? $group['-'] : array();
                 unset($group['-']);
                 $group['-'] = $null;
             }
             // 已拒绝、已终止的任务放相应分组的最后
             if ($sortCol == 'percent') {
                 foreach ($group as $key => $value) {
                     $sortGroups = array();
                     $pushGroups = array();
                     foreach ($value as $tudu) {
                         if ($tudu['type'] == 'task' && ($tudu['selftudustatus'] == 3 || $tudu['selftudustatus'] == 4 || $tudu['status'] == 3 || $tudu['status'] == 4)) {
                             $pushGroups[] = $tudu;
                         } else {
                             $sortGroups[] = $tudu;
                         }
                     }
                     $group[$key] = array_merge($sortGroups, $pushGroups);
                 }
             }
         }
         $tudus = $group;
     }
     if (!$isInbox && !$isTodo && !$isReview) {
         $this->view->pageinfo = array('query' => $params, 'currpage' => $page, 'pagecount' => $pageCount, 'recordcount' => $recordCount, 'url' => '/tudu/');
     }
     $this->view->columns = $columns;
     $this->view->unread = $isUnread;
     $this->view->labels = $labels;
     $this->view->tudus = $tudus;
     $this->view->label = $label;
     $this->view->sort = array($sortType, $sortAsc ^ 1);
     $this->view->issort = $isSort;
     $this->view->query = http_build_query($params);
     $this->view->unupdateother = $unUpdateOther;
     $this->view->unupdatediscuss = $unUpdateDiscuss;
     $this->view->unupdatetodo = $unUpdateTodo;
     $this->view->registFunction('format_label', array($this, 'formatLabels'));
     // 显示搜索结果列表
     if ($isSearch) {
         //$daoCast = Oray_Dao::factory('Dao_Md_Cast_Cast', $this->multidb->getDb());
         //$this->view->users  = $daoCast->getCastUsers($this->_user->orgId, $this->_user->castId)->toArray();
         $boards = $this->getBoards();
         $this->view->params = $params;
         $this->view->boards = $boards;
         $this->view->coreseek = $coreseek;
         return $this->render('search');
     }
     //var_dump($params['chart']);exit;
     if ($chart == 'gantt') {
         $this->view->registFunction('cal_gantt', array($this, 'ganttDraw'));
         $this->view->params = array('next' => $endDate + 86400, 'prev' => $startDate - 86400);
         $this->view->type = $type;
         $this->view->startdate = $startDate;
         $this->view->enddate = $endDate;
         $this->view->headers = $headers;
         return $this->render('ganttchart');
     }
 }
예제 #2
0
 /**
  * 记录搜索
  *
  */
 public function searchAction()
 {
     $key = trim($this->_request->getQuery('keyword'));
     $target = trim($this->_request->getQuery('target'));
     $range = $this->_request->getQuery('range');
     $page = max(1, (int) $this->_request->getQuery('page'));
     $fromUrl = $this->_request->getQuery('fromurl');
     $pageSize = 20;
     $timeRange = null;
     if (!empty($range)) {
         switch ($range) {
             case 'week':
                 $timeRange = array(strtotime('-7 days'), time());
                 break;
             case 'month':
                 $timeRange = array(strtotime('-30 days'), time());
                 break;
             case '3month':
                 $timeRange = array(strtotime('-90 days'), time());
                 break;
         }
     }
     $params = array('keyword' => $key, 'target' => $target, 'range' => $range, 'fromUrl' => $fromUrl);
     $config = $this->options['sphinx'];
     $sphinx = new Oray_Search_Sphinx_Client($config);
     $option = new Oray_Search_Sphinx_Option(array('sortby' => 'create_time', 'mode' => Oray_Search_Sphinx_Option::MATCH_EXTENDED2, 'offset' => ($page - 1) * $pageSize));
     $arr = preg_split('/[\\s\\+\\/]+/', $key);
     foreach ($arr as $i => $word) {
         if (!$word) {
             unset($arr[$i]);
         }
         $arr[$i] = $sphinx->escapeString($word);
     }
     $keyword = implode('|', $arr);
     $keyword = "@content \"{$keyword}\"/1";
     if ($target) {
         if ($target == '^user') {
             $email = str_replace('@', '\\@', $this->_user->userName);
             $keyword = "@users {$email} {$keyword}";
         } elseif ($target == '^groups') {
             $groupId = trim($this->_request->getQuery('groupid'));
             if ($groupId) {
                 // 获取加入时间
                 $inTime = 0;
                 $daoGroup = $this->getImDao('Dao_Im_Group_Group');
                 $member = $daoGroup->getGroupMember($groupId, $this->_user->userName);
                 if ($member) {
                     $inTime = strtotime($member['createtime']);
                     if (null == $timeRange) {
                         $timeRange = array(0 => 0, 1 => time());
                     }
                     if (empty($timeRange[0]) || $timeRange[0] < $inTime) {
                         $timeRange[0] = $inTime;
                     }
                     $gid = str_replace('-', '', str_replace('@', '\\@', $groupId));
                     $keyword = "@groupid {$gid} {$keyword}";
                 } else {
                     $keyword = null;
                 }
                 $params['groupid'] = $groupId;
             }
         } else {
             $otherId = $this->_request->getQuery('otherid');
             $otherId = str_replace('@', '\\@', $otherId);
             $email = str_replace('@', '\\@', $this->_user->userName);
             $keyword = "@users {$email}+{$otherId}|{$otherId}+{$email} {$keyword}";
             $params['otherid'] = $otherId;
         }
     }
     $logs = array();
     $total = 0;
     $keys = array();
     $w = strtolower($w);
     if ($keyword != null) {
         if (!empty($timeRange)) {
             $option->addRangeFilter('create_time', $timeRange[0], $timeRange[1]);
         }
         $result = $sphinx->query($keyword, $option, $config['indexes']['chat'] . ' ' . $config['indexes']['chatinc']);
         $matches = $result->getMatches();
         $total = $result->getTotal();
         $words = $result->getWords();
         foreach ($words as $w => $info) {
             if ($w && $info['docs'] > 0 && false !== strpos(strtolower($key), $w)) {
                 $keys[] = $w;
             }
         }
         if (count($matches)) {
             $logNums = array();
             foreach ($matches as $match) {
                 $logNums[] = $match['id'];
             }
             /* @var $daoChatLog Dao_Im_Chat_Log */
             $daoChatLog = $this->getImDao('Dao_Im_Chat_Log');
             $condition = array('ordernum' => $logNums);
             if ($target == '^groups') {
                 $condition['groupid'] = $groupId;
             } else {
                 $condition['ownerid'] = $this->_user->userName;
             }
             $logs = $daoChatLog->getLogs($condition)->toArray();
         }
     }
     $this->view->back = $this->_request->getQuery('back');
     $this->view->logs = $logs;
     $this->view->pageinfo = array('currpage' => $page, 'pagecount' => intval(($total - 1) / $pageSize + 1), 'recordcount' => $total);
     $this->view->keys = implode("','", $keys);
     $this->view->query = $params;
     $this->view->keyword = $keys;
     $this->view->type = $target == '^groups' ? 'group' : 'user';
 }