add standard fetchAll method on ProductFournisseur
This commit is contained in:
parent
4c81f0a52a
commit
5a47e4b7ec
@ -1277,4 +1277,81 @@ class ProductFournisseur extends Product
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
|
$records = array();
|
||||||
|
|
||||||
|
$sql = 'SELECT ';
|
||||||
|
$sql .= $this->getFieldList();
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||||
|
$sql .= ' WHERE t.entity IN ('.getEntity('productsupplierprice').')';
|
||||||
|
|
||||||
|
// Manage filter
|
||||||
|
$sqlwhere = array();
|
||||||
|
if (count($filter) > 0) {
|
||||||
|
foreach ($filter as $key => $value) {
|
||||||
|
if ($key == 't.rowid') {
|
||||||
|
$sqlwhere[] = $key.'='.$value;
|
||||||
|
} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
|
||||||
|
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
|
||||||
|
} elseif ($key == 'customsql') {
|
||||||
|
$sqlwhere[] = $value;
|
||||||
|
} elseif (strpos($value, '%') === false) {
|
||||||
|
$sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
|
||||||
|
} else {
|
||||||
|
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($sqlwhere) > 0) {
|
||||||
|
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($sortfield)) {
|
||||||
|
$sql .= $this->db->order($sortfield, $sortorder);
|
||||||
|
}
|
||||||
|
if (!empty($limit)) {
|
||||||
|
$sql .= ' '.$this->db->plimit($limit, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql) {
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
$i = 0;
|
||||||
|
while ($i < ($limit ? min($limit, $num) : $num)) {
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
$record = new self($this->db);
|
||||||
|
$record->setVarsFromFetchObj($obj);
|
||||||
|
|
||||||
|
$records[$record->id] = $record;
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
|
||||||
|
return $records;
|
||||||
|
} else {
|
||||||
|
$this->errors[] = 'Error '.$this->db->lasterror();
|
||||||
|
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user