diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-09-20 22:18:56 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-09-20 22:18:56 -0400 |
commit | 689687dd4ee186cb9cf5d0230b4648e242c53b10 (patch) | |
tree | 3d26bc2079c6eb45790ba604b3a79997be4768ab /app/Model | |
parent | f579663adcbc0b202d9a068d734e8f9284dc3a37 (diff) |
Add formatters
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Base.php | 20 | ||||
-rw-r--r-- | app/Model/Project.php | 48 | ||||
-rw-r--r-- | app/Model/TaskFilter.php | 224 |
3 files changed, 1 insertions, 291 deletions
diff --git a/app/Model/Base.php b/app/Model/Base.php index 3ee60844..a15f071c 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -121,26 +121,6 @@ abstract class Base extends \Core\Base } /** - * Get common properties for task calendar events - * - * @access protected - * @param array $task - * @return array - */ - protected function getTaskCalendarProperties(array &$task) - { - return array( - 'timezoneParam' => $this->config->getCurrentTimezone(), - 'id' => $task['id'], - 'title' => t('#%d', $task['id']).' '.$task['title'], - 'backgroundColor' => $this->color->getBackgroundColor($task['color_id']), - 'borderColor' => $this->color->getBorderColor($task['color_id']), - 'textColor' => 'black', - 'url' => $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), - ); - } - - /** * Group a collection of records by a column * * @access public diff --git a/app/Model/Project.php b/app/Model/Project.php index 8ddcc443..1bd5b624 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -115,54 +115,6 @@ 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 diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index 89ad9aa4..95fb293e 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -2,11 +2,6 @@ namespace Model; -use DateTime; -use Eluceo\iCal\Component\Calendar; -use Eluceo\iCal\Component\Event; -use Eluceo\iCal\Property\Event\Attendees; - /** * Task Filter * @@ -137,7 +132,7 @@ class TaskFilter extends Base */ public function copy() { - $filter = clone($this); + $filter = new static($this->container); $filter->query = clone($this->query); $filter->query->condition = clone($this->query->condition); return $filter; @@ -675,223 +670,6 @@ 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( - 'type' => 'task', - '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_name'], - '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 - * @return array - */ - public function toAutoCompletion() - { - return $this->query->columns(Task::TABLE.'.id', Task::TABLE.'.title')->callback(function(array $results) { - - foreach ($results as &$result) { - $result['value'] = $result['title']; - $result['label'] = '#'.$result['id'].' - '.$result['title']; - } - - return $results; - - })->findAll(); - } - - /** - * Transform results to calendar events - * - * @access public - * @param string $start_column Column name for the start date - * @param string $end_column Column name for the end date - * @return array - */ - public function toDateTimeCalendarEvents($start_column, $end_column) - { - $events = array(); - - foreach ($this->query->findAll() as $task) { - - $events[] = array_merge( - $this->getTaskCalendarProperties($task), - array( - 'start' => date('Y-m-d\TH:i:s', $task[$start_column]), - 'end' => date('Y-m-d\TH:i:s', $task[$end_column] ?: time()), - 'editable' => false, - ) - ); - } - - return $events; - } - - /** - * Transform results to all day calendar events - * - * @access public - * @param string $column Column name for the date - * @return array - */ - public function toAllDayCalendarEvents($column = 'date_due') - { - $events = array(); - - foreach ($this->query->findAll() as $task) { - - $events[] = array_merge( - $this->getTaskCalendarProperties($task), - array( - 'start' => date('Y-m-d', $task[$column]), - 'end' => date('Y-m-d', $task[$column]), - 'allday' => true, - ) - ); - } - - return $events; - } - - /** - * Transform results to ical events - * - * @access public - * @param string $start_column Column name for the start date - * @param string $end_column Column name for the end date - * @param Calendar $vCalendar Calendar object - * @return Calendar - */ - public function addDateTimeIcalEvents($start_column, $end_column, Calendar $vCalendar = null) - { - if ($vCalendar === null) { - $vCalendar = new Calendar('Kanboard'); - } - - foreach ($this->query->findAll() as $task) { - - $start = new DateTime; - $start->setTimestamp($task[$start_column]); - - $end = new DateTime; - $end->setTimestamp($task[$end_column] ?: time()); - - $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$start_column.'-'.$end_column); - $vEvent->setDtStart($start); - $vEvent->setDtEnd($end); - - $vCalendar->addComponent($vEvent); - } - - return $vCalendar; - } - - /** - * Transform results to all day ical events - * - * @access public - * @param string $column Column name for the date - * @param Calendar $vCalendar Calendar object - * @return Calendar - */ - public function addAllDayIcalEvents($column = 'date_due', Calendar $vCalendar = null) - { - if ($vCalendar === null) { - $vCalendar = new Calendar('Kanboard'); - } - - foreach ($this->query->findAll() as $task) { - - $date = new DateTime; - $date->setTimestamp($task[$column]); - - $vEvent = $this->getTaskIcalEvent($task, 'task-#'.$task['id'].'-'.$column); - $vEvent->setDtStart($date); - $vEvent->setDtEnd($date); - $vEvent->setNoTime(true); - - $vCalendar->addComponent($vEvent); - } - - return $vCalendar; - } - - /** - * Get common events for task ical events - * - * @access protected - * @param array $task - * @param string $uid - * @return Event - */ - protected function getTaskIcalEvent(array &$task, $uid) - { - $dateCreation = new DateTime; - $dateCreation->setTimestamp($task['date_creation']); - - $dateModif = new DateTime; - $dateModif->setTimestamp($task['date_modification']); - - $vEvent = new Event($uid); - $vEvent->setCreated($dateCreation); - $vEvent->setModified($dateModif); - $vEvent->setUseTimezone(true); - $vEvent->setSummary(t('#%d', $task['id']).' '.$task['title']); - $vEvent->setUrl($this->helper->url->base().$this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - - if (! empty($task['owner_id'])) { - $vEvent->setOrganizer($task['assignee_name'] ?: $task['assignee_username'], $task['assignee_email']); - } - - if (! empty($task['creator_id'])) { - $attendees = new Attendees; - $attendees->add('MAILTO:'.($task['creator_email'] ?: $task['creator_username'].'@kanboard.local')); - $vEvent->setAttendees($attendees); - } - - return $vEvent; - } - - /** * Filter with an operator * * @access public |