<?php
/**
* Tudu Controller
*
* @author Hiro
* @version $Id: TuduController.php 2920 2013-08-08 08:33:45Z cutecube $
*/
class TuduController extends TuduX_Controller_Base
{
/**
*
*/
private $_sortTypes = array('lastposttime', 'subject', 'endtime', 'from', 'to', 'starttime', 'percent');
/**
*
* @var array
*/
private $_depts;
/**
*
* @var array
*/
private $_labelVisible = array(
'^all' => 0,
'^i' => 1,
'^a' => 2,
'^r' => 1,
'^e' => 2,
'^v' => 2,
'^m' => 2,
'^f' => 2,
'^t' => 2,
'^n' => 0,
'^d' => 0,
'^o' => 0,
'^g' => 0
);
public function preDispatch()
{
$this->lang = Tudu_Lang::getInstance()->load(array('common', 'tudu'));
$this->view->LANG = $this->lang;
if (!$this->_user->isLogined()) {
$this->jump(null, array('error' => 'timeout'));
}
// IP或登录时间无效
if (!empty($this->session->auth['invalid'])) {
$this->jump('/forbid/');
}
$this->view->uploadsizelimit = $this->options['upload']['sizelimit'] / 1024;
}
/**
* 默认(图度列表)
*/
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'] = !(boolean) $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;
// 全文搜索
} else