* Refactor messageModel::getNoticeTodos, and modify its unit test.
This commit is contained in:
+14
-11
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/message.class.php';
|
||||
su('admin');
|
||||
|
||||
zdTable('todo')->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的信息
|
||||
$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 的需要提示的待办信息
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user