* Refactor close method and case.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$now = helper::now();
|
||||
|
||||
global $app;
|
||||
$config->program->form = new stdclass();
|
||||
|
||||
$config->program->form->close['realEnd'] = array('type' => 'string', 'required' => true, 'default' => $now, 'filter' => 'trim');
|
||||
$config->program->form->close['status'] = array('type' => 'string', 'required' => false, 'default' => 'closed');
|
||||
$config->program->form->close['closedDate'] = array('type' => 'string', 'required' => false, 'default' => $now);
|
||||
$config->program->form->close['closedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account);
|
||||
$config->program->form->close['lastEditedDate'] = array('type' => 'string', 'required' => false, 'default' => $now);
|
||||
$config->program->form->close['lastEditedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account);
|
||||
@@ -266,13 +266,14 @@ class program extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭一个项目集。
|
||||
* Close a program.
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function close($programID)
|
||||
public function close(int $programID)
|
||||
{
|
||||
$this->loadModel('action');
|
||||
$program = $this->program->getByID($programID);
|
||||
@@ -283,10 +284,11 @@ class program extends control
|
||||
$hasUnfinished = $this->program->hasUnfinished($program);
|
||||
if($hasUnfinished) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$this->lang->program->closeErrorMessage}');"));
|
||||
|
||||
$changes = $this->program->close($programID);
|
||||
$programData = form::data()->get();
|
||||
$changes = $this->program->close($programData, $program);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
if($this->post->comment != '' or !empty($changes))
|
||||
if($this->post->comment != '' || !empty($changes))
|
||||
{
|
||||
$actionID = $this->action->create('program', $programID, 'Closed', $this->post->comment);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
|
||||
@@ -973,37 +973,26 @@ class programModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Close program.
|
||||
* 关闭一个项目集。
|
||||
* Close a program.
|
||||
*
|
||||
* @param int $programID
|
||||
* @param object $oldProgram
|
||||
* @param object $program
|
||||
* @access public
|
||||
* @return array
|
||||
* @return array|bool
|
||||
*/
|
||||
public function close(int $programID) :array
|
||||
public function close(object $program, object $oldProgram) :array|bool
|
||||
{
|
||||
$oldProgram = $this->getById($programID);
|
||||
$now = helper::now();
|
||||
|
||||
$program = fixer::input('post')
|
||||
->setDefault('status', 'closed')
|
||||
->setDefault('closedBy', $this->app->user->account)
|
||||
->setDefault('closedDate', $now)
|
||||
->setDefault('lastEditedBy', $this->app->user->account)
|
||||
->setDefault('lastEditedDate', $now)
|
||||
->stripTags($this->config->program->editor->close['id'], $this->config->allowedTags)
|
||||
->remove('comment')
|
||||
->get();
|
||||
|
||||
$program = $this->loadModel('file')->processImgURL($program, $this->config->program->editor->close['id'], $this->post->uid);
|
||||
|
||||
$this->dao->update(TABLE_PROJECT)->data($program)
|
||||
->autoCheck()
|
||||
->checkIF($program->realEnd != '', 'realEnd', 'le', helper::today())
|
||||
->checkIF($program->realEnd != '', 'realEnd', 'ge', $oldProgram->realBegan)
|
||||
->checkFlow()
|
||||
->where('id')->eq((int)$programID)
|
||||
->where('id')->eq($oldProgram->id)
|
||||
->exec();
|
||||
|
||||
if(dao::isError()) return false;
|
||||
return common::createChanges($oldProgram, $program);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/program.class.php';
|
||||
zdTable('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
$program = zdTable('project')->config('program');
|
||||
$program->realBegan->range('`2023-09-11`');
|
||||
$program->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 programModel::close();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
*/
|
||||
|
||||
$programID = 1;
|
||||
$maxDate = array('realEnd' => date('Y-m-d', strtotime('+1 day')));
|
||||
$minDate = array('realEnd' => '2023-09-10');
|
||||
$normalDate = array('realEnd' => '2023-09-12');
|
||||
|
||||
$programTester = new programTest();
|
||||
r($programTester->closeTest($programID, $maxDate)) && p('realEnd:0') && e('~f:『实际完成日期』应当不大于~'); // 测试实际完成时间大于今日的情况
|
||||
r($programTester->closeTest($programID, $minDate)) && p('realEnd:0') && e('『实际完成日期』应当不小于『2023-09-11』。'); // 测试实际完成时间小于实际开始时间的情况
|
||||
r($programTester->closeTest($programID, $normalDate)) && p('0:field,old,new') && e('status,doing,close'); // 测试关闭一个项目集
|
||||
@@ -468,4 +468,32 @@ class programTest
|
||||
|
||||
return $this->program->getProgramIDByObject($objectID, $object, $objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭一个项目集。
|
||||
* Close a program.
|
||||
*
|
||||
* @param int $programID
|
||||
* @param array $postData
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function closeTest(int $programID, array $postData): array
|
||||
{
|
||||
$now = helper::now();
|
||||
$oldProgram = $this->program->getByID($programID);
|
||||
|
||||
$program = new stdclass();
|
||||
$program->status = 'close';
|
||||
$program->closedDate = $now;
|
||||
$program->closedBy = 'admin';
|
||||
$program->lastEditedDate = $now;
|
||||
$program->lastEditedBy = 'admin';
|
||||
foreach($postData as $field => $value) $program->{$field} = $value;
|
||||
|
||||
$changes = $this->program->close($program, $oldProgram);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $changes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ formPanel
|
||||
set::name('realEnd'),
|
||||
set::control('date'),
|
||||
set::value(!helper::isZeroDate($program->realEnd) ? $program->realEnd : helper::today()),
|
||||
set::required(true)
|
||||
),
|
||||
formGroup
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user