project done

This commit is contained in:
Florian HENRY 2020-12-24 00:53:10 +01:00
parent 224a28f2d2
commit 268618d045

View File

@ -2135,50 +2135,8 @@ class Project extends CommonObject
*/
public function setCategories($categories)
{
$type_categ = Categorie::TYPE_PROJECT;
// Handle single category
if (!is_array($categories)) {
$categories = array($categories);
}
// Get current categories
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$c = new Categorie($this->db);
$existing = $c->containing($this->id, $type_categ, 'id');
// Diff
if (is_array($existing)) {
$to_del = array_diff($existing, $categories);
$to_add = array_diff($categories, $existing);
} else {
$to_del = array(); // Nothing to delete
$to_add = $categories;
}
// Process
foreach ($to_del as $del) {
if ($c->fetch($del) > 0) {
$result = $c->del_type($this, $type_categ);
if ($result < 0) {
$this->errors = $c->errors;
$this->error = $c->error;
return -1;
}
}
}
foreach ($to_add as $add) {
if ($c->fetch($add) > 0) {
$result = $c->add_type($this, $type_categ);
if ($result < 0) {
$this->errors = $c->errors;
$this->error = $c->error;
return -1;
}
}
}
return 1;
return parent::setCategoriesCommon($categories, Categorie::TYPE_PROJECT);
}