From 928149db30c1e820c89afe75a66192784106a1d2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 26 Apr 2022 14:50:30 +0800 Subject: [PATCH 1/2] * Feedback api. --- api/v1/entries/feedbacks.php | 125 +++++++++++++++++++++++++++++++++++ config/routes.php | 2 + 2 files changed, 127 insertions(+) create mode 100644 api/v1/entries/feedbacks.php diff --git a/api/v1/entries/feedbacks.php b/api/v1/entries/feedbacks.php new file mode 100644 index 0000000000..536ebf27bb --- /dev/null +++ b/api/v1/entries/feedbacks.php @@ -0,0 +1,125 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class feedbacksEntry extends entry +{ + /** + * GET method. + * + * @param int $projectID + * @access public + * @return void + */ + public function get() + { + a('yes');die; + $control = $this->loadController('feedback', 'admin'); + $control->admin(); + $data = $this->getData(); + a($data);die; + + if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + + $executions = $data->data->executionStats; + $pager = $data->data->pager; + $projects = $data->data->projects; + + $data = array(); + $data['page'] = $pager->pageID; + $data['total'] = $pager->recTotal; + $data['limit'] = $pager->recPerPage; + $data['executions'] = $result; + if(!empty($withProject)) $data['projects'] = $projects; + + return $this->send(200, $data); + } + + /** + * POST method. + * + * @param int $projectID + * @access public + * @return void + */ + public function post($projectID = 0) + { + $fields = 'project,code,name,begin,end,lifetime,desc,days'; + $this->batchSetPost($fields); + + $projectID = $this->param('project', $projectID); + $this->setPost('project', $projectID); + $this->setPost('acl', $this->request('acl', 'private')); + $this->setPost('PO', $this->request('PO', '')); + $this->setPost('PM', $this->request('PM', '')); + $this->setPost('QD', $this->request('QD', '')); + $this->setPost('RD', $this->request('RD', '')); + $this->setPost('whitelist', $this->request('whitelist', array())); + $this->setPost('products', $this->request('products', array())); + $this->setPost('plans', $this->request('plans', array())); + + $control = $this->loadController('execution', 'create'); $this->requireFields('name,code,begin,end,days'); + $control->create($projectID); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + + $execution = $this->loadModel('execution')->getByID($data->id); + + $this->send(201, $this->format($execution, 'openedBy:user,openedDate:time,lastEditedBy:user,lastEditedDate:time,closedBy:user,closedDate:time,canceledBy:user,canceledDate:time,PM:user,PO:user,RD:user,QD:user,whitelist:userList,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool')); + } + + /** + * Get drop menu. + * + * @access public + * @return void + */ + public function getDropMenu() + { + $control = $this->loadController('execution', 'ajaxGetDropMenu'); + $control->ajaxGetDropMenu($this->request('executionID', 0), $this->request('module', 'execution'), $this->request('method', 'task'), $this->request('extra', '')); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + + $account = $this->app->user->account; + $projects = $data->data->projects; + $dropMenu = array('involved' => array(), 'other' => array(), 'closed' => array()); + foreach($data->data->executions as $projectID => $projectExecutions) + { + foreach($projectExecutions as $execution) + { + if(helper::diffDate(date('Y-m-d'), $execution->end) > 0) $execution->delay = true; + $teams = $execution->teams; + $execution = $this->filterFields($execution, 'id,project,model,type,name,code,status,PM,delay'); + + $projectName = zget($projects, $execution->project, ''); + if($projectName) $execution->name = $projectName . '/' . $execution->name; + + if($execution->status == 'closed') + { + $dropMenu['closed'][] = $execution; + } + elseif($execution->status != 'done' and $execution->status != 'closed' and ($execution->PM == $account or isset($teams->$account))) + { + $dropMenu['involved'][] = $execution; + } + else + { + $dropMenu['other'][] = $execution; + } + } + } + + $this->send(200, $dropMenu); + } +} diff --git a/config/routes.php b/config/routes.php index 23156d702d..bad7129397 100644 --- a/config/routes.php +++ b/config/routes.php @@ -16,6 +16,8 @@ $routes['/tabs/:module'] = 'tabs'; $routes['/files'] = 'files'; $routes['/files/:id'] = 'file'; +$routes['/feedbacks'] = 'feedbacks'; + $routes['/options/:type'] = 'options'; $routes['/configurations'] = 'configs'; From 2fe95ae6598930f70c9d734ddcb6d9267d8bfe57 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 26 Apr 2022 15:06:22 +0800 Subject: [PATCH 2/2] * Feedback api. --- api/v1/entries/feedbacks.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/api/v1/entries/feedbacks.php b/api/v1/entries/feedbacks.php index 536ebf27bb..1eeb8c2636 100644 --- a/api/v1/entries/feedbacks.php +++ b/api/v1/entries/feedbacks.php @@ -20,25 +20,27 @@ class feedbacksEntry extends entry */ public function get() { - a('yes');die; $control = $this->loadController('feedback', 'admin'); - $control->admin(); + $control->admin($this->param('status', 'unclosed'), 0, $this->param('orderBy', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); $data = $this->getData(); - a($data);die; if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - $executions = $data->data->executionStats; - $pager = $data->data->pager; - $projects = $data->data->projects; + $feedbacks = $data->data->feedbacks; + $pager = $data->data->pager; + + $result = array(); + foreach($feedbacks as $feedback) + { + $result[] = $this->format($feedback, 'openedBy:user,openedDate:time,reviewedBy:user,reviewedDate:time,processedBy:user,processedDate:time,closedBy:user,closedDate:time,editedBy:user,editedDate:time,mailto:userList,deleted:bool'); + } $data = array(); - $data['page'] = $pager->pageID; - $data['total'] = $pager->recTotal; - $data['limit'] = $pager->recPerPage; - $data['executions'] = $result; - if(!empty($withProject)) $data['projects'] = $projects; + $data['page'] = $pager->pageID; + $data['total'] = $pager->recTotal; + $data['limit'] = $pager->recPerPage; + $data['feedbacks'] = $result; return $this->send(200, $data); }