Merge branch 'sprint/167' of https://gitlab.zcorp.cc/easycorp/zentaopms into sprint/167

This commit is contained in:
王怡栋
2021-10-18 10:20:31 +08:00
10 changed files with 204 additions and 46 deletions
+1
View File
@@ -274,6 +274,7 @@ class requests {
public static function post($url, $headers = array(), $data = array(), $options = array()) {
return self::request($url, $headers, $data, self::POST, $options);
}
/**
* Send a PUT request
*/
+2 -2
View File
@@ -541,7 +541,7 @@ class my extends control
/* Get PM id list. */
$accounts = array();
$projects = $this->user->getExecutions($this->app->user->account, 'project', $status, 'id_desc', $pager);
$projects = $this->user->getObjects($this->app->user->account, 'project', $status, 'id_desc', $pager);
foreach($projects as $project)
{
if(!empty($project->PM) and !in_array($project->PM, $accounts)) $accounts[] = $project->PM;
@@ -581,7 +581,7 @@ class my extends control
$this->view->title = $this->lang->my->common . $this->lang->colon . $this->lang->my->execution;
$this->view->position[] = $this->lang->my->execution;
$this->view->tabID = 'project';
$this->view->executions = $this->user->getExecutions($this->app->user->account, 'execution', $type, $orderBy, $pager);
$this->view->executions = $this->user->getObjects($this->app->user->account, 'execution', $type, $orderBy, $pager);
$this->view->type = $type;
$this->view->pager = $pager;
$this->view->mode = 'execution';
-1
View File
@@ -493,7 +493,6 @@ class projectModel extends model
{
return $this->dao->select('*')->from(TABLE_PROJECT)
->where('type')->eq('project')
->andWhere('deleted')->eq(0)
->andWhere('id')->in($projectIdList)
->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->projects)->fi()
->fetchAll('id');
+1 -1
View File
@@ -362,7 +362,7 @@ class user extends control
$this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->execution;
$this->view->position[] = $this->lang->user->execution;
$this->view->tabID = 'project';
$this->view->executions = $this->user->getExecutions($account, 'execution', 'all', $orderBy, $pager);
$this->view->executions = $this->user->getObjects($account, 'execution', 'all', $orderBy, $pager);
$this->view->user = $user;
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
+34 -38
View File
@@ -1043,7 +1043,7 @@ class userModel extends model
}
/**
* Get execution a user participated.
* Get the project or execution in which the user participates..
*
* @param string $account
* @param string $type project|execution
@@ -1053,13 +1053,13 @@ class userModel extends model
* @access public
* @return array
*/
public function getExecutions($account, $type = 'execution', $status = 'all', $orderBy = 'id_desc', $pager = null)
public function getObjects($account, $type = 'execution', $status = 'all', $orderBy = 'id_desc', $pager = null)
{
$projectType = $type == 'execution' ? 'sprint,stage' : $type;
$myProjectsList = $this->dao->select('t1.*,t2.*')->from(TABLE_TEAM)->alias('t1')
$objectType = $type == 'execution' ? 'sprint,stage' : $type;
$myObjectsList = $this->dao->select('t1.*,t2.*')->from(TABLE_TEAM)->alias('t1')
->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.root = t2.id')
->where('t1.type')->eq($type)
->andWhere('t2.type')->in($projectType)
->andWhere('t2.type')->in($objectType)
->beginIF(strpos('doing|wait|suspended|closed', $status) !== false)->andWhere('status')->eq($status)->fi()
->beginIF($status == 'done')->andWhere('status')->in('done,closed')->fi()
->beginIF($status == 'undone')->andWhere('status')->notin('done,closed')->fi()
@@ -1070,12 +1070,14 @@ class userModel extends model
->andWhere('t2.deleted')->eq(0)
->orderBy("t2.$orderBy")
->page($pager)
->fetchGroup('project');
->fetchAll('root');
$objectIdList = array();
$projectIdList = array();
foreach($myProjectsList as $projects)
foreach($myObjectsList as $object)
{
foreach($projects as $project) $projectIdList[] = $project->id;
$objectIdList[] = $object->id;
$projectIdList[] = $object->project;
}
/* Get all tasks and compute totalConsumed, totalLeft, totalWait, progress according to them. */
@@ -1085,22 +1087,22 @@ class userModel extends model
$tasks = $this->dao->select('id, project, execution, consumed, `left`, status, assignedTo')
->from(TABLE_TASK)
->where('parent')->lt(1)
->andWhere($searchField)->in($projectIdList)->fi()
->andWhere($searchField)->in($objectIdList)->fi()
->andWhere('deleted')->eq(0)
->fetchGroup($searchField, 'id');
/* Compute totalEstimate, totalConsumed, totalLeft. */
foreach($tasks as $projectID => $projectTasks)
foreach($tasks as $objectID => $objectTasks)
{
$hour = (object)$emptyHour;
foreach($projectTasks as $task)
foreach($objectTasks as $task)
{
if($task->status == 'wait') $hour->waitTasks += 1;
if($task->status != 'cancel') $hour->totalConsumed += $task->consumed;
if($task->status != 'cancel' and $task->status != 'closed') $hour->totalLeft += $task->left;
if($task->assignedTo == $account) $hour->assignedToMeTasks += 1;
}
$hours[$projectID] = $hour;
$hours[$objectID] = $hour;
}
/* Compute totalReal and progress. */
@@ -1112,37 +1114,31 @@ class userModel extends model
$hour->progress = $hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0;
}
$projectIdList = array_keys($myProjectsList);
$projectList = $this->loadModel('project')->getByIdList($projectIdList);
$myProjects = array();
foreach($myProjectsList as $projects)
$myObjects = array();
$projectList = $this->loadModel('project')->getByIdList($projectIdList);
foreach($myObjectsList as $object)
{
foreach($projects as $project)
/* Judge whether the project or execution is delayed. */
if($object->status != 'done' and $object->status != 'closed' and $object->status != 'suspended')
{
/* Judge whether the project is delayed. */
if($project->status != 'done' and $project->status != 'closed' and $project->status != 'suspended')
{
$delay = helper::diffDate(helper::today(), $project->end);
if($delay > 0) $project->delay = $delay;
}
/* Process the hours. */
$project->progress = isset($hours[$project->id]) ? $hours[$project->id]->progress : 0;
$project->waitTasks = isset($hours[$project->id]) ? $hours[$project->id]->waitTasks : 0;
$project->assignedToMeTasks = isset($hours[$project->id]) ? $hours[$project->id]->assignedToMeTasks : 0;
if($project->project)
{
$parentProject = zget($projectList, $project->project, '');
if(empty($parentProject)) $parentProject = $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->eq($project->project)->fetch();
$project->projectName = $parentProject ? $parentProject->name : '';
}
$myProjects[$project->id] = $project;
$delay = helper::diffDate(helper::today(), $object->end);
if($delay > 0) $object->delay = $delay;
}
/* Process the hours. */
$object->progress = isset($hours[$object->id]) ? $hours[$object->id]->progress : 0;
$object->waitTasks = isset($hours[$object->id]) ? $hours[$object->id]->waitTasks : 0;
$object->assignedToMeTasks = isset($hours[$object->id]) ? $hours[$object->id]->assignedToMeTasks : 0;
if($object->project)
{
$parentProject = zget($projectList, $object->project, '');
$object->projectName = $parentProject ? $parentProject->name : '';
}
$myObjects[$object->id] = $object;
}
return $myProjects;
return $myObjects;
}
/**
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
/**
title=测试API 用户获取token;
cid=1
pid=1
使用正确用户名和密码获取token >> `[A-Za-z0-9]+`
使用正确用户名和密码获取token >> 登录失败,请检查您的用户名或密码是否填写正确。
*/
$pass = $rest->post('/tokens', array('account' => 'admin', 'password' => '123qwe!@#'));
$fail = $rest->post('/tokens', array('account' => 'admin', 'password' => '123'));
r($pass) && c(201) && p('token') && e('`[A-Za-z0-9]+`'); // 使用正确用户名和密码获取token
r($fail) && c(400) && p('error') && e('登录失败,请检查您的用户名或密码是否填写正确。'); // 使用正确用户名和密码获取token
+26 -2
View File
@@ -17,6 +17,26 @@ error_reporting(E_ALL & E_STRICT);
$frameworkRoot = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'framework' . DIRECTORY_SEPARATOR;
/**
* Assert status code and set body as $_result.
*
* @param int $code
* @access public
* @return bool
*/
function c($code)
{
global $_result;
if($_result and isset($_result->status_code) and $_result->status_code == $code)
{
$_result = $_result->body;
return true;
}
echo ">> \n\n";
return false;
}
/* Load the framework. */
include $frameworkRoot . 'router.class.php';
include $frameworkRoot . 'control.class.php';
@@ -26,8 +46,12 @@ include $frameworkRoot . 'helper.class.php';
$app = router::createApp('pms', dirname(dirname(__FILE__)), 'router');
$tester = $app->loadCommon();
/* Load libraries. */
/* Load rest for api. */
if(!isset($config->webSite)) die("Error: \$config->webSite is not set.\n");
$app->loadClass('requests', true);
include 'rest.php';
$rest = new Rest($config->webSite . '/api.php/v1');
/* Set configs. */
$config->zendataRoot = dirname(dirname(__FILE__)) . '/zendata';
@@ -83,7 +107,7 @@ function p($key, $delimiter = ',')
$result = trim($result, $delimiter);
}
echo $result . "\n\n";
echo $result . "\n";
return true;
}
+119
View File
@@ -0,0 +1,119 @@
<?php
/**
* The rest class.
*
* @package test
*/
class rest
{
/**
* The base url of request.
*
* @var string
* @access public
*/
public $base;
/**
* Construct.
*
* @param string $base
* @access public
* @return void
*/
public function __construct($base)
{
$this->base = $base;
}
/**
* Get method.
*
* @param string $url
* @param array $headers
* @access public
* @return object
*/
public function get($url, $headers = array())
{
$headers['Accept'] = 'application/json';
$resp = requests::get($this->base . $url, $headers, array());
try
{
$resp->body = json_decode($resp->body);
}
catch(Exception $e)
{
}
return $resp;
}
/**
* Post method.
*
* @param string $url
* @param array $data
* @param array $headers
* @access public
* @return object
*/
public function post($url, $data = array(), $headers = array())
{
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = 'application/json';
$data = json_encode($data);
$resp = requests::post($this->base . $url, $headers, $data, array());
try
{
$resp->body = json_decode($resp->body);
}
catch(Exception $e)
{
}
return $resp;
}
/**
* Put method.
*
* @param string $url
* @param array $data
* @param array $headers
* @access public
* @return object
*/
public function put($url, $data = array(), $headers = array())
{
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = 'application/json';
$resp = requests::put($this->base . $url, $headers, $data, $options);
try
{
$resp->body = json_decode($resp->body);
}
catch(Exception $e)
{
}
return $resp;
}
/**
* Delete method.
*
* @param string $url
* @param array $headers
* @param array $options
* @access public
* @return object
*/
public function delete($url, $headers = array())
{
$headers['Accept'] = 'application/json';
return requests::delete($this->base . $url, $headers, array());
}
}
+1 -1
View File
@@ -23,4 +23,4 @@ r($user->getByID('account1')) && p('account') && e('account1'); //
r($user->getByID(1)) && p('account') && e(''); // 通过默认字段获取不存在的用户
r($user->getByID(100000, 'id')) && p('account') && e(''); // 通过id字段获取不存在的用户
r($user->getByID('error', 'account')) && p('account') && e(''); // 通过默认字段获取不存在的用户
*/
*/
+1 -1
View File
@@ -10,10 +10,10 @@ switch($argv[1])
zdRun();
break;
case 'extract':
ztfExtract('api');
ztfExtract('model');
break;
case 'api':
ztfExtract('api');
ztfRun('api');
break;
case 'control':