From e59be3dc021e81babaacf70661737cbba42c80cc Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 28 Dec 2014 15:39:39 -0500 Subject: Add default project categories in settings --- app/Model/Category.php | 25 ++++++++++++++++++++++++- app/Model/Project.php | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'app/Model') diff --git a/app/Model/Category.php b/app/Model/Category.php index 54a0f552..cd60e7f7 100644 --- a/app/Model/Category.php +++ b/app/Model/Category.php @@ -118,7 +118,30 @@ class Category extends Base } /** - * Create a category + * Create default cetegories during project creation (transaction already started in Project::create()) + * + * @access public + * @param integer $project_id + */ + public function createDefaultCategories($project_id) + { + $categories = explode(',', $this->config->get('project_categories')); + + foreach ($categories as $category) { + + $category = trim($category); + + if (! empty($category)) { + $this->db->table(self::TABLE)->insert(array( + 'project_id' => $project_id, + 'name' => $category, + )); + } + } + } + + /** + * Create a category (run inside a transaction) * * @access public * @param array $values Form values diff --git a/app/Model/Project.php b/app/Model/Project.php index 9c0adee9..278fe6ab 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -298,6 +298,8 @@ class Project extends Base $this->projectPermission->allowUser($project_id, $user_id); } + $this->category->createDefaultCategories($project_id); + $this->db->closeTransaction(); return (int) $project_id; -- cgit v1.2.3