NEW: All fetchAll() method now support the USF syntax.
This commit is contained in:
parent
09802f76c1
commit
ef45783d64
3 changed files with 77 additions and 51 deletions
|
|
@ -513,16 +513,16 @@ class Cronjob extends CommonObject
|
|||
/**
|
||||
* Load list of cron jobs in a memory array from the database
|
||||
*
|
||||
* @param string $sortorder sort order
|
||||
* @param string $sortfield sort field
|
||||
* @param int $limit limit page
|
||||
* @param int $offset page
|
||||
* @param int $status display active or not
|
||||
* @param array $filter filter output
|
||||
* @param int $processing Processing or not
|
||||
* @return int if KO: <0 || if OK: >0
|
||||
* @param string $sortorder Sort order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit Limit page
|
||||
* @param int $offset Offset ppage
|
||||
* @param int $status Display active or not
|
||||
* @param string|array $filter Filter USF.
|
||||
* @param int $processing Processing or not
|
||||
* @return int if KO: <0 || if OK: >0
|
||||
*/
|
||||
public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, array $filter = [], int $processing = -1)
|
||||
public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, $filter = '', int $processing = -1)
|
||||
{
|
||||
$this->lines = array();
|
||||
|
||||
|
|
|
|||
|
|
@ -368,15 +368,15 @@ class ProductCustomerPrice extends CommonObject
|
|||
/**
|
||||
* Load all customer prices in memory from database
|
||||
*
|
||||
* @param string $sortorder order
|
||||
* @param string $sortfield field
|
||||
* @param int $limit page
|
||||
* @param int $offset offset
|
||||
* @param array $filter Filter for select
|
||||
* @return int Return integer <0 if KO, >0 if OK
|
||||
* @param string $sortorder Sort order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit Limit page
|
||||
* @param int $offset offset
|
||||
* @param string|array $filter Filter USF.
|
||||
* @return int Return integer <0 if KO, >0 if OK
|
||||
* @since dolibarr v17
|
||||
*/
|
||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array())
|
||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '')
|
||||
{
|
||||
if (empty($sortfield)) {
|
||||
$sortfield = "t.rowid";
|
||||
|
|
@ -418,21 +418,35 @@ class ProductCustomerPrice extends CommonObject
|
|||
$sql .= " AND t.entity IN (".getEntity('productprice').")";
|
||||
|
||||
// Manage filter
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'";
|
||||
} elseif ($key == 'soc.nom') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
} elseif ($key == 'prod.ref' || $key == 'prod.label') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
} elseif ($key == 't.price' || $key == 't.price_ttc') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = ".((float) price2num($value));
|
||||
} else {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
|
||||
if (is_array($filter)) {
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'";
|
||||
} elseif ($key == 'soc.nom') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
} elseif ($key == 'prod.ref' || $key == 'prod.label') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
} elseif ($key == 't.price' || $key == 't.price_ttc') {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = ".((float) price2num($value));
|
||||
} else {
|
||||
$sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$filter = '';
|
||||
}
|
||||
|
||||
// Manage filter
|
||||
$errormessage = '';
|
||||
$sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
|
||||
if ($errormessage) {
|
||||
$this->errors[] = $errormessage;
|
||||
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
$sql .= $this->db->order($sortfield, $sortorder);
|
||||
if (!empty($limit)) {
|
||||
$sql .= $this->db->plimit($limit + 1, $offset);
|
||||
|
|
|
|||
|
|
@ -318,18 +318,16 @@ class ProductFournisseurPrice extends CommonObject
|
|||
/**
|
||||
* Load list of objects in memory from the database.
|
||||
*
|
||||
* @param string $sortorder Sort Order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit limit
|
||||
* @param int $offset Offset
|
||||
* @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
|
||||
* @param string $filtermode Filter mode (AND or OR)
|
||||
* @return array|int int <0 if KO, array of pages if OK
|
||||
* @param string $sortorder Sort Order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit Limit
|
||||
* @param int $offset Offset
|
||||
* @param string|array $filter Filter USF.
|
||||
* @param string $filtermode Filter mode (AND or OR)
|
||||
* @return array|int int <0 if KO, array of pages if OK
|
||||
*/
|
||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
|
||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$records = array();
|
||||
|
|
@ -342,23 +340,37 @@ class ProductFournisseurPrice extends CommonObject
|
|||
} else {
|
||||
$sql .= " WHERE 1 = 1";
|
||||
}
|
||||
|
||||
// Manage filter
|
||||
$sqlwhere = array();
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if ($key == 't.rowid') {
|
||||
$sqlwhere[] = $key." = ".((int) $value);
|
||||
} elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
|
||||
$sqlwhere[] = $key." = '".$this->db->idate($value)."'";
|
||||
} elseif (strpos($value, '%') === false) {
|
||||
$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
|
||||
} else {
|
||||
$sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
if (is_array($filter)) {
|
||||
$sqlwhere = array();
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if ($key == 't.rowid') {
|
||||
$sqlwhere[] = $key." = ".((int) $value);
|
||||
} elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
|
||||
$sqlwhere[] = $key." = '".$this->db->idate($value)."'";
|
||||
} elseif (strpos($value, '%') === false) {
|
||||
$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
|
||||
} else {
|
||||
$sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($sqlwhere) > 0) {
|
||||
$sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
|
||||
}
|
||||
|
||||
$filter = '';
|
||||
}
|
||||
if (count($sqlwhere) > 0) {
|
||||
$sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
|
||||
|
||||
// Manage filter
|
||||
$errormessage = '';
|
||||
$sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
|
||||
if ($errormessage) {
|
||||
$this->errors[] = $errormessage;
|
||||
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!empty($sortfield)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue