NEW show category tree in sellist and chkbxlst for common object

This commit is contained in:
lvessiller 2022-04-14 11:08:05 +02:00
parent 7ad7943d2b
commit ab61c4d735
2 changed files with 306 additions and 227 deletions

View File

@ -6830,6 +6830,8 @@ abstract class CommonObject
// 2 : key fields name (if differ of rowid) // 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists) // 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
// 5 : id category type
// 6 : ids categories list separated by comma for category root
$keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid');
if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
@ -6844,6 +6846,14 @@ abstract class CommonObject
$keyList .= ', '.$parentField; $keyList .= ', '.$parentField;
} }
$filter_categorie = false;
if (count($InfoFieldList) > 5) {
if ($InfoFieldList[0] == 'categorie') {
$filter_categorie = true;
}
}
if ($filter_categorie === false) {
$fields_label = explode('|', $InfoFieldList[1]); $fields_label = explode('|', $InfoFieldList[1]);
if (is_array($fields_label)) { if (is_array($fields_label)) {
$keyList .= ', '; $keyList .= ', ';
@ -6951,6 +6961,16 @@ abstract class CommonObject
} else { } else {
print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
} }
} else {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1);
$out .= '<option value="0">&nbsp;</option>';
foreach ($data as $data_key => $data_value) {
$out .= '<option value="' . $data_key . '"';
$out .= ($value == $data_key ? ' selected' : '');
$out .= '>' . $data_value . '</option>';
}
}
} }
$out .= '</select>'; $out .= '</select>';
} elseif ($type == 'checkbox') { } elseif ($type == 'checkbox') {
@ -6982,6 +7002,8 @@ abstract class CommonObject
// 2 : key fields name (if differ of rowid) // 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists) // 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
// 5 : id category type
// 6 : ids categories list separated by comma for category root
$keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid');
if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
@ -6996,6 +7018,14 @@ abstract class CommonObject
} }
} }
$filter_categorie = false;
if (count($InfoFieldList) > 5) {
if ($InfoFieldList[0] == 'categorie') {
$filter_categorie = true;
}
}
if ($filter_categorie === false) {
$fields_label = explode('|', $InfoFieldList[1]); $fields_label = explode('|', $InfoFieldList[1]);
if (is_array($fields_label)) { if (is_array($fields_label)) {
$keyList .= ', '; $keyList .= ', ';
@ -7105,6 +7135,11 @@ abstract class CommonObject
} else { } else {
print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
} }
} else {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1);
$out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, '', 0, $morecss, 0, '100%');
}
} }
} elseif ($type == 'link') { } elseif ($type == 'link') {
$param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]' $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter[:Sortfield]]]'
@ -7369,6 +7404,13 @@ abstract class CommonObject
$keyList .= implode(', ', $fields_label); $keyList .= implode(', ', $fields_label);
} }
$filter_categorie = false;
if (count($InfoFieldList) > 5) {
if ($InfoFieldList[0] == 'categorie') {
$filter_categorie = true;
}
}
$sql = "SELECT ".$keyList; $sql = "SELECT ".$keyList;
$sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0];
if (strpos($InfoFieldList[4], 'extra') !== false) { if (strpos($InfoFieldList[4], 'extra') !== false) {
@ -7387,6 +7429,7 @@ abstract class CommonObject
dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
if ($filter_categorie === false) {
$value = ''; // value was used, so now we reste it to use it to build final output $value = ''; // value was used, so now we reste it to use it to build final output
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -7417,6 +7460,19 @@ abstract class CommonObject
$value = $obj->{$InfoFieldList[1]}; $value = $obj->{$InfoFieldList[1]};
} }
} }
} else {
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
$toprint = array();
$obj = $this->db->fetch_object($resql);
$c = new Categorie($this->db);
$c->fetch($obj->rowid);
$ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #aaa"') . '>' . img_object('', 'category') . ' ' . $way . '</li>';
}
$value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
}
} else { } else {
dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
} }
@ -7452,6 +7508,13 @@ abstract class CommonObject
$keyList .= implode(', ', $fields_label); $keyList .= implode(', ', $fields_label);
} }
$filter_categorie = false;
if (count($InfoFieldList) > 5) {
if ($InfoFieldList[0] == 'categorie') {
$filter_categorie = true;
}
}
$sql = "SELECT ".$keyList; $sql = "SELECT ".$keyList;
$sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0];
if (strpos($InfoFieldList[4], 'extra') !== false) { if (strpos($InfoFieldList[4], 'extra') !== false) {
@ -7463,6 +7526,7 @@ abstract class CommonObject
dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
if ($filter_categorie === false) {
$value = ''; // value was used, so now we reste it to use it to build final output $value = ''; // value was used, so now we reste it to use it to build final output
$toprint = array(); $toprint = array();
while ($obj = $this->db->fetch_object($resql)) { while ($obj = $this->db->fetch_object($resql)) {
@ -7494,6 +7558,21 @@ abstract class CommonObject
} }
} }
} }
} else {
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
$toprint = array();
while ($obj = $this->db->fetch_object($resql)) {
if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
$c = new Categorie($this->db);
$c->fetch($obj->rowid);
$ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #aaa"') . '>' . img_object('', 'category') . ' ' . $way . '</li>';
}
}
}
}
$value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
} else { } else {
dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);

View File

@ -102,7 +102,7 @@ class Inventory extends CommonObject
'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'), 'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'),
'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'),
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'),
'fk_categories_product' => array('type'=>'chkbxlst:categorie:label:rowid::type=0', 'label'=>'ProductsCategoriesShort', 'visible'=>3, 'enabled'=>1, 'position'=>33, 'help'=>'', 'picto'=>'category', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx'), 'fk_categories_product' => array('type'=>'chkbxlst:categorie:label:rowid::type=0:0:', 'label'=>'ProductsCategoriesShort', 'visible'=>3, 'enabled'=>1, 'position'=>33, 'help'=>'', 'picto'=>'category', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx'),
'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default. 'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default.
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),