]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added OC_Contacts_VCard::moveToAddressBook
authorThomas Tanghus <thomas@tanghus.net>
Mon, 13 Feb 2012 23:56:50 +0000 (00:56 +0100)
committerThomas Tanghus <thomas@tanghus.net>
Tue, 14 Feb 2012 00:00:41 +0000 (01:00 +0100)
apps/contacts/lib/vcard.php

index f9ca427354e34803df50587d80178153fba9a07e..a0eacd0e63b1c6dc5c041a1a216bc1757c82fc28 100644 (file)
@@ -384,4 +384,44 @@ class OC_Contacts_VCard{
                }
                return $temp;
        }
+
+       /**
+        * @brief Move card(s) to an address book
+        * @param integer $aid Address book id
+        * @param $id Array or integer of cards to be moved.
+        * @return boolean
+        *
+        */
+       public static function moveToAddressBook($aid, $id){
+               OC_Contacts_App::getAddressbook($aid); // check for user ownership.
+               if(is_array($id)) {
+                       $id_sql = join(',', array_fill(0, count($id), '?'));
+                       $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')';
+                       try {
+                               $stmt = OC_DB::prepare( $prep );
+                               //$aid = array($aid);
+                               $vals = array_merge((array)$aid, $id);
+                               $result = $stmt->execute($vals);
+                       } catch(Exception $e) {
+                               OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG);
+                               OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, ids: '.join(',', $vals),OC_Log::DEBUG);
+                               OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG);
+                               return false;
+                       }
+               } else {
+                       try {
+                               $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
+                               $result = $stmt->execute(array($aid, $id));
+                       } catch(Exception $e) {
+                               OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG);
+                               OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, id: '.$id,OC_Log::DEBUG);
+                               OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG);
+                               return false;
+                       }
+               }
+
+               OC_Contacts_Addressbook::touch($aid);
+               return true;
+       }
+
 }