From 7aa4d16eef24242142044ce4534bf282cc54293a Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Tue, 10 Apr 2018 16:23:56 +0200 Subject: [PATCH] NEW: can specify SQL 'ORDER BY' clause in fetchObjectLinked --- htdocs/core/class/commonobject.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 25fa78b1067..94380ffa794 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2787,11 +2787,12 @@ abstract class CommonObject * @param int $targetid Object target id (if not defined, id of object) * @param string $targettype Object target type (if not defined, elemennt name of object) * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided - * @param int $alsosametype 0=Return only links to object that differs from source. 1=Include also link to objects of same type. - * @return int <0 if KO, >0 if OK + * @param int $alsosametype 0=Return only links to object that differs from source. 1=Include also link to objects of same type. + * @param string $orderby SQL 'ORDER BY' clause + * @return int <0 if KO, >0 if OK * @see add_object_linked, updateObjectLinked, deleteObjectLinked */ - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1) + function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype') { global $conf; @@ -2847,7 +2848,7 @@ abstract class CommonObject $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; } - $sql .= ' ORDER BY sourcetype'; + $sql .= ' ORDER BY '.$orderby; dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); $resql = $this->db->query($sql);