Merge pull request #18159 from Hystepik/develop#1

New : Language support for knowledge record
This commit is contained in:
Laurent Destailleur 2021-08-18 00:45:50 +02:00 committed by GitHub
commit ddf425f73e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 10 deletions

View File

@ -57,9 +57,11 @@ if ($action == 'add' && !empty($permissiontoadd)) {
} }
} else { } else {
if (!GETPOSTISSET($key)) { if (!GETPOSTISSET($key)) {
if ($key != 'lang' || !GETPOSTISSET($key.'object')) {
continue; // The field was not submited to be edited continue; // The field was not submited to be edited
} }
} }
}
// Ignore special fields // Ignore special fields
if (in_array($key, array('rowid', 'entity', 'import_key'))) { if (in_array($key, array('rowid', 'entity', 'import_key'))) {
continue; continue;
@ -86,9 +88,13 @@ if ($action == 'add' && !empty($permissiontoadd)) {
} elseif ($object->fields[$key]['type'] == 'reference') { } elseif ($object->fields[$key]['type'] == 'reference') {
$tmparraykey = array_keys($object->param_list); $tmparraykey = array_keys($object->param_list);
$value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2'); $value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2');
} else {
if ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
} else { } else {
$value = GETPOST($key, 'alphanohtml'); $value = GETPOST($key, 'alphanohtml');
} }
}
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') { if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
$value = ''; // This is an implicit foreign key field $value = ''; // This is an implicit foreign key field
} }
@ -161,9 +167,11 @@ if ($action == 'update' && !empty($permissiontoadd)) {
} }
} else { } else {
if (!GETPOSTISSET($key)) { if (!GETPOSTISSET($key)) {
if ($key != 'lang' || !GETPOSTISSET($key.'object')) {
continue; // The field was not submited to be edited continue; // The field was not submited to be edited
} }
} }
}
// Ignore special fields // Ignore special fields
if (in_array($key, array('rowid', 'entity', 'import_key'))) { if (in_array($key, array('rowid', 'entity', 'import_key'))) {
continue; continue;
@ -199,7 +207,11 @@ if ($action == 'update' && !empty($permissiontoadd)) {
} elseif ($object->fields[$key]['type'] == 'reference') { } elseif ($object->fields[$key]['type'] == 'reference') {
$value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2'); $value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2');
} else { } else {
$value = GETPOST($key, 'alpha'); if ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
} else {
$value = GETPOST($key, 'alphanohtml');
}
} }
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') { if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') {
$value = ''; // This is an implicit foreign key field $value = ''; // This is an implicit foreign key field

View File

@ -79,14 +79,21 @@ foreach ($object->fields as $key => $val) {
$value = (GETPOST($key) == 'on' ? 1 : 0); $value = (GETPOST($key) == 'on' ? 1 : 0);
} elseif ($val['type'] == 'price') { } elseif ($val['type'] == 'price') {
$value = price2num(GETPOST($key)); $value = price2num(GETPOST($key));
} elseif ($key == 'lang') {
$value = GETPOST($key.'object', 'aZ09');
} else { } else {
$value = GETPOST($key, 'alphanohtml'); $value = GETPOST($key, 'alphanohtml');
} }
if (!empty($val['noteditable'])) { if (!empty($val['noteditable'])) {
print $object->showOutputField($val, $key, $value, '', '', '', 0); print $object->showOutputField($val, $key, $value, '', '', '', 0);
} else {
if ($key == 'lang') {
print img_picto('', 'language', 'class="pictofixedwidth"');
print $formadmin->select_language($value, $key.'object', 0, null, 1, 0, 0, 'minwidth300', 2);
} else { } else {
print $object->showInputField($val, $key, $value, '', '', '', 0); print $object->showInputField($val, $key, $value, '', '', '', 0);
} }
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }

View File

@ -79,15 +79,22 @@ foreach ($object->fields as $key => $val) {
$value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key; $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
} elseif ($val['type'] == 'price') { } elseif ($val['type'] == 'price') {
$value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key); $value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key);
} elseif ($key == 'lang') {
$value = GETPOSTISSET($key.'object', 'aZ09')?GETPOST($key.'object', 'aZ09'):$object->lang;
} else { } else {
$value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key; $value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key;
} }
//var_dump($val.' '.$key.' '.$value); //var_dump($val.' '.$key.' '.$value);
if ($val['noteditable']) { if ($val['noteditable']) {
print $object->showOutputField($val, $key, $value, '', '', '', 0); print $object->showOutputField($val, $key, $value, '', '', '', 0);
} else {
if ($key == 'lang') {
print img_picto('', 'language', 'class="pictofixedwidth"');
print $formadmin->select_language($value, $key.'object', 0, null, 1, 0, 0, 'minwidth300', 2);
} else { } else {
print $object->showInputField($val, $key, $value, '', '', '', 0); print $object->showInputField($val, $key, $value, '', '', '', 0);
} }
}
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }

View File

@ -81,7 +81,14 @@ foreach ($object->fields as $key => $val) {
if (in_array($val['type'], array('text', 'html'))) { if (in_array($val['type'], array('text', 'html'))) {
print '<div class="longmessagecut">'; print '<div class="longmessagecut">';
} }
if ($key == 'lang') {
$langs->load("languages");
$labellang = ($value ? $langs->trans('Language_'.$value) : '');
print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
} else {
print $object->showOutputField($val, $key, $value, '', '', '', 0); print $object->showOutputField($val, $key, $value, '', '', '', 0);
}
//print dol_escape_htmltag($object->$key, 1, 1); //print dol_escape_htmltag($object->$key, 1, 1);
if (in_array($val['type'], array('text', 'html'))) { if (in_array($val['type'], array('text', 'html'))) {
print '</div>'; print '</div>';

View File

@ -21,6 +21,7 @@ CREATE TABLE llx_knowledgemanagement_knowledgerecord(
date_creation datetime NOT NULL, date_creation datetime NOT NULL,
tms timestamp, tms timestamp,
last_main_doc varchar(255), last_main_doc varchar(255),
lang varchar(6),
fk_user_creat integer NOT NULL, fk_user_creat integer NOT NULL,
fk_user_modif integer, fk_user_modif integer,
fk_user_valid integer, fk_user_valid integer,

View File

@ -114,7 +114,8 @@ class KnowledgeRecord extends CommonObject
'answer' => array('type'=>'html', 'label'=>'Solution', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>3, 'csslist'=>'tdoverflow300'), 'answer' => array('type'=>'html', 'label'=>'Solution', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>3, 'csslist'=>'tdoverflow300'),
//'url' => array('type'=>'varchar(255)', 'label'=>'URL', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflow200', 'help'=>'UrlForInfoPage'), //'url' => array('type'=>'varchar(255)', 'label'=>'URL', 'enabled'=>'1', 'position'=>55, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflow200', 'help'=>'UrlForInfoPage'),
'fk_c_ticket_category' => array('type'=>'integer:CTicketCategory:ticket/class/cticketcategory.class.php', 'label'=>'GroupOfTicket', 'enabled'=>'$conf->ticket->enabled', 'position'=>512, 'notnull'=>0, 'visible'=>-1, 'help'=>'YouCanLinkArticleToATicketCategory'), 'fk_c_ticket_category' => array('type'=>'integer:CTicketCategory:ticket/class/cticketcategory.class.php', 'label'=>'GroupOfTicket', 'enabled'=>'$conf->ticket->enabled', 'position'=>512, 'notnull'=>0, 'visible'=>-1, 'help'=>'YouCanLinkArticleToATicketCategory'),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated'),), 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'default'=>0, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Valid'),),
'lang' => array('type'=>'varchar(6)', 'label'=>'Language', 'enabled'=>'1', 'position'=>51, 'notnull'=>0, 'visible'=>1),
); );
public $rowid; public $rowid;
public $ref; public $ref;
@ -130,6 +131,7 @@ class KnowledgeRecord extends CommonObject
public $answer; public $answer;
public $url; public $url;
public $status; public $status;
public $lang;
// END MODULEBUILDER PROPERTIES // END MODULEBUILDER PROPERTIES

View File

@ -28,6 +28,7 @@ require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; 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/class/knowledgerecord.class.php';
require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php'; require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
@ -117,6 +118,11 @@ if (empty($reshook)) {
$triggermodname = 'KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_MODIFY'; // Name of trigger action code to execute when we modify record $triggermodname = 'KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_MODIFY'; // Name of trigger action code to execute when we modify record
// Upadate / add for lang
if (($action == 'update' || $action == 'add') && !empty($permissiontoadd)) {
$object->lang = GETPOSTISSET('langkm', 'aZ09')?GETPOST('langkm', 'aZ09'):$object->lang;
}
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
@ -156,6 +162,7 @@ if ($action == 'confirm_validate') {
$form = new Form($db); $form = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$formproject = new FormProjets($db); $formproject = new FormProjets($db);
$formadmin = new FormAdmin($db);
$title = $langs->trans("KnowledgeRecord"); $title = $langs->trans("KnowledgeRecord");
$help_url = ''; $help_url = '';
@ -185,6 +192,7 @@ if ($action == 'create') {
// Common attributes // Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
// Other attributes // Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
@ -225,6 +233,7 @@ if (($id || $ref) && $action == 'edit') {
// Common attributes // Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
// Other attributes // Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';

View File

@ -26,6 +26,7 @@
require '../main.inc.php'; require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
@ -88,8 +89,12 @@ $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alph
$search = array(); $search = array();
foreach ($object->fields as $key => $val) { foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha') !== '') { if (GETPOST('search_'.$key, 'alpha') !== '') {
if ($key == "lang") {
$search[$key] = GETPOST('search_'.$key, 'alpha')!='0' ? GETPOST('search_'.$key, 'alpha') : '';
} else {
$search[$key] = GETPOST('search_'.$key, 'alpha'); $search[$key] = GETPOST('search_'.$key, 'alpha');
} }
}
if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
@ -197,6 +202,7 @@ if (empty($reshook)) {
$form = new Form($db); $form = new Form($db);
$user_temp = new User($db); $user_temp = new User($db);
$formadmin = new FormAdmin($db);
$now = dol_now(); $now = dol_now();
@ -455,7 +461,11 @@ foreach ($object->fields as $key => $val) {
} elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) { } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth125', 1); print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth125', 1);
} elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) { } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
if ($key == 'lang') {
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth300', 2);
} else {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">'; print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
}
} elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
print '<div class="nowrap">'; print '<div class="nowrap">';
print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
@ -592,6 +602,10 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
} }
print $user_temp->getNomUrl(-1); print $user_temp->getNomUrl(-1);
} }
} elseif ($key == 'lang') {
$labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
print $labellang;
} else { } else {
print $object->showOutputField($val, $key, $object->$key, ''); print $object->showOutputField($val, $key, $object->$key, '');
} }