mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 03:12:35 +01:00
FormCategory : create method to select the product category
This commit is contained in:
@@ -3708,7 +3708,6 @@ class Form
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Load into cache list of payment terms
|
||||
|
||||
@@ -60,4 +60,44 @@ class FormCategory extends Form
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a select form for products categories
|
||||
* @param string $selected Id category pre-selection
|
||||
* @param string $htmlname Name of HTML field
|
||||
* @param int $showempty Add an empty field
|
||||
* @return integer|null
|
||||
*/
|
||||
public function selectProductCategory($selected = 0, $htmlname = 'product_category_id', $showempty = 0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT cp.fk_categorie as cat_index, cat.label FROM `llx_categorie_product` as cp INNER JOIN llx_categorie as cat ON cat.rowid = cp.fk_categorie GROUP BY cp.fk_categorie;";
|
||||
|
||||
dol_syslog(get_class($this)."::selectProductCategory", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
|
||||
if ($showempty) {
|
||||
print '<option value="0"> </option>';
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$num_rows = $this->db->num_rows($resql);
|
||||
while ($i < $num_rows) {
|
||||
$category = $this->db->fetch_object($resql);
|
||||
if ($selected && $selected == $category->cat_index) {
|
||||
print '<option value="'.$category->cat_index.'" selected>'.$category->label.'</option>';
|
||||
} else {
|
||||
print '<option value="'.$category->cat_index.'">'.$category->label.'</option>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
print ('</select>');
|
||||
|
||||
return $num_rows;
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user