diff --git a/htdocs/webportal/class/html.formlistwebportal.class.php b/htdocs/webportal/class/html.formlistwebportal.class.php
index 6b5b341cc12..0458022ce8f 100644
--- a/htdocs/webportal/class/html.formlistwebportal.class.php
+++ b/htdocs/webportal/class/html.formlistwebportal.class.php
@@ -366,11 +366,14 @@ class FormListWebPortal
}
/**
- * set SQL request
+ * Set SQL request
*
+ * @param string $sqlSelect [=''] Add more fields in SQL select
+ * @param string $sqlBody [=''] Add more fields in SQL where
+ * @param string $sqlOrder [=''] Add more fields in SQL order by
* @return void
*/
- public function setSqlRequest()
+ public function setSqlRequest($sqlSelect = '', $sqlBody = '', $sqlOrder = '')
{
global $hookmanager;
@@ -384,8 +387,11 @@ class FormListWebPortal
if ($this->object->ismultientitymanaged == 1) {
$this->sql_select .= ", t.entity as element_entity, t.entity";
}
+ $this->sql_select .= $sqlSelect;
// Add fields from hooks
- $parameters = array();
+ $parameters = array(
+ 'sql_select' => &$this->sql_select,
+ );
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $context);
$this->sql_select .= $hookmanager->resPrint;
$this->sql_select = preg_replace('/,\s*$/', '', $this->sql_select);
@@ -455,8 +461,11 @@ class FormListWebPortal
if (!empty($this->search_all) && !empty($this->fields_to_search_all)) {
$this->sql_body .= natural_search(array_keys($this->fields_to_search_all), $this->search_all);
}
+ $this->sql_body .= $sqlBody;
// Add where from hooks
- $parameters = array();
+ $parameters = array(
+ 'sql_body' => &$this->sql_body,
+ );
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $context);
$this->sql_body .= $hookmanager->resPrint;
@@ -466,6 +475,13 @@ class FormListWebPortal
$this->offset = $this->limit * ($this->page - 1);
$this->sql_order = $this->db->order($this->sortfield, $this->sortorder);
+ $this->sql_order .= $sqlOrder;
+ // Add order by from hooks
+ $parameters = array(
+ 'sql_order' => &$this->sql_order,
+ );
+ $reshook = $hookmanager->executeHooks('printFieldListOrderBy', $parameters, $context);
+
if ($this->limit) {
$this->sql_order .= $this->db->plimit($this->limit, $this->offset);
}
diff --git a/htdocs/webportal/controllers/invoicelist.controller.class.php b/htdocs/webportal/controllers/invoicelist.controller.class.php
index a029a48ceb4..3e5467fa4b7 100644
--- a/htdocs/webportal/controllers/invoicelist.controller.class.php
+++ b/htdocs/webportal/controllers/invoicelist.controller.class.php
@@ -74,12 +74,11 @@ class InvoiceListController extends AbstractListController
$this->formList->doActions();
}
- $this->formList->setSqlRequest();
-
// filter on logged third-party
- $this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
+ $sqlBody = " AND t.fk_soc = ".((int) $context->logged_thirdparty->id);
// discard record with status draft
- $this->formList->sql_body .= " AND t.fk_statut <> 0";
+ $sqlBody .= " AND t.fk_statut <> 0";
+ $this->formList->setSqlRequest('', $sqlBody);
$this->formList->loadRecords();
$this->formList->setParams();
diff --git a/htdocs/webportal/controllers/orderlist.controller.class.php b/htdocs/webportal/controllers/orderlist.controller.class.php
index f66074f1258..30b00d55c6c 100644
--- a/htdocs/webportal/controllers/orderlist.controller.class.php
+++ b/htdocs/webportal/controllers/orderlist.controller.class.php
@@ -75,12 +75,11 @@ class OrderListController extends AbstractListController
$this->formList->doActions();
}
- $this->formList->setSqlRequest();
-
// filter on logged third-party
- $this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
+ $sqlBody = " AND t.fk_soc = ".((int) $context->logged_thirdparty->id);
// discard record with status draft
- $this->formList->sql_body .= " AND t.fk_statut <> 0";
+ $sqlBody .= " AND t.fk_statut <> 0";
+ $this->formList->setSqlRequest('', $sqlBody);
$this->formList->loadRecords();
$this->formList->setParams();
diff --git a/htdocs/webportal/controllers/propallist.controller.class.php b/htdocs/webportal/controllers/propallist.controller.class.php
index 7edae69688c..6bef1c9ca78 100644
--- a/htdocs/webportal/controllers/propallist.controller.class.php
+++ b/htdocs/webportal/controllers/propallist.controller.class.php
@@ -78,12 +78,11 @@ class PropalListController extends AbstractListController
$this->formList->doActions();
}
- $this->formList->setSqlRequest();
-
// filter on logged third-party
- $this->formList->sql_body .= " AND t.fk_soc = " . ((int) $context->logged_thirdparty->id);
+ $sqlBody = " AND t.fk_soc = ".((int) $context->logged_thirdparty->id);
// discard record with status draft
- $this->formList->sql_body .= " AND t.fk_statut <> 0";
+ $sqlBody .= " AND t.fk_statut <> 0";
+ $this->formList->setSqlRequest('', $sqlBody);
$this->formList->loadRecords();
$this->formList->setParams();