diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index 09c8e344794..dc33a189be2 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -44,6 +44,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// Load translation files required by the page
$langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda"));
@@ -374,6 +375,10 @@ if (empty($reshook) && $action == 'add')
{
if (! $object->error)
{
+ // Category association
+ $categories = GETPOST('categories', 'array');
+ $object->setCategories($categories);
+
unset($_SESSION['assignedtouser']);
$moreparam='';
@@ -595,6 +600,10 @@ if (empty($reshook) && $action == 'update')
if ($result > 0)
{
+ // Category association
+ $categories = GETPOST('categories', 'array');
+ $object->setCategories($categories);
+
unset($_SESSION['assignedtouser']);
$db->commit();
@@ -1000,6 +1009,14 @@ if ($action == 'create')
print '';
}
+ if ($conf->categorie->enabled) {
+ // Categories
+ print '
| '.$langs->trans("Categories").' | ';
+ $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACTIONCOMM, '', 'parent', 64, 0, 1);
+ print $form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, '', 0, '100%');
+ print " |
";
+ }
+
print '';
@@ -1411,6 +1428,19 @@ if ($id > 0)
print $form->select_dolusers($object->userdoneid> 0?$object->userdoneid:-1, 'doneby', 1);
print '';
}
+ // Tags-Categories
+ if ($conf->categorie->enabled) {
+ print '| '.$langs->trans("Categories").' | ';
+ $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACTIONCOMM, '', 'parent', 64, 0, 1);
+ $c = new Categorie($db);
+ $cats = $c->containing($object->id, Categorie::TYPE_ACTIONCOMM);
+ $arrayselected = array();
+ foreach ($cats as $cat) {
+ $arrayselected[] = $cat->id;
+ }
+ print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
+ print " |
";
+ }
print '';
@@ -1716,6 +1746,12 @@ if ($id > 0)
}
print '';
}
+ // Categories
+ if ($conf->categorie->enabled) {
+ print '| '.$langs->trans("Categories").' | ';
+ print $form->showCategories($object->id, 'actioncomm', 1);
+ print " |
";
+ }
print '';
diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 97d3c4e397e..3e84c23dbc3 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -1501,6 +1501,50 @@ class ActionComm extends CommonObject
return $result;
}
+ /**
+ * Sets object to supplied categories.
+ *
+ * Deletes object from existing categories not supplied.
+ * Adds it to non existing supplied categories.
+ * Existing categories are left untouch.
+ *
+ * @param int[]|int $categories Category or categories IDs
+ * @return void
+ */
+ public function setCategories($categories)
+ {
+ // Handle single category
+ if (! is_array($categories)) {
+ $categories = array($categories);
+ }
+
+ // Get current categories
+ include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
+ $c = new Categorie($this->db);
+ $existing = $c->containing($this->id, Categorie::TYPE_ACTIONCOMM, '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) {
+ $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
+ }
+ }
+ foreach ($to_add as $add) {
+ if ($c->fetch($add) > 0) {
+ $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
+ }
+ }
+ return;
+ }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**