* Optimized getList function for todo model.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
helper::import(dirname(__FILE__) . 'config/form.php');
|
||||
helper::import(dirname(dirname(dirname(__FILE__))) . '/lib/date/date.class.php');
|
||||
|
||||
$config->todo = new stdclass();
|
||||
$config->todo->maxBatchCreate = 8;
|
||||
@@ -62,18 +61,3 @@ if($this->config->edition == 'max')
|
||||
$config->todo->project['opportunity'] = TABLE_OPPORTUNITY;
|
||||
$config->todo->project['review'] = TABLE_REVIEW;
|
||||
}
|
||||
|
||||
$config->todo->dateRange = array();
|
||||
$config->todo->dateRange['all'] = array('begin' => '1970-01-01', 'end' => '2109-01-01');
|
||||
$config->todo->dateRange['assignedtoother'] = array('begin' => '1970-01-01', 'end' => '2109-01-01');
|
||||
$config->todo->dateRange['today'] = array('begin' => date::today(), 'end' => date::today());
|
||||
$config->todo->dateRange['future'] = array('begin' => '2030-01-01', 'end' => '2030-01-01');
|
||||
$config->todo->dateRange['before'] = array('begin' => '1970-01-01', 'end' => date::today());
|
||||
$config->todo->dateRange['cycle'] = array('begin' => '', 'end' => '');
|
||||
$config->todo->dateRange['yesterday'] = array('begin' => date::yesterday(), 'end' => date::yesterday());
|
||||
$config->todo->dateRange['thisweek'] = array('begin' => date::getThisWeek()['begin'], 'end' => date::getThisWeek()['end']);
|
||||
$config->todo->dateRange['lastweek'] = array('begin' => date::getLastWeek()['begin'], 'end' => date::getLastWeek()['end']);
|
||||
$config->todo->dateRange['thismonth'] = array('begin' => date::getThisMonth()['begin'], 'end' => date::getThisMonth()['end']);
|
||||
$config->todo->dateRange['lastmonth'] = array('begin' => date::getLastMonth()['begin'], 'end' => date::getLastMonth()['end']);
|
||||
$config->todo->dateRange['thisseason'] = array('begin' => date::getThisSeason()['begin'], 'end' => date::getThisSeason()['end']);
|
||||
$config->todo->dateRange['thisyear'] = array('begin' => date::getThisYear()['begin'], 'end' => date::getThisYear()['end']);
|
||||
|
||||
+31
-6
@@ -249,17 +249,14 @@ class todoModel extends model
|
||||
*/
|
||||
public function getList(string $type = 'today', string $account = '', string|array $status = 'all', int $limit = 0, object $pager = null, string $orderBy="date, status, begin"): array
|
||||
{
|
||||
$this->app->loadClass('date');
|
||||
$todos = array();
|
||||
$type = strtolower($type);
|
||||
$type = strtolower($type);
|
||||
|
||||
$dateRange = $this->config->todo->dateRange[$type] ? $this->config->todo->dateRange[$type] : array('begin' => $type, 'end' => $type);
|
||||
$begin = (string)$dateRange['begin'];
|
||||
$end = (string)$dateRange['end'];
|
||||
$dateRange = $this->dateRange($type);
|
||||
|
||||
if(empty($account)) $account = $this->app->user->account;
|
||||
|
||||
$stmt = $this->todoTao->getListQuery($type, $account, $status, $begin, $end, $pager, $limit, $orderBy);
|
||||
$stmt = $this->todoTao->getListQuery($type, $account, $status, (string)$dateRange['begin'], (string)$dateRange['end'], $limit, $orderBy, $pager);
|
||||
|
||||
/* Set session. */
|
||||
$sql = explode('WHERE', $this->dao->get());
|
||||
@@ -281,6 +278,34 @@ class todoModel extends model
|
||||
return $todos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取时间范围。
|
||||
* Date range.
|
||||
*
|
||||
* @param string $type
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function dateRange($type): array
|
||||
{
|
||||
$this->app->loadClass('date');
|
||||
$dateRange['all'] = array('begin' => '1970-01-01', 'end' => '2109-01-01');
|
||||
$dateRange['assignedtoother'] = array('begin' => '1970-01-01', 'end' => '2109-01-01');
|
||||
$dateRange['today'] = array('begin' => date::today(), 'end' => date::today());
|
||||
$dateRange['future'] = array('begin' => '2030-01-01', 'end' => '2030-01-01');
|
||||
$dateRange['before'] = array('begin' => '1970-01-01', 'end' => date::today());
|
||||
$dateRange['cycle'] = array('begin' => '', 'end' => '');
|
||||
$dateRange['yesterday'] = array('begin' => date::yesterday(), 'end' => date::yesterday());
|
||||
$dateRange['thisweek'] = array('begin' => date::getThisWeek()['begin'], 'end' => date::getThisWeek()['end']);
|
||||
$dateRange['lastweek'] = array('begin' => date::getLastWeek()['begin'], 'end' => date::getLastWeek()['end']);
|
||||
$dateRange['thismonth'] = array('begin' => date::getThisMonth()['begin'], 'end' => date::getThisMonth()['end']);
|
||||
$dateRange['lastmonth'] = array('begin' => date::getLastMonth()['begin'], 'end' => date::getLastMonth()['end']);
|
||||
$dateRange['thisseason'] = array('begin' => date::getThisSeason()['begin'], 'end' => date::getThisSeason()['end']);
|
||||
$dateRange['thisyear'] = array('begin' => date::getThisYear()['begin'], 'end' => date::getThisYear()['end']);
|
||||
|
||||
return isset($dateRange[$type]) ? $dateRange[$type] : array('begin' => $type, 'end' => $type);;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过包含一个或多个待办ID的列表获取待办列表,这个列表是以todoID为key、以todo对象为value的数组。
|
||||
* 如果待办ID列表为空则返回所有待办。
|
||||
|
||||
+2
-2
@@ -486,13 +486,13 @@ class todoTao extends todoModel
|
||||
* @param string|array $status
|
||||
* @param string $begin
|
||||
* @param string $end
|
||||
* @param object $pager
|
||||
* @param int $limit
|
||||
* @param string $orderBy
|
||||
* @param object $pager
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function getListQuery(string $type, string $account, array|string $status, string $begin, string $end, object $pager = null, int $limit, string $orderBy): object
|
||||
protected function getListQuery(string $type, string $account, array|string $status, string $begin, string $end, int $limit, string $orderBy, object $pager = null): object
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_TODO)
|
||||
->where('deleted')->eq('0')
|
||||
|
||||
Reference in New Issue
Block a user