summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-02-14 00:56:50 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-02-14 01:00:41 +0100
commit3adaacc0ce8cbbcb070cd06fb52d98e4f590751a (patch)
treee3997984685ab402742e67745394b8b330313a2b /apps/contacts/lib
parent024405e4f1a645f640803ad41e24e59a43f27890 (diff)
downloadnextcloud-server-3adaacc0ce8cbbcb070cd06fb52d98e4f590751a.tar.gz
nextcloud-server-3adaacc0ce8cbbcb070cd06fb52d98e4f590751a.zip
Added OC_Contacts_VCard::moveToAddressBook
Diffstat (limited to 'apps/contacts/lib')
-rw-r--r--apps/contacts/lib/vcard.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php
index f9ca427354e..a0eacd0e63b 100644
--- a/apps/contacts/lib/vcard.php
+++ b/apps/contacts/lib/vcard.php
@@ -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;
+ }
+
}