diff options
Diffstat (limited to 'app/Model')
| -rw-r--r-- | app/Model/Acl.php | 1 | ||||
| -rw-r--r-- | app/Model/Notification.php | 36 | ||||
| -rw-r--r-- | app/Model/ProjectDuplication.php | 4 | ||||
| -rw-r--r-- | app/Model/SubTask.php | 32 | ||||
| -rw-r--r-- | app/Model/SubtaskTimeTracking.php | 80 |
5 files changed, 138 insertions, 15 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php index d1757a85..56f2980b 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -64,6 +64,7 @@ class Acl extends Base * @var array */ private $admin_acl = array( + 'app' => array('dashboard'), 'user' => array('index', 'create', 'save', 'remove'), 'config' => '*', 'project' => array('remove'), diff --git a/app/Model/Notification.php b/app/Model/Notification.php index 95306e86..49691f85 100644 --- a/app/Model/Notification.php +++ b/app/Model/Notification.php @@ -119,6 +119,18 @@ class Notification extends Base } /** + * Get the mail subject for a given label + * + * @access private + * @param string $label Label + * @param array $data Template data + */ + private function getStandardMailSubject($label, array $data) + { + return e('[%s][%s] %s (#%d)', $data['task']['project_name'], $label, $data['task']['title'], $data['task']['id']); + } + + /** * Get the mail subject for a given template name * * @access public @@ -129,40 +141,40 @@ class Notification extends Base { switch ($template) { case 'file_creation': - $subject = e('[%s][New attachment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('New attachment', $data); break; case 'comment_creation': - $subject = e('[%s][New comment] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('New comment', $data); break; case 'comment_update': - $subject = e('[%s][Comment updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Comment updated', $data); break; case 'subtask_creation': - $subject = e('[%s][New subtask] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('New subtask', $data); break; case 'subtask_update': - $subject = e('[%s][Subtask updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Subtask updated', $data); break; case 'task_creation': - $subject = e('[%s][New task] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('New task', $data); break; case 'task_update': - $subject = e('[%s][Task updated] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Task updated', $data); break; case 'task_close': - $subject = e('[%s][Task closed] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Task closed', $data); break; case 'task_open': - $subject = e('[%s][Task opened] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Task opened', $data); break; case 'task_move_column': - $subject = e('[%s][Column Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Column Change', $data); break; case 'task_move_position': - $subject = e('[%s][Position Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Position Change', $data); break; case 'task_assignee_change': - $subject = e('[%s][Assignee Change] %s (#%d)', $data['task']['project_name'], $data['task']['title'], $data['task']['id']); + $subject = $this->getStandardMailSubject('Assignee Change', $data); break; case 'task_due': $subject = e('[%s][Due tasks]', $data['project']); diff --git a/app/Model/ProjectDuplication.php b/app/Model/ProjectDuplication.php index 5adc1b4c..b93cbee5 100644 --- a/app/Model/ProjectDuplication.php +++ b/app/Model/ProjectDuplication.php @@ -23,8 +23,8 @@ class ProjectDuplication extends Base { $suffix = ' ('.t('Clone').')'; - if (strlen($name.$suffix) > 50) { - $name = substr($name, 0, 50 - strlen($suffix)); + if (strlen($name.$suffix) > $max_length) { + $name = substr($name, 0, $max_length - strlen($suffix)); } return $name.$suffix; diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php index 3fccad47..dd243b1f 100644 --- a/app/Model/SubTask.php +++ b/app/Model/SubTask.php @@ -223,13 +223,43 @@ class SubTask extends Base $values = array( 'id' => $subtask['id'], 'status' => ($subtask['status'] + 1) % 3, - 'task_id' => $subtask['task_id'], ); return $this->update($values); } /** + * Get the subtask in progress for this user + * + * @access public + * @param integer $user_id + * @return array + */ + public function getSubtaskInProgress($user_id) + { + return $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->findOne(); + } + + /** + * Return true if the user have a subtask in progress + * + * @access public + * @param integer $user_id + * @return boolean + */ + public function hasSubtaskInProgress($user_id) + { + return $this->config->get('subtask_restriction') == 1 && + $this->db->table(self::TABLE) + ->eq('status', self::STATUS_INPROGRESS) + ->eq('user_id', $user_id) + ->count() === 1; + } + + /** * Remove * * @access public diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php new file mode 100644 index 00000000..5c8a7c81 --- /dev/null +++ b/app/Model/SubtaskTimeTracking.php @@ -0,0 +1,80 @@ +<?php + +namespace Model; + +/** + * Subtask timesheet + * + * @package model + * @author Frederic Guillot + */ +class SubtaskTimeTracking extends Base +{ + /** + * SQL table name + * + * @var string + */ + const TABLE = 'subtask_time_tracking'; + + /** + * Get query for user timesheet (pagination) + * + * @access public + * @param integer $user_id User id + * @return \PicoDb\Table + */ + public function getUserQuery($user_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.subtask_id', + self::TABLE.'.end', + self::TABLE.'.start', + SubTask::TABLE.'.task_id', + SubTask::TABLE.'.title AS subtask_title', + Task::TABLE.'.title AS task_title', + Task::TABLE.'.project_id' + ) + ->join(SubTask::TABLE, 'id', 'subtask_id') + ->join(Task::TABLE, 'id', 'task_id', SubTask::TABLE) + ->eq(self::TABLE.'.user_id', $user_id); + } + + /** + * Log start time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logStartTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time())); + } + + /** + * Log end time + * + * @access public + * @param integer $subtask_id + * @param integer $user_id + * @return boolean + */ + public function logEndTime($subtask_id, $user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('subtask_id', $subtask_id) + ->eq('user_id', $user_id) + ->eq('end', 0) + ->update(array( + 'end' => time() + )); + } +} |
