Add per-project and per-swimlane task limits

This change allows projects and swimlanes to be configured with task limits that apply to their whole scope (i.e. all active tasks in a project or swimlane, respectively), as opposed to the usual per-column task limits.
This commit is contained in:
Andre Nathan
2020-02-26 01:26:31 -03:00
committed by GitHub
parent 542fd17891
commit c8a617cfcb
21 changed files with 161 additions and 27 deletions

View File

@@ -160,6 +160,7 @@ class ProjectDuplicationModel extends Base
'priority_start' => $project['priority_start'],
'priority_end' => $project['priority_end'],
'per_swimlane_task_limits' => empty($project['per_swimlane_task_limits']) ? 0 : 1,
'task_limit' => $project['task_limit'],
'identifier' => $identifier,
);

View File

@@ -79,6 +79,24 @@ class ProjectModel extends Base
->findOne();
}
/**
* Get a project by id with owner name and task count
*
* @access public
* @param integer $project_id Project id
* @return array
*/
public function getByIdWithOwnerAndTaskCount($project_id)
{
return $this->db->table(self::TABLE)
->columns(self::TABLE.'.*', UserModel::TABLE.'.username AS owner_username', UserModel::TABLE.'.name AS owner_name', 'SUM(CAST('.TaskModel::TABLE.'.is_active AS INTEGER)) AS nb_active_tasks')
->eq(self::TABLE.'.id', $project_id)
->join(UserModel::TABLE, 'id', 'owner_id')
->join(TaskModel::TABLE, 'project_id', 'id')
->groupBy(self::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name')
->findOne();
}
/**
* Get a project by the name
*
@@ -372,7 +390,7 @@ class ProjectModel extends Base
$values['identifier'] = strtoupper($values['identifier']);
}
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end', 'task_limit'));
if (! $this->db->table(self::TABLE)->save($values)) {
$this->db->cancelTransaction();
@@ -459,7 +477,7 @@ class ProjectModel extends Base
$values['per_swimlane_task_limits'] = empty($values['per_swimlane_task_limits']) ? 0 : 1;
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end'));
$this->helper->model->convertIntegerFields($values, array('priority_default', 'priority_start', 'priority_end', 'task_limit'));
return $this->exists($values['id']) &&
$this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
@@ -568,4 +586,19 @@ class ProjectModel extends Base
->eq('id', $project_id)
->save(array('is_public' => 0, 'token' => ''));
}
/**
* Return the task count for a project
*
* @access public
* @param integer $project_id Project id
* @return integer
*/
public function taskCount($project_id)
{
return $this->db->table(self::TABLE)
->eq('id', $project_id)->exists()
->join(ColumnModel::TABLE, 'id', 'project_id')
->count();
}
}

View File

@@ -178,7 +178,7 @@ class SwimlaneModel extends Base
);
$swimlanes = $this->db->table(self::TABLE)
->columns('id', 'name', 'description', 'project_id', 'position', 'is_active')
->columns('id', 'name', 'description', 'project_id', 'position', 'is_active', 'task_limit')
->subquery("SELECT COUNT(*) FROM ".TaskModel::TABLE." WHERE swimlane_id=".self::TABLE.".id AND is_active='1'", 'nb_open_tasks')
->subquery("SELECT COUNT(*) FROM ".TaskModel::TABLE." WHERE swimlane_id=".self::TABLE.".id AND is_active='0'", 'nb_closed_tasks')
->eq('project_id', $project_id)
@@ -231,7 +231,7 @@ class SwimlaneModel extends Base
* @param string $description
* @return bool|int
*/
public function create($projectId, $name, $description = '')
public function create($projectId, $name, $description = '', $task_limit = 0)
{
if (! $this->projectModel->exists($projectId)) {
return 0;
@@ -243,6 +243,7 @@ class SwimlaneModel extends Base
'description' => $description,
'position' => $this->getLastPosition($projectId),
'is_active' => 1,
'task_limit' => $task_limit,
));
}