From ef8e4e8400d50402f9e0e1027733de3605ea3a71 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Wed, 15 Jul 2015 08:18:17 +0200 Subject: [PATCH] inList() returns false or the index of the element backported from develop --- SeedDMS_Core/Core/inc.ClassDMS.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 0b50c1609..e5da45e28 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -196,18 +196,23 @@ class SeedDMS_Core_DMS { /** * Checks if a list of objects contains a single object * - * The regular php check done by '==' compares all attributes of + * This function is only applicable on list containing objects which have + * a method getID() because it is used to check if two objects are equal. + * The regular php check on objects done by '==' compares all attributes of * two objects, which isn't required. The method will first check * if the objects are instances of the same class. * + * The result of the function can be 0 which happens if the first element + * of an indexed array matches. + * * @param object $object1 object to look for (needle) * @param array $list list of objects (haystack) - * @return boolean true if object was found, otherwise false + * @return boolean/integer index in array if object was found, otherwise false */ static function inList($object, $list) { /* {{{ */ - foreach($list as $item) { + foreach($list as $i=>$item) { if(get_class($item) == get_class($object) && $item->getID() == $object->getID()) - return true; + return $i; } return false; } /* }}} */ @@ -258,7 +263,7 @@ class SeedDMS_Core_DMS { * * @param array $links list of objects of type SeedDMS_Core_DocumentLink * @param object $user user for which access is being checked - * @return filtered list of links + * @return array filtered list of links */ static function filterDocumentLinks($user, $links) { /* {{{ */ $tmp = array(); @@ -514,8 +519,6 @@ class SeedDMS_Core_DMS { /** * Returns all documents locked by a given user - * FIXME: Not full implemented. Do not use, because it still requires the - * temporary tables! * * @param object $user * @return array list of documents