Merge pull request #18696 from Hystepik/develop#1

Close #18678 : Implemention of tags/categories KM
This commit is contained in:
Laurent Destailleur 2021-09-17 11:59:29 +02:00 committed by GitHub
commit ee8e11069c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 145 additions and 4 deletions

View File

@ -58,6 +58,7 @@ class Categorie extends CommonObject
const TYPE_ACTIONCOMM = 'actioncomm';
const TYPE_WEBSITE_PAGE = 'website_page';
const TYPE_TICKET = 'ticket';
const TYPE_KNOWLEDGEMANAGEMENT = 'knowledgemanagement';
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
@ -81,7 +82,8 @@ class Categorie extends CommonObject
'warehouse' => 9,
'actioncomm' => 10,
'website_page' => 11,
'ticket' => 12
'ticket' => 12,
'knowledgemanagement' => 13
);
/**
@ -102,7 +104,8 @@ class Categorie extends CommonObject
9 => 'warehouse',
10 => 'actioncomm',
11 => 'website_page',
12 => 'ticket'
12 => 'ticket',
13 => 'knowledgemanagement'
);
/**
@ -146,7 +149,8 @@ class Categorie extends CommonObject
'warehouse'=> 'Entrepot',
'actioncomm' => 'ActionComm',
'website_page' => 'WebsitePage',
'ticket' => 'Ticket'
'ticket' => 'Ticket',
'knowledgemanagement' => 'KnowledgeRecord'
);
/**

View File

@ -131,6 +131,10 @@ if ($action == 'add' && !empty($permissiontoadd)) {
$result = $object->create($user);
if ($result > 0) {
// Creation OK
if ($conf->categorie->enabled) {
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
}
$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: ".$urltogo);
@ -229,6 +233,11 @@ if ($action == 'update' && !empty($permissiontoadd)) {
}
}
}
if ($conf->categorie->enabled) {
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
}
}
// Fill array 'array_options' with data from add form

View File

@ -362,6 +362,19 @@ class modKnowledgeManagement extends DolibarrModules
// 0=Menu for internal users, 1=external users, 2=both
'user'=>2
);
$this->menu[$r++] = array(
'fk_menu' => 'fk_mainmenu=ticket,fk_leftmenu=knowledgemanagement_knowledgerecord',
'type' => 'left',
'titre' => 'Categories',
'mainmenu' => 'ticket',
'url' => '/categories/index.php?type=13',
'langs' => 'knowledgemanagement',
'position' => 112,
'enabled' => '$conf->knowledgemanagement->enabled',
'perms' => '$user->rights->knowledgemanagement->knowledgerecord->read',
'target' => '',
'user' => 0
);
/* END MODULEBUILDER LEFTMENU KNOWLEDGERECORD */

View File

@ -93,6 +93,19 @@ DELETE FROM llx_menu WHERE type = 'top' AND module = 'cashdesk' AND mainmenu = '
INSERT INTO llx_c_action_trigger (code, label, description, elementtype, rang) values ('MEMBER_EXCLUDE', 'Member excluded', 'Executed when a member is excluded', 'member', 27);
CREATE TABLE llx_categorie_knowledgemanagement
(
fk_categorie integer NOT NULL,
fk_knowledgemanagement integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;
ALTER TABLE llx_categorie_knowledgemanagement ADD PRIMARY KEY pk_categorie_knowledgemanagement (fk_categorie, fk_knowledgemanagement);
ALTER TABLE llx_categorie_knowledgemanagement ADD INDEX idx_categorie_knowledgemanagement_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_knowledgemanagement ADD INDEX idx_categorie_knowledgemanagement_fk_knowledgemanagement (fk_knowledgemanagement);
ALTER TABLE llx_categorie_knowledgemanagement ADD CONSTRAINT fk_categorie_knowledgemanagement_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_knowledgemanagement ADD CONSTRAINT fk_categorie_knowledgemanagement_knowledgemanagement_rowid FOREIGN KEY (fk_knowledgemanagement) REFERENCES llx_knowledgemanagement (rowid);
ALTER TABLE llx_product_lot ADD COLUMN barcode varchar(180) DEFAULT NULL;
ALTER TABLE llx_product_lot ADD COLUMN fk_barcode_type integer DEFAULT NULL;

View File

@ -0,0 +1,21 @@
-- Copyright (C) 2021 EOXIA <dev@eoxia.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see https://www.gnu.org/licenses/.
ALTER TABLE llx_categorie_knowledgemanagement ADD PRIMARY KEY pk_categorie_knowledgemanagement (fk_categorie, fk_knowledgemanagement);
ALTER TABLE llx_categorie_knowledgemanagement ADD INDEX idx_categorie_knowledgemanagement_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_knowledgemanagement ADD INDEX idx_categorie_knowledgemanagement_fk_knowledgemanagement (fk_knowledgemanagement);
ALTER TABLE llx_categorie_knowledgemanagement ADD CONSTRAINT fk_categorie_knowledgemanagement_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_knowledgemanagement ADD CONSTRAINT fk_categorie_knowledgemanagement_knowledgemanagement_rowid FOREIGN KEY (fk_knowledgemanagement) REFERENCES llx_knowledgemanagement (rowid);

View File

@ -0,0 +1,20 @@
-- Copyright (C) 2021 EOXIA <dev@eoxia.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see https://www.gnu.org/licenses/.
create table llx_categorie_knowledgemanagement
fk_categorie integer NOT NULL,
fk_knowledgemanagement integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View File

@ -456,6 +456,15 @@ class KnowledgeRecord extends CommonObject
*/
public function delete(User $user, $notrigger = false)
{
$error = 0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $this->rowid);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->error .= $this->db->lasterror();
$errorflag = -1;
}
return $this->deleteCommon($user, $notrigger);
//return $this->deleteCommon($user, $notrigger, 1);
}
@ -1036,6 +1045,22 @@ class KnowledgeRecord extends CommonObject
return $error;
}
/**
* 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)
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
return parent::setCategoriesCommon($categories, Categorie::TYPE_KNOWLEDGEMANAGEMENT);
}
}

View File

@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// Load translation files required by the page
$langs->loadLangs(array("knowledgemanagement", "ticket", "other"));
@ -192,6 +193,16 @@ if ($action == 'create') {
// Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
if ($conf->categorie->enabled) {
$cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 1);
if (count($cate_arbo)) {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
print "</td></tr>";
}
}
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
@ -229,6 +240,24 @@ if (($id || $ref) && $action == 'edit') {
// Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
if ($conf->categorie->enabled) {
$cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 1);
if (count($cate_arbo)) {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
$c = new Categorie($db);
$cats = $c->containing($object->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT);
$arrayselected = array();
if (is_array($cats)) {
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
}
print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
print "</td></tr>";
}
}
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
@ -335,6 +364,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
//unset($object->fields['fk_soc']); // Hide field already shown in banner
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
// Categories
if ($conf->categorie->enabled) {
print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->showCategories($object->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT, 1);
print "</td></tr>";
}
// Other attributes. Fields from hook formObjectOptions and Extrafields.
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';