* move task get list by search into task model, and add to api.
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Get task list by conditions.
|
||||
*
|
||||
* @param object $conds
|
||||
* @param string $orderBy
|
||||
* @param int $limit
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getListByConds($conds, $orderBy = 'id_desc', $limit = 0, $pager = null)
|
||||
{
|
||||
foreach(array('priList' => 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');
|
||||
}
|
||||
Reference in New Issue
Block a user