From 944b476e32fa59e9da900529ef640b3db5afdb48 Mon Sep 17 00:00:00 2001 From: shenshulong Date: Thu, 4 May 2023 02:37:49 +0000 Subject: [PATCH] * Adjusted todo model the assignTo and getCount function. --- module/todo/model.php | 19 +++++++------------ module/todo/tao.php | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/module/todo/model.php b/module/todo/model.php index 03af18945b..e9def53891 100755 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -579,32 +579,27 @@ class todoModel extends model */ public function assignTo(object $todo): bool { - $result = $this->todoTao->updateRow((int)$todo->id, $todo); + $todoID = (int)$todo->id; + $result = $this->todoTao->updateRow($todoID, $todo); if(!$result) return false; - $this->loadModel('action')->create('todo', (int)$todo->id, 'assigned', '', $todo->assignedTo); + $this->loadModel('action')->create('todo', $todoID, 'assigned', '', $todo->assignedTo); return !dao::isError(); } /** + * 获取待办事项的数量。 * Get todo count. * * @param string $account * @access public * @return int */ - public function getCount($account = '') + public function getCount(string $account = ''): int { if(empty($account)) $account = $this->app->user->account; - return $this->dao->select('count(*) as count')->from(TABLE_TODO) - ->where('cycle')->eq('0') - ->andWhere('deleted')->eq('0') - ->andWhere('vision')->eq($this->config->vision) - ->andWhere('account', true)->eq($account) - ->orWhere('assignedTo')->eq($account) - ->orWhere('finishedBy')->eq($account) - ->markRight(1) - ->fetch('count'); + + return $this->todoTao->getTodoCountByAccount($account); } /** diff --git a/module/todo/tao.php b/module/todo/tao.php index 72d304ba79..f980541e29 100644 --- a/module/todo/tao.php +++ b/module/todo/tao.php @@ -324,4 +324,25 @@ class todoTao extends todoModel $this->dao->update(TABLE_TODO)->set('date')->eq($date)->where('id')->in($todoIdList)->exec(); return !dao::isError(); } + + /** + * 获取用户的待办事项数量。 + * Get todo count on the account. + * + * @param string $account + * @access protected + * @return int + */ + protected function getTodoCountByAccount(string $account): int + { + return $this->dao->select('count(*) as count')->from(TABLE_TODO) + ->where('cycle')->eq('0') + ->andWhere('deleted')->eq('0') + ->andWhere('vision')->eq($this->config->vision) + ->andWhere('account', true)->eq($account) + ->orWhere('assignedTo')->eq($account) + ->orWhere('finishedBy')->eq($account) + ->markRight(1) + ->fetch('count'); + } }