diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-08-22 16:20:53 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-08-22 16:20:53 -0400 |
commit | fd60964c239627d2d55c6eca0888be84a8f6653f (patch) | |
tree | 062836c4a49857625a25b2cfdd3bbb93732f915d /app/Model | |
parent | 18fd39e6d648a58be0782d514604877504833832 (diff) |
Add global Gantt chart for all projects
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Acl.php | 3 | ||||
-rw-r--r-- | app/Model/DateParser.php | 14 | ||||
-rw-r--r-- | app/Model/Project.php | 51 | ||||
-rw-r--r-- | app/Model/ProjectPermission.php | 41 | ||||
-rw-r--r-- | app/Model/TaskFilter.php | 1 |
5 files changed, 90 insertions, 20 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php index b1e9eb07..e93bf1d9 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -65,7 +65,7 @@ class Acl extends Base 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', 'budget' => '*', - 'gantt' => '*', + 'gantt' => array('project', 'savetaskdate', 'task', 'savetask'), ); /** @@ -77,6 +77,7 @@ class Acl extends Base private $project_admin_acl = array( 'project' => array('remove'), 'projectuser' => '*', + 'gantt' => array('projects', 'saveprojectdate'), ); /** diff --git a/app/Model/DateParser.php b/app/Model/DateParser.php index 036725e3..6e833061 100644 --- a/app/Model/DateParser.php +++ b/app/Model/DateParser.php @@ -77,7 +77,7 @@ class DateParser extends Base } /** - * Parse a date ad return a unix timestamp, try different date formats + * Parse a date and return a unix timestamp, try different date formats * * @access public * @param string $value Date to parse @@ -97,6 +97,18 @@ class DateParser extends Base } /** + * Get ISO8601 date from user input + * + * @access public + * @param string $value Date to parse + * @return string + */ + public function getIsoDate($value) + { + return date('Y-m-d', ctype_digit($value) ? $value : $this->getTimestamp($value)); + } + + /** * Get all combinations of date/time formats * * @access public diff --git a/app/Model/Project.php b/app/Model/Project.php index 161a0cae..52500820 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -115,6 +115,54 @@ class Project extends Base } /** + * Get all projects to generate the Gantt chart + * + * @access public + * @param array $project_ids + * @return array + */ + public function getGanttBars(array $project_ids) + { + if (empty($project_ids)) { + return array(); + } + + $colors = $this->color->getDefaultColors(); + $projects = $this->db->table(self::TABLE)->asc('start_date')->in('id', $project_ids)->eq('is_active', self::ACTIVE)->eq('is_private', 0)->findAll(); + $bars = array(); + + foreach ($projects as $project) { + $start = empty($project['start_date']) ? time() : strtotime($project['start_date']); + $end = empty($project['end_date']) ? $start : strtotime($project['end_date']); + $color = next($colors) ?: reset($colors); + + $bars[] = array( + 'type' => 'project', + 'id' => $project['id'], + 'title' => $project['name'], + 'start' => array( + (int) date('Y', $start), + (int) date('n', $start), + (int) date('j', $start), + ), + 'end' => array( + (int) date('Y', $end), + (int) date('n', $end), + (int) date('j', $end), + ), + 'link' => $this->helper->url->href('project', 'show', array('project_id' => $project['id'])), + 'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])), + 'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])), + 'color' => $color, + 'not_defined' => empty($project['start_date']) || empty($project['end_date']), + 'users' => $this->projectPermission->getProjectUsers($project['id']), + ); + } + + return $bars; + } + + /** * Get all projects * * @access public @@ -271,8 +319,7 @@ class Project extends Base { foreach ($projects as &$project) { $this->getColumnStats($project); - $project['managers'] = $this->projectPermission->getManagers($project['id']); - $project['members'] = $this->projectPermission->getOnlyMembers($project['id']); + $project = array_merge($project, $this->projectPermission->getProjectUsers($project['id'])); } return $projects; diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php index 03e9bea6..c412b7a9 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermission.php @@ -50,40 +50,49 @@ class ProjectPermission extends Base } /** - * Get a list of allowed people for a project + * Get a list of members and managers with a single SQL query * * @access public * @param integer $project_id Project id * @return array */ - public function getMembers($project_id) + public function getProjectUsers($project_id) { - if ($this->isEverybodyAllowed($project_id)) { - return $this->user->getList(); + $result = array( + 'managers' => array(), + 'members' => array(), + ); + + $users = $this->db + ->table(self::TABLE) + ->join(User::TABLE, 'id', 'user_id') + ->eq('project_id', $project_id) + ->asc('username') + ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', self::TABLE.'.is_owner') + ->findAll(); + + foreach ($users as $user) { + $key = $user['is_owner'] == 1 ? 'managers' : 'members'; + $result[$key][$user['id']] = $user['name'] ?: $user['username']; } - return $this->getAssociatedUsers($project_id); + return $result; } /** - * Get a list of standard user members for a project + * Get a list of allowed people for a project * * @access public * @param integer $project_id Project id * @return array */ - public function getOnlyMembers($project_id) + public function getMembers($project_id) { - $users = $this->db - ->table(self::TABLE) - ->join(User::TABLE, 'id', 'user_id') - ->eq('project_id', $project_id) - ->eq('is_owner', 0) - ->asc('username') - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name') - ->findAll(); + if ($this->isEverybodyAllowed($project_id)) { + return $this->user->getList(); + } - return $this->user->prepareList($users); + return $this->getAssociatedUsers($project_id); } /** diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index cede59e3..d72af68c 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -726,6 +726,7 @@ class TaskFilter extends Base $end = $task['date_due'] ?: $start; $bars[] = array( + 'type' => 'task', 'id' => $task['id'], 'title' => $task['title'], 'start' => array( |