mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
Merge pull request #3331 from FHenry/3.8
FIX : better fetchAll method into skeleton_class.class.php
This commit is contained in:
@@ -222,10 +222,11 @@ class Skeleton_Class extends CommonObject
|
|||||||
* @param int $limit offset limit
|
* @param int $limit offset limit
|
||||||
* @param int $offset offset limit
|
* @param int $offset offset limit
|
||||||
* @param array $filter filter array
|
* @param array $filter filter array
|
||||||
|
* @param string $filtermode filter mode (AND or OR)
|
||||||
*
|
*
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function fetchAll($sortorder, $sortfield, $limit, $offset, array $filter = array())
|
public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
|
||||||
{
|
{
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
@@ -240,14 +241,19 @@ class Skeleton_Class extends CommonObject
|
|||||||
$sqlwhere = array();
|
$sqlwhere = array();
|
||||||
if (count($filter) > 0) {
|
if (count($filter) > 0) {
|
||||||
foreach ($filter as $key => $value) {
|
foreach ($filter as $key => $value) {
|
||||||
$sqlwhere [] = ' AND ' . $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
|
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($sqlwhere) > 0) {
|
if (count($sqlwhere) > 0) {
|
||||||
$sql .= ' WHERE ' . implode(' AND ', $sqlwhere);
|
$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
|
||||||
}
|
}
|
||||||
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ' . $this->db->plimit($limit + 1, $offset);
|
|
||||||
|
|
||||||
|
if (!empty($sortfield)) {
|
||||||
|
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder;
|
||||||
|
}
|
||||||
|
if (!empty($limit)) {
|
||||||
|
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||||
|
}
|
||||||
$this->lines = array();
|
$this->lines = array();
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ class modProduct extends DolibarrModules
|
|||||||
if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
|
if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
|
||||||
// Add extra fields
|
// Add extra fields
|
||||||
$import_extrafield_sample=array();
|
$import_extrafield_sample=array();
|
||||||
$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' entity IN (0, ".$conf->entity.')';
|
$sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.')';
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql) // This can fail when class is used on old database (during migration for example)
|
if ($resql) // This can fail when class is used on old database (during migration for example)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -740,7 +740,7 @@ $formcompany = new FormCompany($db);
|
|||||||
|
|
||||||
if ($socid > 0 && empty($object->id))
|
if ($socid > 0 && empty($object->id))
|
||||||
{
|
{
|
||||||
$res=$object->fetch($socid);
|
$result=$object->fetch($socid);
|
||||||
if ($result <= 0) dol_print_error('',$object->error);
|
if ($result <= 0) dol_print_error('',$object->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user