From 6491d70c06aaa3655a4dfa5a010841cebbdd6189 Mon Sep 17 00:00:00 2001 From: Wenrui LI Date: Wed, 7 Dec 2022 09:43:50 +0800 Subject: [PATCH] * move task get list by search into task model, and add to api. --- api/v1/entries/tasks.php | 22 +++++++++++- module/task/model.php | 34 +++++++++++++++++++ .../extension/xuan/im/ext/bot/zentao.bot.php | 4 +-- .../xuan/task/ext/model/xuanxuan.php | 30 ---------------- 4 files changed, 57 insertions(+), 33 deletions(-) delete mode 100644 xuanxuan/extension/xuan/task/ext/model/xuanxuan.php diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php index 63ed468957..1fb8282ae9 100644 --- a/api/v1/entries/tasks.php +++ b/api/v1/entries/tasks.php @@ -20,7 +20,27 @@ class tasksEntry extends entry */ public function get($executionID = 0) { - if(!$executionID) + /* Get tasks by search, search arguments available: pri, assignedTo, status, id, name. Pager arguments will be utilized as well. */ + if($this->param('search', 0) == 1) + { + $this->loadModel('task'); + $searchParams = array(); + foreach(array('pri' => 'priList', 'assignedTo' => 'assignedToList', 'status' => 'statusList', 'id' => 'idList', 'name' => 'taskName') as $field => $condName) + { + if($this->param($field, false)) $searchParams[$condName] = $this->param($field); + } + + $this->app->loadClass('pager', $static = true); + $pager = pager::init($this->param('total', 0), $this->param('limit', 20), $this->param('page', 1)); + $tasks = $this->task->getListByConds((object)$searchParams, $this->param('order', 'id_desc'), $pager); + + $data = new stdclass(); + $data->status = 'success'; + $data->data = new stdclass(); + $data->data->tasks = array_values($tasks); + $data->data->pager = (object)$pager; + } + elseif(!$executionID) { /* Get my tasks defaultly. */ $control = $this->loadController('my', 'task'); diff --git a/module/task/model.php b/module/task/model.php index dd57730843..84cba6af2a 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -4339,4 +4339,38 @@ class taskModel extends model $order ++; } } + + /** + * Get task list by conditions. + * + * @param object $conds + * @param string $orderBy + * @param object $pager + * @access public + * @return array + */ + public function getListByConds($conds, $orderBy = 'id_desc', $pager = null) + { + foreach(array('priList' => array(), 'assignedToList' => array(), 'statusList' => array(), 'idList' => array(), 'taskName' => '') as $condKey => $defaultValue) + { + if(!isset($conds->$condKey)) + { + $conds->$condKey = $defaultValue; + continue; + } + if(strripos($condKey, 'list') === strlen($condKey) - 4 && !is_array($conds->$condKey)) $conds->$condKey = array_filter(explode(',', $conds->$condKey)); + } + + return $this->dao->select('*')->from(TABLE_TASK) + ->where('deleted')->eq(0) + ->beginIF(!empty($conds->priList))->andWhere('pri')->in($conds->priList)->fi() + ->beginIF(!empty($conds->assignedToList))->andWhere('assignedTo')->in($conds->assignedToList)->fi() + ->beginIF(!empty($conds->statusList))->andWhere('status')->in($conds->statusList)->fi() + ->beginIF(!empty($conds->idList))->andWhere('id')->in($conds->idList)->fi() + ->beginIF(!empty($conds->taskName))->andWhere('name')->like("%{$conds->taskName}%") + ->beginIF(!$this->app->user->admin)->andWhere('execution')->in($this->app->user->view->sprints)->fi() + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } } diff --git a/xuanxuan/extension/xuan/im/ext/bot/zentao.bot.php b/xuanxuan/extension/xuan/im/ext/bot/zentao.bot.php index 940530236b..f3e03b74fa 100644 --- a/xuanxuan/extension/xuan/im/ext/bot/zentao.bot.php +++ b/xuanxuan/extension/xuan/im/ext/bot/zentao.bot.php @@ -353,7 +353,7 @@ class zentaoBot extends xuanBot $conds = new stdClass(); $conds->assignedToList = is_object($user) ? $user->account : false; $conds->statusList = 'wait,doing,done,pause,cancel'; - return $this->im->task->getListByConds($conds, 'status_asc', 0, $pager); + return $this->im->task->getListByConds($conds, 'status_asc', $pager); } $keys = array(); @@ -364,7 +364,7 @@ class zentaoBot extends xuanBot $keys['taskName'] = true; $conds = $this->parseArguments($args, $keys); - return $this->im->task->getListByConds($conds, 'status_asc', 0, $pager); + return $this->im->task->getListByConds($conds, 'status_asc', $pager); } /** diff --git a/xuanxuan/extension/xuan/task/ext/model/xuanxuan.php b/xuanxuan/extension/xuan/task/ext/model/xuanxuan.php deleted file mode 100644 index 9d2302186e..0000000000 --- a/xuanxuan/extension/xuan/task/ext/model/xuanxuan.php +++ /dev/null @@ -1,30 +0,0 @@ - array(), 'assignedToList' => array(), 'statusList' => array(), 'idList' => array(), 'taskName' => '') as $condKey => $defaultValue) - { - if(!isset($conds->$condKey)) $conds->$condKey = $defaultValue; - } - - return $this->dao->select('*')->from(TABLE_TASK) - ->where('deleted')->eq(0) - ->beginIF(!empty($conds->priList))->andWhere('pri')->in($conds->priList)->fi() - ->beginIF(!empty($conds->assignedToList))->andWhere('assignedTo')->in($conds->assignedToList)->fi() - ->beginIF(!empty($conds->statusList))->andWhere('status')->in($conds->statusList)->fi() - ->beginIF(!empty($conds->idList))->andWhere('id')->in($conds->idList)->fi() - ->beginIF(!empty($conds->taskName))->andWhere('name')->like("%{$conds->taskName}%") - ->orderBy($orderBy) - ->beginIF($limit > 0)->limit($limit)->fi() - ->page($pager) - ->fetchAll('id'); -}