From 5e10d2d29faaf0cce4274a5b7ffa0735a0aa04a1 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 19 Aug 2014 17:43:01 -0700 Subject: Fix a bug and improve project cloning code --- app/Model/Category.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'app/Model/Category.php') 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 @@ -117,6 +117,34 @@ class Category extends Base return $r1 && $r2; } + /** + * 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 * -- cgit v1.2.3