summaryrefslogtreecommitdiff
path: root/app/Model/Category.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-08-19 17:43:01 -0700
committerFrédéric Guillot <fred@kanboard.net>2014-08-19 17:43:01 -0700
commit5e10d2d29faaf0cce4274a5b7ffa0735a0aa04a1 (patch)
tree979d41628f961e281d1c37221bdd76c7196e4313 /app/Model/Category.php
parent532b16cbdd58d3d7083eb14886a0ae826629d645 (diff)
Fix a bug and improve project cloning code
Diffstat (limited to 'app/Model/Category.php')
-rw-r--r--app/Model/Category.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/Model/Category.php b/app/Model/Category.php
index f86abe58..58841f9a 100644
--- a/app/Model/Category.php
+++ b/app/Model/Category.php
@@ -118,6 +118,34 @@ class Category extends Base
}
/**
+ * Duplicate categories from a project to another one
+ *
+ * @author Antonio Rabelo
+ * @param integer $project_from Project Template
+ * @return integer $project_to Project that receives the copy
+ * @return boolean
+ */
+ public function duplicate($project_from, $project_to)
+ {
+ $categories = $this->db->table(self::TABLE)
+ ->columns('name')
+ ->eq('project_id', $project_from)
+ ->asc('name')
+ ->findAll();
+
+ foreach ($categories as $category) {
+
+ $category['project_id'] = $project_to;
+
+ if (! $this->category->create($category)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Validate category creation
*
* @access public