diff options
Diffstat (limited to 'apps/contacts/lib/addressbook.php')
-rw-r--r-- | apps/contacts/lib/addressbook.php | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 6f2f34225de..78792f5f948 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -140,6 +140,25 @@ class OC_Contacts_Addressbook{ return true; } + public static function cleanArray($array, $remove_null_number = true){ + $new_array = array(); + + $null_exceptions = array(); + + foreach ($array as $key => $value){ + $value = trim($value); + + if($remove_null_number){ + $null_exceptions[] = '0'; + } + + if(!in_array($value, $null_exceptions) && $value != "") { + $new_array[] = $value; + } + } + return $new_array; + } + /** * @brief Get active addressbooks for a user. * @param integer $uid User id. If null current user will be used. @@ -170,8 +189,21 @@ class OC_Contacts_Addressbook{ public static function active($uid){ $active = self::activeIds($uid); $addressbooks = array(); - /** FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'? - */ + $ids_sql = join(',', array_fill(0, count($active), '?')); + $prep = 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id IN ('.$ids_sql.') ORDER BY displayname'; + try { + $stmt = OC_DB::prepare( $prep ); + $result = $stmt->execute($active); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_Addressbook:active:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_Addressbook:active, ids: '.join(',', $active),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_Addressbook::active, SQL:'.$prep,OC_Log::DEBUG); + } + + while( $row = $result->fetchRow()){ + $addressbooks[] = $row; + } + /* foreach( $active as $aid ){ $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' ); $result = $stmt->execute(array($aid,)); @@ -179,7 +211,7 @@ class OC_Contacts_Addressbook{ while( $row = $result->fetchRow()){ $addressbooks[] = $row; } - } + }*/ return $addressbooks; } @@ -208,6 +240,7 @@ class OC_Contacts_Addressbook{ unset($openaddressbooks[array_search($id, $openaddressbooks)]); } } + $openaddressbooks = self::cleanArray($openaddressbooks, false); sort($openaddressbooks, SORT_NUMERIC); // FIXME: I alway end up with a ';' prepending when imploding the array..? OC_Preferences::setValue(OC_User::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks)); @@ -221,7 +254,7 @@ class OC_Contacts_Addressbook{ * @return boolean */ public static function isActive($id){ - OC_Log::write('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()), OC_Log::DEBUG); + //OC_Log::write('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()), OC_Log::DEBUG); return in_array($id, self::activeIds()); } |