Merge pull request #16247 from bafbes/abb120355

New : Hook selectForFormsListWhere
This commit is contained in:
Laurent Destailleur 2021-02-19 12:49:42 +01:00 committed by GitHub
commit 95b859dfd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6301,7 +6301,7 @@ class Form
*/ */
public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0) public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0)
{ {
global $conf, $langs, $user; global $conf, $langs, $user, $hookmanager;
//print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled"; //print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled";
@ -6347,27 +6347,34 @@ class Form
} }
if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') if ($objecttmp->ismultientitymanaged == 'fk_soc@societe')
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE 1=1";
if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; // Add where from hooks
if (isset($objecttmp->ismultientitymanaged) && !is_numeric($objecttmp->ismultientitymanaged)) { $parameters = array();
$sql .= ' AND parenttable.entity = t.'.$tmparray[0]; $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook
} if (!empty($hookmanager->resPrint)) $sql .= $hookmanager->resPrint;
if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) { else {
if ($objecttmp->element == 'societe') $sql .= " AND t.rowid = ".$user->socid; $sql .= " WHERE 1=1";
else $sql .= " AND t.fk_soc = ".$user->socid; if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")";
} if (isset($objecttmp->ismultientitymanaged) && !is_numeric($objecttmp->ismultientitymanaged)) {
if ($searchkey != '') $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); $sql .= ' AND parenttable.entity = t.'.$tmparray[0];
if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') { }
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
} if ($objecttmp->element == 'societe') $sql .= " AND t.rowid = ".$user->socid;
if ($objecttmp->filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" else $sql .= " AND t.fk_soc = ".$user->socid;
/*if (! DolibarrApi::_checkFilters($objecttmp->filter)) }
{ if ($searchkey != '') $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
throw new RestException(503, 'Error when validating parameter sqlfilters '.$objecttmp->filter); if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') {
}*/ if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; }
$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'Form::forgeCriteriaCallback', $objecttmp->filter).")"; if ($objecttmp->filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
} /*if (! DolibarrApi::_checkFilters($objecttmp->filter))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$objecttmp->filter);
}*/
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'Form::forgeCriteriaCallback', $objecttmp->filter).")";
}
}
$sql .= $this->db->order($fieldstoshow, "ASC"); $sql .= $this->db->order($fieldstoshow, "ASC");
//$sql.=$this->db->plimit($limit, 0); //$sql.=$this->db->plimit($limit, 0);
//print $sql; //print $sql;