Fix a bug and improve project cloning code

This commit is contained in:
Frédéric Guillot
2014-08-19 17:43:01 -07:00
parent 532b16cbdd
commit 5e10d2d29f
4 changed files with 133 additions and 128 deletions

View File

@@ -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
*