From f9401d3519911f65f3a783376ce4a95c23d2dcdc Mon Sep 17 00:00:00 2001 From: liumengyi Date: Wed, 29 Nov 2023 10:36:56 +0800 Subject: [PATCH] * Refactor messageModel::getNoticeTodos, and modify its unit test. --- module/message/model.php | 25 +++++++++++--------- module/message/test/message.class.php | 11 +++++---- module/message/test/model/getnoticetodos.php | 11 +++++++-- module/message/test/yaml/todo.yaml | 21 ++++++++++++++++ 4 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 module/message/test/yaml/todo.yaml diff --git a/module/message/model.php b/module/message/model.php index 529991ef99..916ed5637b 100755 --- a/module/message/model.php +++ b/module/message/model.php @@ -224,12 +224,13 @@ class messageModel extends model } /** + * 获取提示待办。 * Get notice todos. * * @access public * @return array */ - public function getNoticeTodos() + public function getNoticeTodos(): array { $todos = $this->loadModel('todo')->getList('today', $this->app->user->account, 'wait'); $notices = array(); @@ -237,21 +238,23 @@ class messageModel extends model $interval = 60; if($todos) { - $begins[1] = date('Hi', strtotime($now)); - $ends[1] = date('Hi', strtotime("+$interval seconds $now")); - $begins[10] = date('Hi', strtotime("+10 minute $now")); - $ends[10] = date('Hi', strtotime("+10 minute $interval seconds $now")); - $begins[30] = date('Hi', strtotime("+30 minute $now")); - $ends[30] = date('Hi', strtotime("+30 minute $interval seconds $now")); + /* Set date array. */ + $begins[1] = (int)date('Hi', strtotime($now)); + $begins[10] = (int)date('Hi', strtotime("+10 minute {$now}")); + $begins[30] = (int)date('Hi', strtotime("+30 minute {$now}")); + $ends[1] = (int)date('Hi', strtotime("+{$interval} seconds {$now}")); + $ends[10] = (int)date('Hi', strtotime("+10 minute {$interval} seconds {$now}")); + $ends[30] = (int)date('Hi', strtotime("+30 minute {$interval} seconds {$now}")); foreach($todos as $todo) { if(empty($todo->begin)) continue; - $time = str_replace(':', '', $todo->begin); + $time = (int)str_replace(':', '', $todo->begin); $lastTime = 0; - if((int)$time > (int)$begins[1] and (int)$time <= (int)$ends[1]) $lastTime = 1; - if((int)$time > (int)$begins[10] and (int)$time <= (int)$ends[10]) $lastTime = 10; - if((int)$time > (int)$begins[30] and (int)$time <= (int)$ends[30]) $lastTime = 30; + if($time > $begins[1] && $time <= $ends[1]) $lastTime = 1; + if($time > $begins[10] && $time <= $ends[10]) $lastTime = 10; + if($time > $begins[30] && $time <= $ends[30]) $lastTime = 30; + /* If the todo needs to be reminded, add it to notices array. */ if($lastTime) { $notice = new stdclass(); diff --git a/module/message/test/message.class.php b/module/message/test/message.class.php index 80f89f5d56..c8b2b28846 100644 --- a/module/message/test/message.class.php +++ b/module/message/test/message.class.php @@ -137,17 +137,20 @@ class messageTest } /** - * Get notice todos. + * 测试获取要提示的待办信息。 + * Test get notice todos. * + * @param string $account * @access public - * @return void + * @return string|array */ - public function getNoticeTodosTest() + public function getNoticeTodosTest(string $account): string|array { + su($account); $objects = $this->objectModel->getNoticeTodos(); if(dao::isError()) return dao::getError(); - return $objects; + return implode(',', array_keys($objects)); } } diff --git a/module/message/test/model/getnoticetodos.php b/module/message/test/model/getnoticetodos.php index 07bc79c63a..a550e6f8f9 100755 --- a/module/message/test/model/getnoticetodos.php +++ b/module/message/test/model/getnoticetodos.php @@ -1,8 +1,11 @@ #!/usr/bin/env php config('todo')->gen(20); +zdTable('user')->gen(3); /** @@ -16,4 +19,8 @@ pid=1 $message = new messageTest(); -r($message->getNoticeTodosTest()) && p('0') && e('0'); //查询notice为空的todo的信息 \ No newline at end of file +$account = array('admin', 'user1', 'user2'); + +r($message->getNoticeTodosTest($account[0])) && p('0') && e('todo3,todo7,todo11'); // 查询 admin 的需要提示的待办信息 +r($message->getNoticeTodosTest($account[1])) && p('0') && e('todo15,todo19'); // 查询 user1 的需要提示的待办信息 +r($message->getNoticeTodosTest($account[2])) && p('0') && e('0'); // 查询 user2 的需要提示的待办信息 diff --git a/module/message/test/yaml/todo.yaml b/module/message/test/yaml/todo.yaml new file mode 100644 index 0000000000..98d51cc9af --- /dev/null +++ b/module/message/test/yaml/todo.yaml @@ -0,0 +1,21 @@ +title: zt_todo +desc: "待办" +author: Mengyi Liu +version: "1.0" +fields: + - field: assignedTo + range: "admin{3},user1{2}" + - field: status + range: wait,closed + - field: date + range: "(-2D)-(+2D):1D" + type: timestamp + format: "YY/MM/DD" + - field: begin + range: "(+1m)-(+3m):60" + type: timestamp + format: "hhmm" + - field: end + range: "(+2m)-(+4m):60" + type: timestamp + format: "hhmm"