diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Acl.php | 14 | ||||
-rw-r--r-- | app/Model/SubTask.php | 6 | ||||
-rw-r--r-- | app/Model/SubtaskExport.php | 119 |
3 files changed, 127 insertions, 12 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 9c3f5e06..599ff055 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -50,7 +50,8 @@ class Acl extends Base 'analytic' => '*', 'board' => array('movecolumn', 'edit', 'update', 'add', 'remove'), 'category' => '*', - 'project' => array('edit', 'update', 'exporttasks', 'exportdailyprojectsummary', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), + 'export' => array('tasks', 'subtasks', 'summary'), + 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', ); @@ -179,7 +180,7 @@ class Acl extends Base // Check project member permissions if ($this->isMemberAction($controller, $action)) { - return $this->isMemberActionAllowed($project_id); + return $project_id > 0 && $this->projectPermission->isMember($project_id, $this->userSession->getId()); } // Other applications actions are allowed @@ -188,11 +189,10 @@ class Acl extends Base public function isManagerActionAllowed($project_id) { - return $project_id > 0 && $this->projectPermission->isManager($project_id, $this->userSession->getId()); - } + if ($this->userSession->isAdmin()) { + return true; + } - public function isMemberActionAllowed($project_id) - { - return $project_id > 0 && $this->projectPermission->isMember($project_id, $this->userSession->getId()); + return $project_id > 0 && $this->projectPermission->isManager($project_id, $this->userSession->getId()); } } diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php index adc5aa73..1c5d1bf0 100644 --- a/app/Model/SubTask.php +++ b/app/Model/SubTask.php @@ -58,15 +58,11 @@ class SubTask extends Base */ public function getStatusList() { - $status = array( + return array( self::STATUS_TODO => t('Todo'), self::STATUS_INPROGRESS => t('In progress'), self::STATUS_DONE => t('Done'), ); - - asort($status); - - return $status; } /** diff --git a/app/Model/SubtaskExport.php b/app/Model/SubtaskExport.php new file mode 100644 index 00000000..50b028e2 --- /dev/null +++ b/app/Model/SubtaskExport.php @@ -0,0 +1,119 @@ +<?php + +namespace Model; + +/** + * Subtask Export + * + * @package model + * @author Frederic Guillot + */ +class SubtaskExport extends Base +{ + /** + * Subtask statuses + * + * @access private + * @var array + */ + private $subtask_status = array(); + + /** + * Fetch subtasks and return the prepared CSV + * + * @access public + * @param integer $project_id Project id + * @param mixed $from Start date (timestamp or user formatted date) + * @param mixed $to End date (timestamp or user formatted date) + * @return array + */ + public function export($project_id, $from, $to) + { + $this->subtask_status = $this->subTask->getStatusList(); + $subtasks = $this->getSubtasks($project_id, $from, $to); + $results = array($this->getColumns()); + + foreach ($subtasks as $subtask) { + $results[] = $this->format($subtask); + } + + return $results; + } + + /** + * Get column titles + * + * @access public + * @return string[] + */ + public function getColumns() + { + return array( + e('Subtask Id'), + e('Title'), + e('Status'), + e('Assignee'), + e('Time estimated'), + e('Time spent'), + e('Task Id'), + e('Task Title'), + ); + } + + /** + * Format the output of a subtask array + * + * @access public + * @param array $subtask Subtask properties + * @return array + */ + public function format(array $subtask) + { + $values = array(); + $values[] = $subtask['id']; + $values[] = $subtask['title']; + $values[] = $this->subtask_status[$subtask['status']]; + $values[] = $subtask['assignee_name'] ?: $subtask['assignee_username']; + $values[] = $subtask['time_estimated']; + $values[] = $subtask['time_spent']; + $values[] = $subtask['task_id']; + $values[] = $subtask['task_title']; + + return $values; + } + + /** + * Get all subtasks for a given project + * + * @access public + * @param integer $task_id Task id + * @param mixed $from Start date (timestamp or user formatted date) + * @param mixed $to End date (timestamp or user formatted date) + * @return array + */ + public function getSubtasks($project_id, $from, $to) + { + if (! is_numeric($from)) { + $from = $this->dateParser->resetDateToMidnight($this->dateParser->getTimestamp($from)); + } + + if (! is_numeric($to)) { + $to = $this->dateParser->resetDateToMidnight(strtotime('+1 day', $this->dateParser->getTimestamp($to))); + } + + return $this->db->table(SubTask::TABLE) + ->eq('project_id', $project_id) + ->columns( + SubTask::TABLE.'.*', + User::TABLE.'.username AS assignee_username', + User::TABLE.'.name AS assignee_name', + Task::TABLE.'.title AS task_title' + ) + ->gte('date_creation', $from) + ->lte('date_creation', $to) + ->join(Task::TABLE, 'id', 'task_id') + ->join(User::TABLE, 'id', 'user_id') + ->asc(SubTask::TABLE.'.id') + ->findAll(); + } +} |