+ enhanced the feature of todo.

This commit is contained in:
wangchunsheng
2009-11-05 09:43:41 +00:00
parent 059ba9a56b
commit ba5909ccee
4 changed files with 70 additions and 9 deletions

View File

@@ -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();
}

View File

@@ -95,10 +95,10 @@ EOT;
<div>
<?php
echo html::select('date', $dates, $date, 'onchange=changeDate(this.value)');
//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=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);
?>
</div>

View File

@@ -27,6 +27,7 @@
<thead>
<tr>
<th><?php echo $lang->todo->id;?></th>
<th><?php echo $lang->todo->date;?></th>
<th><?php echo $lang->todo->type;?></th>
<th><?php echo $lang->todo->pri;?></th>
<th><?php echo $lang->todo->name;?></th>
@@ -41,6 +42,7 @@
<?php foreach($todos as $todo):?>
<tr class='a-center'>
<td><?php echo $todo->id;?></td>
<td><?php echo $todo->date;?></td>
<td><?php echo $lang->todo->typeList->{$todo->type};?></td>
<td><?php echo $todo->pri;?></td>
<td class='a-left'>

View File

@@ -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;
}
}