From bdcb3f1df4db56931dea0f65b5c50d9a55bacfef Mon Sep 17 00:00:00 2001 From: jukui Date: Fri, 5 May 2023 09:14:14 +0800 Subject: [PATCH] * Optimized getList function for todo model. --- module/todo/config.php | 16 ---------------- module/todo/model.php | 37 +++++++++++++++++++++++++++++++------ module/todo/tao.php | 4 ++-- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/module/todo/config.php b/module/todo/config.php index d1603458e2..948d1bf652 100644 --- a/module/todo/config.php +++ b/module/todo/config.php @@ -1,7 +1,6 @@ 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']); diff --git a/module/todo/model.php b/module/todo/model.php index 353bdd2a2d..7c9727be6a 100755 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -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列表为空则返回所有待办。 diff --git a/module/todo/tao.php b/module/todo/tao.php index 9c7277c8db..a341af9768 100644 --- a/module/todo/tao.php +++ b/module/todo/tao.php @@ -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')