summaryrefslogtreecommitdiff
path: root/app/Model/SubTask.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-01 19:36:40 -0800
committerFrédéric Guillot <fred@kanboard.net>2014-09-01 19:36:40 -0800
commite6d0658a0eedeb6a641c003d1c492af0f9a7502c (patch)
tree31004fe37246e39e438fb2dc7f1d07996634f1f3 /app/Model/SubTask.php
parente4965546543be040da29dc341900fa9511a158be (diff)
Add the possibility to duplicate a task to another project
Diffstat (limited to 'app/Model/SubTask.php')
-rw-r--r--app/Model/SubTask.php53
1 files changed, 42 insertions, 11 deletions
diff --git a/app/Model/SubTask.php b/app/Model/SubTask.php
index 9f2941c5..011c58e7 100644
--- a/app/Model/SubTask.php
+++ b/app/Model/SubTask.php
@@ -121,13 +121,12 @@ class SubTask extends Base
}
/**
- * Create
+ * Prepare data before insert/update
*
* @access public
* @param array $values Form values
- * @return bool
*/
- public function create(array $values)
+ public function prepare(array &$values)
{
if (isset($values['another_subtask'])) {
unset($values['another_subtask']);
@@ -140,7 +139,18 @@ class SubTask extends Base
if (isset($values['time_spent']) && empty($values['time_spent'])) {
$values['time_spent'] = 0;
}
+ }
+ /**
+ * Create
+ *
+ * @access public
+ * @param array $values Form values
+ * @return bool
+ */
+ public function create(array $values)
+ {
+ $this->prepare($values);
$result = $this->db->table(self::TABLE)->save($values);
if ($result) {
@@ -160,14 +170,7 @@ class SubTask extends Base
*/
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;
- }
-
+ $this->prepare($values);
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
if ($result) {
@@ -190,6 +193,34 @@ class SubTask extends Base
}
/**
+ * Duplicate all subtasks to another task
+ *
+ * @access public
+ * @param integer $src_task_id Source task id
+ * @param integer $dst_task_id Destination task id
+ * @return bool
+ */
+ public function duplicate($src_task_id, $dst_task_id)
+ {
+ $subtasks = $this->db->table(self::TABLE)
+ ->columns('title', 'time_estimated')
+ ->eq('task_id', $src_task_id)
+ ->findAll();
+
+ foreach ($subtasks as &$subtask) {
+
+ $subtask['task_id'] = $dst_task_id;
+ $subtask['time_spent'] = 0;
+
+ if (! $this->db->table(self::TABLE)->save($subtask)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Validate creation/modification
*
* @access public