diff --git a/app/Controller/Base.php b/app/Controller/Base.php index b21d9b8f1..5829fc36c 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -23,6 +23,7 @@ use Model\LastLogin; * @property \Model\Ldap $ldap * @property \Model\Project $project * @property \Model\RememberMe $rememberMe + * @property \Model\SubTask $subTask * @property \Model\Task $task * @property \Model\User $user */ diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php new file mode 100644 index 000000000..5ef193c83 --- /dev/null +++ b/app/Controller/Subtask.php @@ -0,0 +1,185 @@ +subTask->getById($this->request->getIntegerParam('subtask_id')); + + if (! $subtask) { + $this->notfound(); + } + + return $subtask; + } + + /** + * Creation form + * + * @access public + */ + public function create() + { + $task = $this->getTask(); + + $this->response->html($this->taskLayout('subtask_create', array( + 'values' => array( + 'task_id' => $task['id'], + ), + 'errors' => array(), + 'users_list' => $this->project->getUsersList($task['project_id']), + 'task' => $task, + 'menu' => 'tasks', + 'title' => t('Add a sub-task') + ))); + } + + /** + * Validation and creation + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->subTask->validate($values); + + if ($valid) { + + if ($this->subTask->create($values)) { + $this->session->flash(t('Sub-task added successfully.')); + } + else { + $this->session->flashError(t('Unable to create your sub-task.')); + } + + if (isset($values['another_subtask']) && $values['another_subtask'] == 1) { + $this->response->redirect('?controller=subtask&action=create&task_id='.$task['id']); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'#subtasks'); + } + + $this->response->html($this->taskLayout('subtask_create', array( + 'values' => $values, + 'errors' => $errors, + 'users_list' => $this->project->getUsersList($task['project_id']), + 'task' => $task, + 'menu' => 'tasks', + 'title' => t('Add a sub-task') + ))); + } + + /** + * Edit form + * + * @access public + */ + public function edit() + { + $task = $this->getTask(); + $subtask = $this->getSubTask(); + + $this->response->html($this->taskLayout('subtask_edit', array( + 'values' => $subtask, + 'errors' => array(), + 'users_list' => $this->project->getUsersList($task['project_id']), + 'status_list' => $this->subTask->getStatusList(), + 'subtask' => $subtask, + 'task' => $task, + 'menu' => 'tasks', + 'title' => t('Edit a sub-task') + ))); + } + + /** + * Update and validate a subtask + * + * @access public + */ + public function update() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->subTask->validate($values); + + if ($valid) { + + if ($this->subTask->update($values)) { + $this->session->flash(t('Sub-task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your sub-task.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'#subtasks'); + } + + $this->response->html($this->taskLayout('subtask_edit', array( + 'values' => $values, + 'errors' => $errors, + 'users_list' => $this->project->getUsersList($task['project_id']), + 'status_list' => $this->subTask->getStatusList(), + 'subtask' => $subtask, + 'task' => $task, + 'menu' => 'tasks', + 'title' => t('Edit a sub-task') + ))); + } + + /** + * Confirmation dialog before removing a subtask + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $this->response->html($this->taskLayout('subtask_remove', array( + 'subtask' => $subtask, + 'task' => $task, + 'menu' => 'tasks', + 'title' => t('Remove a sub-task') + ))); + } + + /** + * Remove a subtask + * + * @access public + */ + public function remove() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + if ($this->subTask->remove($subtask['id'])) { + $this->session->flash(t('Sub-task removed successfully.')); + } + else { + $this->session->flashError(t('Unable to remove this sub-task.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'#subtasks'); + } +} diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 8230eef3f..68e3728ac 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -62,6 +62,7 @@ class Task extends Base $this->response->html($this->taskLayout('task_show', array( 'files' => $this->file->getAll($task['id']), 'comments' => $this->comment->getAll($task['id']), + 'subtasks' => $this->subTask->getAll($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php index 909588530..b554b01d8 100644 --- a/app/Locales/de_DE/translations.php +++ b/app/Locales/de_DE/translations.php @@ -346,4 +346,29 @@ return array( // 'Add a comment' => '', // 'Edit a comment' => '', // 'Summary' => '', + // 'Time tracking' => '', + // 'Estimate:' => '', + // 'Spent:' => '', + // 'Do you really want to remove this sub-task?' => '', + // 'Remaining:' => '', + // 'hours' => '', + // 'spent' => '', + // 'estimated' => '', + // 'Sub-Tasks' => '', + // 'Add a sub-task' => '', + // 'Original Estimate' => '', + // 'Create another sub-task' => '', + // 'Time Spent' => '', + // 'Edit a sub-task' => '', + // 'Remove a sub-task' => '', + // 'The time must be a numeric value' => '', + // 'Todo' => '', + // 'In progress' => '', + // 'Done' => '', + // 'Sub-task removed successfully.' => '', + // 'Unable to remove this sub-task.' => '', + // 'Sub-task updated successfully.' => '', + // 'Unable to update your sub-task.' => '', + // 'Unable to create your sub-task.' => '', + // 'Sub-task added successfully.' => '', ); diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php index d0d9efa88..0d8384dd9 100644 --- a/app/Locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -344,4 +344,29 @@ return array( // 'Add a comment' => '', // 'Edit a comment' => '', // 'Summary' => '', + // 'Time tracking' => '', + // 'Estimate:' => '', + // 'Spent:' => '', + // 'Do you really want to remove this sub-task?' => '', + // 'Remaining:' => '', + // 'hours' => '', + // 'spent' => '', + // 'estimated' => '', + // 'Sub-Tasks' => '', + // 'Add a sub-task' => '', + // 'Original Estimate' => '', + // 'Create another sub-task' => '', + // 'Time Spent' => '', + // 'Edit a sub-task' => '', + // 'Remove a sub-task' => '', + // 'The time must be a numeric value' => '', + // 'Todo' => '', + // 'In progress' => '', + // 'Done' => '', + // 'Sub-task removed successfully.' => '', + // 'Unable to remove this sub-task.' => '', + // 'Sub-task updated successfully.' => '', + // 'Unable to update your sub-task.' => '', + // 'Unable to create your sub-task.' => '', + // 'Sub-task added successfully.' => '', ); diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index d1ed9f91f..56acbed52 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -344,4 +344,29 @@ return array( 'Add a comment' => 'Ajouter un commentaire', 'Edit a comment' => 'Modifier un commentaire', 'Summary' => 'Résumé', + 'Time tracking' => 'Gestion du temps', + 'Estimate:' => 'Estimation :', + 'Spent:' => 'Passé :', + 'Do you really want to remove this sub-task?' => 'Voulez-vous vraiment supprimer cette sous-tâche ?', + 'Remaining:' => 'Restant :', + 'hours' => 'heures', + 'spent' => 'passé', + 'estimated' => 'estimé', + 'Sub-Tasks' => 'Sous-Tâches', + 'Add a sub-task' => 'Ajouter une sous-tâche', + 'Original Estimate' => 'Estimation originale', + 'Create another sub-task' => 'Créer une autre sous-tâche', + 'Time Spent' => 'Temps passé', + 'Edit a sub-task' => 'Modifier une sous-tâche', + 'Remove a sub-task' => 'Supprimer une sous-tâche', + 'The time must be a numeric value' => 'Le temps doit-être une valeur numérique', + 'Todo' => 'À faire', + 'In progress' => 'En cours', + 'Done' => 'Terminé', + 'Sub-task removed successfully.' => 'Sous-tâche supprimée avec succès.', + 'Unable to remove this sub-task.' => 'Impossible de supprimer cette sous-tâche.', + 'Sub-task updated successfully.' => 'Sous-tâche mise à jour avec succès.', + 'Unable to update your sub-task.' => 'Impossible de mettre à jour votre sous-tâche.', + 'Unable to create your sub-task.' => 'Impossible de créer votre sous-tâche.', + 'Sub-task added successfully.' => 'Sous-tâche ajouté avec succès.', ); diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php index 3490810aa..dca01a2c2 100644 --- a/app/Locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -349,4 +349,29 @@ return array( // 'Add a comment' => '', // 'Edit a comment' => '', // 'Summary' => '', + // 'Time tracking' => '', + // 'Estimate:' => '', + // 'Spent:' => '', + // 'Do you really want to remove this sub-task?' => '', + // 'Remaining:' => '', + // 'hours' => '', + // 'spent' => '', + // 'estimated' => '', + // 'Sub-Tasks' => '', + // 'Add a sub-task' => '', + // 'Original Estimate' => '', + // 'Create another sub-task' => '', + // 'Time Spent' => '', + // 'Edit a sub-task' => '', + // 'Remove a sub-task' => '', + // 'The time must be a numeric value' => '', + // 'Todo' => '', + // 'In progress' => '', + // 'Done' => '', + // 'Sub-task removed successfully.' => '', + // 'Unable to remove this sub-task.' => '', + // 'Sub-task updated successfully.' => '', + // 'Unable to update your sub-task.' => '', + // 'Unable to create your sub-task.' => '', + // 'Sub-task added successfully.' => '', ); diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php index 267006cef..00fcccefa 100644 --- a/app/Locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -345,4 +345,29 @@ return array( // 'Add a comment' => '', // 'Edit a comment' => '', // 'Summary' => '', + // 'Time tracking' => '', + // 'Estimate:' => '', + // 'Spent:' => '', + // 'Do you really want to remove this sub-task?' => '', + // 'Remaining:' => '', + // 'hours' => '', + // 'spent' => '', + // 'estimated' => '', + // 'Sub-Tasks' => '', + // 'Add a sub-task' => '', + // 'Original Estimate' => '', + // 'Create another sub-task' => '', + // 'Time Spent' => '', + // 'Edit a sub-task' => '', + // 'Remove a sub-task' => '', + // 'The time must be a numeric value' => '', + // 'Todo' => '', + // 'In progress' => '', + // 'Done' => '', + // 'Sub-task removed successfully.' => '', + // 'Unable to remove this sub-task.' => '', + // 'Sub-task updated successfully.' => '', + // 'Unable to update your sub-task.' => '', + // 'Unable to create your sub-task.' => '', + // 'Sub-task added successfully.' => '', ); diff --git a/app/Model/Base.php b/app/Model/Base.php index e95296bbf..ddc06c3db 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -14,6 +14,7 @@ require __DIR__.'/../../vendor/SimpleValidator/Validators/AlphaNumeric.php'; require __DIR__.'/../../vendor/SimpleValidator/Validators/GreaterThan.php'; require __DIR__.'/../../vendor/SimpleValidator/Validators/Date.php'; require __DIR__.'/../../vendor/SimpleValidator/Validators/Email.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Numeric.php'; use Core\Event; use PicoDb\Database; diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php new file mode 100644 index 000000000..21ccdaac5 --- /dev/null +++ b/app/Model/SubTask.php @@ -0,0 +1,179 @@ + t('Todo'), + self::STATUS_INPROGRESS => t('In progress'), + self::STATUS_DONE => t('Done'), + ); + + asort($status); + + return $status; + } + + /** + * Get all subtasks for a given task + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAll($task_id) + { + $status = $this->getStatusList(); + $subtasks = $this->db->table(self::TABLE) + ->eq('task_id', $task_id) + ->columns(self::TABLE.'.*', User::TABLE.'.username') + ->join(User::TABLE, 'id', 'user_id') + ->findAll(); + + foreach ($subtasks as &$subtask) { + $subtask['status_name'] = $status[$subtask['status']]; + } + + return $subtasks; + } + + /** + * Get a subtask by the id + * + * @access public + * @param integer $subtask_id Subtask id + * @return array + */ + public function getById($subtask_id) + { + return $this->db->table(self::TABLE)->eq('id', $subtask_id)->findOne(); + } + + /** + * Create + * + * @access public + * @param array $values Form values + * @return bool + */ + public function create(array $values) + { + if (isset($values['another_subtask'])) { + unset($values['another_subtask']); + } + + if (isset($values['time_estimated']) && empty($values['time_estimated'])) { + $values['time_estimated'] = 0; + } + + if (isset($values['time_spent']) && empty($values['time_spent'])) { + $values['time_spent'] = 0; + } + + return $this->db->table(self::TABLE)->save($values); + } + + /** + * Update + * + * @access public + * @param array $values Form values + * @return bool + */ + public function update(array $values) + { + if (isset($values['time_estimated']) && empty($values['time_estimated'])) { + $values['time_estimated'] = 0; + } + + if (isset($values['time_spent']) && empty($values['time_spent'])) { + $values['time_spent'] = 0; + } + + return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values); + } + + /** + * Remove + * + * @access public + * @param integer $subtask_id Subtask id + * @return bool + */ + public function remove($subtask_id) + { + return $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove(); + } + + /** + * Validate creation/modification + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validate(array $values) + { + $v = new Validator($values, array( + new Validators\Required('task_id', t('The task id is required')), + new Validators\Integer('task_id', t('The task id must be an integer')), + new Validators\Required('title', t('The title is required')), + new Validators\MaxLength('title', t('The maximum length is %d characters', 100), 100), + new Validators\Integer('user_id', t('The user id must be an integer')), + new Validators\Integer('status', t('The status must be an integer')), + new Validators\Numeric('time_estimated', t('The time must be a numeric value')), + new Validators\Numeric('time_spent', t('The time must be a numeric value')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index d3b111f98..3df38deea 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -2,7 +2,24 @@ namespace Schema; -const VERSION = 17; +const VERSION = 18; + +function version_18($pdo) +{ + $pdo->exec(" + CREATE TABLE task_has_subtasks ( + id INT NOT NULL AUTO_INCREMENT, + title VARCHAR(255), + status INT DEFAULT 0, + time_estimated INT DEFAULT 0, + time_spent INT DEFAULT 0, + task_id INT, + user_id INT, + PRIMARY KEY (id), + FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE + ) ENGINE=InnoDB CHARSET=utf8" + ); +} function version_17($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index 94ef0316e..663c7d34e 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -2,7 +2,23 @@ namespace Schema; -const VERSION = 17; +const VERSION = 18; + +function version_18($pdo) +{ + $pdo->exec(" + CREATE TABLE task_has_subtasks ( + id INTEGER PRIMARY KEY, + title TEXT COLLATE NOCASE, + status INTEGER DEFAULT 0, + time_estimated INTEGER DEFAULT 0, + time_spent INTEGER DEFAULT 0, + task_id INTEGER, + user_id INTEGER, + FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE + )" + ); +} function version_17($pdo) { diff --git a/app/Templates/comment_remove.php b/app/Templates/comment_remove.php index 02a23f93d..6409d7c02 100644 --- a/app/Templates/comment_remove.php +++ b/app/Templates/comment_remove.php @@ -1,5 +1,5 @@
+ = t('Do you really want to remove this sub-task?') ?> +
+ += Helper\escape($subtask['title']) ?>
+ +| = t('Title') ?> | += t('Status') ?> | += t('Assignee') ?> | += t('Time tracking') ?> | += t('Actions') ?> | +
|---|---|---|---|---|
| = Helper\escape($subtask['title']) ?> | += Helper\escape($subtask['status_name']) ?> | ++ + = Helper\escape($subtask['username']) ?> + + | ++ + = Helper\escape($subtask['time_spent']).'h' ?> = t('spent') ?> + + + + = Helper\escape($subtask['time_estimated']).'h' ?> = t('estimated') ?> + + | ++ = t('Edit') ?> + = t('or') ?> + = t('Remove') ?> + | +