diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index 83938b158e7..56108ba7488 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -222,10 +222,11 @@ class Skeleton_Class extends CommonObject * @param int $limit offset limit * @param int $offset offset limit * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) * * @return int <0 if KO, >0 if OK */ - public function fetchAll($sortorder, $sortfield, $limit, $offset, array $filter = array()) + public function fetchAll($sortorder, $sortfield, $limit, $offset, array $filter = array(), $filtermode='AND') { dol_syslog(__METHOD__, LOG_DEBUG); @@ -240,14 +241,19 @@ class Skeleton_Class extends CommonObject $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - $sqlwhere [] = ' AND ' . $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } if (count($sqlwhere) > 0) { - $sql .= ' WHERE ' . implode(' AND ', $sqlwhere); + $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); + } + + if (!empty($sortfield)) { + $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder; + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } - $sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder . ' ' . $this->db->plimit($limit + 1, $offset); - $this->lines = array(); $resql = $this->db->query($sql);