NEW Add pagination on list of object of a category
This commit is contained in:
parent
61cf47aa16
commit
bf104f609a
@ -746,13 +746,19 @@ class Categorie extends CommonObject
|
||||
/**
|
||||
* Return list of fetched instance of elements having this category
|
||||
*
|
||||
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
|
||||
* @param int $onlyids Return only ids of objects (consume less memory)
|
||||
* @return array|int -1 if KO, array of instance of object if OK
|
||||
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
|
||||
* @param int $onlyids Return only ids of objects (consume less memory)
|
||||
* @param int $limit Limit
|
||||
* @param int $offset Offset
|
||||
* @param string $sortfield Sort fields
|
||||
* @param string $sortorder Sort order ('ASC' or 'DESC');
|
||||
* @return array|int -1 if KO, array of instance of object if OK
|
||||
* @see containsObject()
|
||||
*/
|
||||
public function getObjectsInCateg($type, $onlyids = 0)
|
||||
public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC')
|
||||
{
|
||||
global $user;
|
||||
|
||||
$objs = array();
|
||||
|
||||
$obj = new $this->MAP_OBJ_CLASS[$type]( $this->db );
|
||||
@ -761,8 +767,15 @@ class Categorie extends CommonObject
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "categorie_" . $this->MAP_CAT_TABLE[$type] . " as c";
|
||||
$sql .= ", " . MAIN_DB_PREFIX . $this->MAP_OBJ_TABLE[$type] . " as o";
|
||||
$sql .= " WHERE o.entity IN (" . getEntity($obj->element).")";
|
||||
$sql.= " AND c.fk_categorie = ".$this->id;
|
||||
$sql .= " AND c.fk_categorie = ".$this->id;
|
||||
$sql .= " AND c.fk_" . $this->MAP_CAT_FK[$type] . " = o.rowid";
|
||||
// Protection for external users
|
||||
if (($type == 'customer' || $type == 'supplier') && $user->societe_id > 0)
|
||||
{
|
||||
$sql.= " AND o.rowid = ".$user->societe_id;
|
||||
}
|
||||
if ($limit > 0 || $offset > 0) $sql .= $this->db->plimit($limit + 1, $offset);
|
||||
$sql .= $this->db->order($sortfield, $sortorder);
|
||||
|
||||
dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
@ -34,14 +34,33 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
// Load translation files required by the page
|
||||
$langs->load("categories");
|
||||
|
||||
$id = GETPOST('id', 'int');
|
||||
$label= GETPOST('label', 'alpha');
|
||||
$type = GETPOST('type', 'az09');
|
||||
$action=GETPOST('action', 'aZ09');
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
$id = GETPOST('id', 'int');
|
||||
$label = GETPOST('label', 'alpha');
|
||||
$type = GETPOST('type', 'az09');
|
||||
$removeelem = GETPOST('removeelem', 'int');
|
||||
$elemid = GETPOST('elemid', 'int');
|
||||
|
||||
$action = GETPOST('action', 'aZ09')?GETPOST('action', 'aZ09'):'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
|
||||
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
|
||||
$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
|
||||
$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
|
||||
$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
|
||||
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
|
||||
$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'myobjectlist'; // To manage different context of search
|
||||
$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
|
||||
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
|
||||
|
||||
|
||||
// Load variable for pagination
|
||||
$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit;
|
||||
$sortfield = GETPOST('sortfield', 'alpha');
|
||||
$sortorder = GETPOST('sortorder', 'alpha');
|
||||
$page = GETPOST('page', 'int');
|
||||
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
|
||||
$offset = $limit * $page;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
|
||||
if ($id == "" && $label == "")
|
||||
{
|
||||
dol_print_error('', 'Missing parameter id');
|
||||
@ -319,10 +338,20 @@ else
|
||||
}
|
||||
|
||||
|
||||
// List of mass actions available
|
||||
$arrayofmassactions = array(
|
||||
//'validate'=>$langs->trans("Validate"),
|
||||
//'generate_doc'=>$langs->trans("ReGeneratePDF"),
|
||||
//'builddoc'=>$langs->trans("PDFMerge"),
|
||||
//'presend'=>$langs->trans("SendByMail"),
|
||||
);
|
||||
$massactionbutton=$form->selectMassAction('', $arrayofmassactions);
|
||||
|
||||
|
||||
// List of products or services (type is type of category)
|
||||
if ($type == Categorie::TYPE_PRODUCT)
|
||||
{
|
||||
$prods = $object->getObjectsInCateg("product");
|
||||
$prods = $object->getObjectsInCateg("product", 0, $limit, $offset);
|
||||
if ($prods < 0)
|
||||
{
|
||||
dol_print_error($db, $prods->error, $prods->errors);
|
||||
@ -351,14 +380,28 @@ if ($type == Categorie::TYPE_PRODUCT)
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
print "<br>";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($prods); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("ProductsAndServices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print "<table class='noborder' width='100%'>\n";
|
||||
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("ProductsAndServices").' <span class="badge">'.count($prods).'</span></td></tr>'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n";
|
||||
|
||||
if (count($prods) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($prods as $prod)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
print $prod->getNomUrl(1);
|
||||
@ -388,26 +431,42 @@ if ($type == Categorie::TYPE_PRODUCT)
|
||||
print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoProduct").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == Categorie::TYPE_SUPPLIER)
|
||||
{
|
||||
$socs = $object->getObjectsInCateg("supplier");
|
||||
$socs = $object->getObjectsInCateg("supplier", 0, $limit, $offset);
|
||||
if ($socs < 0)
|
||||
{
|
||||
dol_print_error($db, $socs->error, $socs->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($socs); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Suppliers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print '<table class="noborder" width="100%">'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Suppliers").' <span class="badge">'.count($socs)."</span></td></tr>\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name")."</td></tr>\n";
|
||||
|
||||
if (count($socs) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($socs as $soc)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
print $soc->getNomUrl(1);
|
||||
@ -437,30 +496,41 @@ if ($type == Categorie::TYPE_SUPPLIER)
|
||||
print '<tr class="oddeven"><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoSupplier").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if($type == Categorie::TYPE_CUSTOMER)
|
||||
{
|
||||
$socs = $object->getObjectsInCateg("customer");
|
||||
$socs = $object->getObjectsInCateg("customer", 0, $limit, $offset);
|
||||
if ($socs < 0)
|
||||
{
|
||||
dol_print_error($db, $socs->error, $socs->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($socs); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Customers"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print '<table class="noborder" width="100%">'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Customers").' <span class="badge">'.count($socs).'</span></td></tr>'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Name").'</td></tr>'."\n";
|
||||
|
||||
if (count($socs) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($socs as $key => $soc)
|
||||
{
|
||||
if ($user->societe_id > 0 && $soc->id != $user->societe_id) continue; // External user always see only themself
|
||||
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
@ -490,6 +560,8 @@ if($type == Categorie::TYPE_CUSTOMER)
|
||||
print '<tr class="oddeven"><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoCustomer").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -498,21 +570,35 @@ if ($type == Categorie::TYPE_MEMBER)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
|
||||
|
||||
$prods = $object->getObjectsInCateg("member");
|
||||
$prods = $object->getObjectsInCateg("member", 0, $limit, $offset);
|
||||
if ($prods < 0)
|
||||
{
|
||||
dol_print_error($db, $prods->error, $prods->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($prods); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Member"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print "<table class='noborder' width='100%'>\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Member").' <span class="badge">'.count($prods).'</span></td></tr>'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Name").'</td></tr>'."\n";
|
||||
|
||||
if (count($prods) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($prods as $key => $member)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
$member->ref=$member->login;
|
||||
@ -543,22 +629,35 @@ if ($type == Categorie::TYPE_MEMBER)
|
||||
print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoMember").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Categorie contact
|
||||
if ($type == Categorie::TYPE_CONTACT)
|
||||
{
|
||||
$contacts = $object->getObjectsInCateg("contact");
|
||||
$contacts = $object->getObjectsInCateg("contact", 0, $limit, $offset);
|
||||
if ($contacts < 0)
|
||||
{
|
||||
dol_print_error($db, $contacts->error, $contacts->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($contacts); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Contact"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print '<table class="noborder" width="100%">'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Contact").' <span class="badge">'.count($contacts).'</span></td></tr>'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Ref").'</td></tr>'."\n";
|
||||
|
||||
if (count($contacts) > 0)
|
||||
{
|
||||
@ -566,6 +665,7 @@ if ($type == Categorie::TYPE_CONTACT)
|
||||
foreach ($contacts as $key => $contact)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
@ -595,6 +695,8 @@ if ($type == Categorie::TYPE_CONTACT)
|
||||
print '<tr class="oddeven"><td class="opacitymedium">'.$langs->trans("ThisCategoryHasNoContact").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -603,21 +705,35 @@ if ($type == Categorie::TYPE_ACCOUNT)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
|
||||
$accounts = $object->getObjectsInCateg("account");
|
||||
$accounts = $object->getObjectsInCateg("account", 0, $limit, $offset);
|
||||
if ($accounts < 0)
|
||||
{
|
||||
dol_print_error($db, $accounts->error, $accounts->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
print "<table class='noborder' width='100%'>\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Account").' <span class="badge">'.count($accounts).'</span></td></tr>'."\n";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($accounts); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Account"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print "<table class='noborder' width='100%'>\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
|
||||
|
||||
if (count($accounts) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($accounts as $key => $account)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
print $account->getNomUrl(1, 0);
|
||||
@ -647,6 +763,8 @@ if ($type == Categorie::TYPE_ACCOUNT)
|
||||
print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoAccount").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,21 +773,35 @@ if ($type == Categorie::TYPE_PROJECT)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
|
||||
$projects = $object->getObjectsInCateg("project");
|
||||
$projects = $object->getObjectsInCateg("project", 0, $limit, $offset);
|
||||
if ($projects < 0)
|
||||
{
|
||||
dol_print_error($db, $object->error, $object->errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<br>";
|
||||
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="type" value="'.$typeid.'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="action" value="list">';
|
||||
|
||||
print '<br>';
|
||||
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($projects); $nbtotalofrecords = ''; $newcardbutton = '';
|
||||
print_barre_liste($langs->trans("Project"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
|
||||
|
||||
print "<table class='noborder' width='100%'>\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Project").' <span class="badge">'.count($projects).'</span></td></tr>'."\n";
|
||||
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";
|
||||
|
||||
if (count($projects) > 0)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($projects as $key => $project)
|
||||
{
|
||||
$i++;
|
||||
if ($i > $limit) break;
|
||||
|
||||
print "\t".'<tr class="oddeven">'."\n";
|
||||
print '<td class="nowrap" valign="top">';
|
||||
print $project->getNomUrl(1);
|
||||
@ -699,6 +831,8 @@ if ($type == Categorie::TYPE_PROJECT)
|
||||
print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoProject").'</td></tr>';
|
||||
}
|
||||
print "</table>\n";
|
||||
|
||||
print '</form>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user