diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Acl.php | 1 | ||||
-rw-r--r-- | app/Model/Task.php | 35 | ||||
-rw-r--r-- | app/Model/TaskCreation.php | 9 | ||||
-rw-r--r-- | app/Model/TaskFilter.php | 76 |
4 files changed, 116 insertions, 5 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 0840f44c..312ae7d4 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -65,6 +65,7 @@ class Acl extends Base 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', 'budget' => '*', + 'gantt' => '*', ); /** diff --git a/app/Model/Task.php b/app/Model/Task.php index 71d973a4..ae8fc7a8 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -121,7 +121,7 @@ class Task extends Base */ public function getRecurrenceStatusList() { - return array ( + return array( Task::RECURRING_STATUS_NONE => t('No'), Task::RECURRING_STATUS_PENDING => t('Yes'), ); @@ -135,7 +135,7 @@ class Task extends Base */ public function getRecurrenceTriggerList() { - return array ( + return array( Task::RECURRING_TRIGGER_FIRST_COLUMN => t('When task is moved from first column'), Task::RECURRING_TRIGGER_LAST_COLUMN => t('When task is moved to last column'), Task::RECURRING_TRIGGER_CLOSE => t('When task is closed'), @@ -150,7 +150,7 @@ class Task extends Base */ public function getRecurrenceBasedateList() { - return array ( + return array( Task::RECURRING_BASEDATE_DUEDATE => t('Existing due date'), Task::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'), ); @@ -164,10 +164,37 @@ class Task extends Base */ public function getRecurrenceTimeframeList() { - return array ( + return array( Task::RECURRING_TIMEFRAME_DAYS => t('Day(s)'), Task::RECURRING_TIMEFRAME_MONTHS => t('Month(s)'), Task::RECURRING_TIMEFRAME_YEARS => t('Year(s)'), ); } + + /** + * Get task progress based on the column position + * + * @access public + * @param array $task + * @param array $columns + * @return integer + */ + public function getProgress(array $task, array $columns) + { + if ($task['is_active'] == self::STATUS_CLOSED) { + return 100; + } + + $position = 0; + + foreach ($columns as $column_id => $column_title) { + if ($column_id == $task['column_id']) { + break; + } + + $position++; + } + + return (int) ($position * 100) / count($columns); + } } diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php index e530da13..4373fa63 100644 --- a/app/Model/TaskCreation.php +++ b/app/Model/TaskCreation.php @@ -25,10 +25,17 @@ class TaskCreation extends Base return 0; } + $position = empty($values['position']) ? 0 : $values['position']; + $this->prepare($values); $task_id = $this->persist(Task::TABLE, $values); if ($task_id !== false) { + + if ($position > 0 && $values['position'] > 1) { + $this->taskPosition->movePosition($values['project_id'], $task_id, $values['column_id'], $position, $values['swimlane_id'], false); + } + $this->fireEvents($task_id, $values); } @@ -46,7 +53,7 @@ class TaskCreation extends Base $this->dateParser->convert($values, array('date_due')); $this->dateParser->convert($values, array('date_started'), true); $this->removeFields($values, array('another_task')); - $this->resetFields($values, array('creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated')); + $this->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated')); if (empty($values['column_id'])) { $values['column_id'] = $this->board->getFirstColumn($values['project_id']); diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index 956ffbe8..8da4a214 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -87,6 +87,38 @@ class TaskFilter extends Base } /** + * Prepare filter for Gantt chart + * + * @access public + * @return TaskFilter + */ + public function gantt() + { + $this->query = $this->db->table(Task::TABLE); + $this->query->join(Board::TABLE, 'id', 'column_id', Task::TABLE); + $this->query->join(User::TABLE, 'id', 'owner_id', Task::TABLE); + + $this->query->columns( + Task::TABLE.'.id', + Task::TABLE.'.title', + Task::TABLE.'.project_id', + Task::TABLE.'.column_id', + Task::TABLE.'.color_id', + Task::TABLE.'.date_started', + Task::TABLE.'.date_due', + Task::TABLE.'.date_creation', + Task::TABLE.'.is_active', + Task::TABLE.'.position', + Board::TABLE.'.position AS column_position', + Board::TABLE.'.title AS column_title', + User::TABLE.'.name AS assignee_name', + User::TABLE.'.username AS assignee_username' + ); + + return $this; + } + + /** * Create a new query * * @access public @@ -675,6 +707,50 @@ class TaskFilter extends Base } /** + * Format tasks to be displayed in the Gantt chart + * + * @access public + * @return array + */ + public function toGanttBars() + { + $bars = array(); + $columns = array(); + + foreach ($this->query->findAll() as $task) { + if (! isset($column_count[$task['project_id']])) { + $columns[$task['project_id']] = $this->board->getColumnsList($task['project_id']); + } + + $start = $task['date_started'] ?: time(); + $end = $task['date_due'] ?: $start; + + $bars[] = array( + 'id' => $task['id'], + 'title' => $task['title'], + '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), + ), + 'column_title' => $task['column_title'], + 'assignee' => $task['assignee_name'] ?: $task['assignee_username'], + 'progress' => $this->task->getProgress($task, $columns[$task['project_id']]).'%', + 'link' => $this->helper->url->href('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), + 'color' => $this->color->getColorProperties($task['color_id']), + 'not_defined' => empty($task['date_due']) || empty($task['date_started']), + ); + } + + return $bars; + } + + /** * Format the results to the ajax autocompletion * * @access public |