Show nb of tags per type

This commit is contained in:
ldestailleur 2025-04-26 16:15:52 +02:00
parent 80cdcf4d62
commit 7c99a650e3
6 changed files with 52 additions and 62 deletions

View file

@ -62,7 +62,7 @@ $backtopage = GETPOST('backtopage', 'alpha');
$label = (string) GETPOST('label', 'alphanohtml');
$description = (string) GETPOST('description', 'restricthtml');
$color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml'));
$position = GETPOSTINT('position');
$position = GETPOSTISSET('position') ? GETPOSTINT('position') : 1;
$visible = GETPOSTINT('visible');
$parent = GETPOSTINT('parent');
@ -255,7 +255,7 @@ if ($user->hasRight('categorie', 'creer')) {
print '<input type="hidden" name="catorigin" value="'.$catorigin.'">';
}
print load_fiche_titre($langs->trans("CreateCat"));
print load_fiche_titre($langs->trans("CreateCat"), '', 'category');
print dol_get_fiche_head();
@ -263,7 +263,8 @@ if ($user->hasRight('categorie', 'creer')) {
// Ref
print '<tr>';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.dol_escape_htmltag($label).'">';
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td>';
print '<td><input id="label" class="minwidth100" name="label" value="'.dol_escape_htmltag($label).'" placeholder="'.$langs->trans("MyTag").'">';
print'</td></tr>';
// Description
@ -283,12 +284,16 @@ if ($user->hasRight('categorie', 'creer')) {
print '<td class="titlefieldcreate">'.$langs->trans("Position").'</td><td><input id="position" type="number" class="minwidth50 maxwidth50" name="position" value="'.$position.'">';
print'</td></tr>';
$htmlselect = $form->select_all_categories($type, $parent, 'parent');
// Parent category
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print img_picto($langs->trans("ParentCategory"), 'category', 'class="pictofixedwidth"');
print $form->select_all_categories($type, $parent, 'parent');
print ajax_combobox('parent');
print '</td></tr>';
if ($form->num > 0) {
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print img_picto($langs->trans("ParentCategory"), 'category', 'class="pictofixedwidth"');
print $htmlselect;
print ajax_combobox('parent');
print '</td></tr>';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

View file

@ -419,6 +419,8 @@ if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $sear
// --------------------------------------------------------------------
if (empty($mode) || $mode == 'hierarchy') {
// Mode tree
$param = ($nosearch ? '&nosearch=1' : '');
if ($type != '') {
$param .= '&type='.urlencode($type);
@ -550,7 +552,7 @@ if (empty($mode) || $mode == 'hierarchy') {
print '<tr class="oddeven">';
print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('', 'treemenu/branchbottom.gif').'</td>';
print '<td class="valignmiddle">';
print $langs->trans("NoCategoryYet");
print '<span class="opacitymedium">'.$langs->trans("NoCategoryYet").'</span>';
print '</td>';
print '<td>&nbsp;</td>';
print '</table></td>';
@ -561,22 +563,9 @@ if (empty($mode) || $mode == 'hierarchy') {
print '</div>';
} else {
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-aaa page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for a horizontal scroll in the table instead of page
// Mode list
// Example : Adding jquery code
// print '<script type="text/javascript">
// jQuery(document).ready(function() {
// function init_myfunc()
// {
// jQuery("#myid").removeAttr(\'disabled\');
// jQuery("#myid").attr(\'disabled\',\'disabled\');
// }
// init_myfunc();
// jQuery("#mybutton").click(function() {
// init_myfunc();
// });
// });
// </script>';
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-aaa page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for a horizontal scroll in the table instead of page
$arrayofselected = is_array($toselect) ? $toselect : array();
@ -811,10 +800,6 @@ if (empty($mode) || $mode == 'hierarchy') {
$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
/*if (!empty($arrayfields['anotherfield']['checked'])) {
print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
$totalarray['nbfield']++;
}*/
// Action column
if (!$conf->main_checkbox_left_column) {
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
@ -849,20 +834,6 @@ if (empty($mode) || $mode == 'hierarchy') {
// Store properties in $object
$object->setVarsFromFetchObj($obj);
/*
$object->thirdparty = null;
if ($obj->fk_soc > 0) {
if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
$companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
} else {
$companyobj = new Societe($db);
$companyobj->fetch($obj->fk_soc);
$conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
}
$object->thirdparty = $companyobj;
}*/
if ($mode == 'kanban') {
if ($i == 0) {
print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
@ -920,7 +891,6 @@ if (empty($mode) || $mode == 'hierarchy') {
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
//if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');

View file

@ -78,7 +78,7 @@ class Categorie extends CommonObject
/**
* @var array<string,int> Table of mapping between type string and ID used for field 'type' in table llx_categories
* @var array<string,int> Table of mapping between type string and type ID used for field 'type' in table llx_categories
*/
public $MAP_ID = array(
'product' => 0,

View file

@ -75,14 +75,33 @@ if (!$permissiontoread) {
$title = $langs->trans("Categories");
llxHeader('', $title, '', '', 0, 0, '', '');
// Get list of category type
$arrayofcateg = array();
foreach ($categstatic->MAP_ID as $key => $idtype) {
$arrayofcateg[$idtype] = array();
$arrayofcateg[$idtype]['key'] = $key;
$arrayofcateg[$idtype]['label'] = $langs->transnoentitiesnoconv($categstatic::$MAP_TYPE_TITLE_AREA[$key]);
$arrayofcateg[$idtype]['labelwithoutaccent'] = dol_string_unaccent($langs->transnoentitiesnoconv($categstatic::$MAP_TYPE_TITLE_AREA[$key]));
}
$arrayofcateg = dol_sort_array($arrayofcateg, 'labelwithoutaccent', 'asc', 1, 0, 1);
// Get number of tags per category type
$sql = "SELECT type as idtype, COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."categorie GROUP BY type";
$resql = $db->query($sql);
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$arrayofcateg[$obj->idtype]['nb'] = $obj->nb;
}
} else {
dol_print_error($db);
}
print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', '', '', '', -1, 0, $categstatic->picto, 0, '', '', -1, 0, 1, 1);
print '<span class="opacitymedium">';
print $langs->trans("CategorieListOfType").'<br>';
print $langs->trans("CategorieListOfType").'...<br>';
print '</span>';
print '<br>';
@ -92,20 +111,13 @@ print '<div class="aaa">';
print '<table class="liste nohover centpercent noborder">';
print '<tr class="liste_titre"><td>'.$langs->trans("Type").'</td>';
print '<td>'.$langs->trans("NumberOfCategories").'</td>';
print '<td class="center">'.$langs->trans("NumberOfCategories").'</td>';
print '<td></td>';
print '</tr>';
$arrayofcateg = array();
foreach ($categstatic->MAP_ID as $key => $id) {
$arrayofcateg[$key]['key'] = $key;
$arrayofcateg[$key]['label'] = $langs->transnoentitiesnoconv($categstatic::$MAP_TYPE_TITLE_AREA[$key]);
$arrayofcateg[$key]['labelwithoutaccent'] = dol_string_unaccent($langs->transnoentitiesnoconv($categstatic::$MAP_TYPE_TITLE_AREA[$key]));
}
$arrayofcateg = dol_sort_array($arrayofcateg, 'labelwithoutaccent', 'asc', 1);
foreach ($arrayofcateg as $key => $val) {
foreach ($arrayofcateg as $idtype => $val) {
$key = $val['key'];
$tmparray = getElementProperties($key);
$classname = $tmparray['classname'];
@ -133,13 +145,12 @@ foreach ($arrayofcateg as $key => $val) {
} else {
print img_picto('', 'generic', 'class="pictofixedwidth"');
}
print dolPrintHTML($arrayofcateg[$key]['label']);
print dolPrintHTML($arrayofcateg[$idtype]['label']);
print '</td>';
print '<td>';
$nb = 'todo';
print $nb;
print '<td class="center">';
print $arrayofcateg[$idtype]['nb'];
print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?mode=hierarchy&type='.urlencode($key).'">'.img_picto('', 'edit').'</a></td>';
print '<td class="center"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?mode=hierarchy&type='.urlencode($key).'">'.img_picto('', 'edit').'</a></td>';
print '</tr>';
}

View file

@ -74,7 +74,8 @@ class Form
// Some properties used to return data by some methods
/** @var array<string,int> */
public $result;
/** @var int */
/** @var int Number of line returned by method to generate combo select */
public $num;
// Cache arrays
@ -5709,6 +5710,8 @@ class Form
$output .= '</select>';
$output .= "\n";
$this->num = count($cate_arbo);
if ($outputmode == 2) {
// TODO: handle error when $cate_arbo is not an array
return $cate_arbo;

View file

@ -102,3 +102,4 @@ AddObjectIntoCategory=Assign to the category
AddTicketIntoCategory=Assign the category to the ticket
CategorieListOfType=Select the type of the categories/tags you want to view or edit
NumberOfCategories=Number of tags/categories
MyTag=My tag