From ba5909ccee8be976c94f160bd8d813445632d412 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Thu, 5 Nov 2009 09:43:41 +0000 Subject: [PATCH] + enhanced the feature of todo. --- trunk/module/my/control.php | 5 ++- trunk/module/my/view/header.html.php | 8 ++-- trunk/module/my/view/todo.html.php | 2 + trunk/module/todo/model.php | 64 ++++++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/trunk/module/my/control.php b/trunk/module/my/control.php index 8f26bf7fbe..d7c2fe0bb3 100644 --- a/trunk/module/my/control.php +++ b/trunk/module/my/control.php @@ -46,7 +46,8 @@ class my extends control $header['title'] = $this->lang->my->common . $this->lang->colon . $this->lang->my->todo; $position[] = $this->lang->my->todo; - if($date == 'today') $date = $this->todo->today(); + $todos = $this->todo->getList($date); + if((int)$date == 0) $date = $this->todo->today(); /* 赋值。*/ $this->assign('header', $header); @@ -54,7 +55,7 @@ class my extends control $this->assign('tabID', 'todo'); $this->assign('dates', $this->todo->buildDateList()); $this->assign('date', $date); - $this->assign('todos', $this->todo->getList($date)); + $this->assign('todos', $todos); $this->display(); } diff --git a/trunk/module/my/view/header.html.php b/trunk/module/my/view/header.html.php index 3cafd1c7ec..e915d0f325 100644 --- a/trunk/module/my/view/header.html.php +++ b/trunk/module/my/view/header.html.php @@ -95,10 +95,10 @@ EOT;
createLink('my', 'todo', "date=thisweek"), $lang->todo->thisWeekTodos); - //echo html::a($this->createLink('my', 'todo', "date=lastweek"), $lang->todo->lastWeekTodos); - //echo html::a($this->createLink('my', 'todo', "date=alldays"), $lang->todo->allDaysTodos); - //echo html::a($this->createLink('my', 'todo', "date=allundone"), $lang->todo->allUndone); + echo html::a($this->createLink('my', 'todo', "date=thisweek"), $lang->todo->thisWeekTodos); + echo html::a($this->createLink('my', 'todo', "date=lastweek"), $lang->todo->lastWeekTodos); + echo html::a($this->createLink('my', 'todo', "date=all"), $lang->todo->allDaysTodos); + echo html::a($this->createLink('my', 'todo', "date=all&account={$app->user->account}&status=wait,doing"), $lang->todo->allUndone); echo html::a($this->createLink('todo', 'create', "date=$date"), $lang->todo->create); ?>
diff --git a/trunk/module/my/view/todo.html.php b/trunk/module/my/view/todo.html.php index c2f1661a07..6637459cba 100644 --- a/trunk/module/my/view/todo.html.php +++ b/trunk/module/my/view/todo.html.php @@ -27,6 +27,7 @@ todo->id;?> + todo->date;?> todo->type;?> todo->pri;?> todo->name;?> @@ -41,6 +42,7 @@ id;?> + date;?> todo->typeList->{$todo->type};?> pri;?> diff --git a/trunk/module/todo/model.php b/trunk/module/todo/model.php index 968ffa4fca..ca1961ac81 100644 --- a/trunk/module/todo/model.php +++ b/trunk/module/todo/model.php @@ -84,12 +84,42 @@ class todoModel extends model } /* 获得用户的todo列表。*/ - public function getList($date = 'today', $account = '') + public function getList($date = 'today', $account = '', $status = 'all') { $todos = array(); - if($date == 'today') $date = $this->today(); + if($date == 'today') + { + $begin = $this->today(); + $end = $begin; + } + elseif($date == 'thisweek') + { + extract($this->getThisWeek()); + } + elseif($date == 'lastweek') + { + extract($this->getLastWeek()); + } + elseif($date == 'all') + { + $begin = '1970-01-01'; + $end = '2109-01-01'; + } + else + { + $begin = $end = $date; + } + if($account == '') $account = $this->app->user->account; - $stmt = $this->dao->select('*')->from(TABLE_TODO)->where('account')->eq($account)->andWhere('date')->eq($date)->orderBy('status, begin')->query(); + if($status == 'all') $status = 'wait,doing,done'; + + $stmt = $this->dao->select('*')->from(TABLE_TODO) + ->where('account')->eq($account) + ->andWhere("date >= '$begin'") + ->andWhere("date <= '$end'") + ->andWhere('status')->in($status) + ->orderBy('date, status, begin') + ->query(); while($todo = $stmt->fetch()) { if($todo->type == 'task') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name'); @@ -185,4 +215,32 @@ class todoModel extends model if(strlen($time) != 4 or $time == '2400') return ''; return substr($time, 0, 2) . ':' . substr($time, 2, 2); } + + /* 获得本周起止时间。*/ + public function getThisWeek() + { + $baseTime = $this->getMiddleOfWeek(); + $begin = date('Y-m-d', strtotime('last monday', $baseTime)); + $end = date('Y-m-d', strtotime('next sunday', $baseTime)); + return array('begin' => $begin, 'end' => $end); + } + + /* 获得上周起止时间。*/ + public function getLastWeek() + { + $baseTime = strtotime('last thursday'); // 取上个礼拜二的时间为基准时间。 + $begin = date('Y-m-d', strtotime('last monday', $baseTime)); + $end = date('Y-m-d', strtotime('next sunday', $baseTime)); + return array('begin' => $begin, 'end' => $end); + } + + /* 获得周中的时间戳,如果当前时间为礼拜一,则往后取一天,为礼拜天,则往前取一天,保证基准时间落在周中。*/ + private function getMiddleOfWeek() + { + $baseTime = time(); + $weekDay = date('N'); + if($weekDay == 1) $baseTime = time() + 86400; + if($weekDay == 7) $baseTime = time() - 86400; + return $baseTime; + } }