Added OC_Contacts_VCard::moveToAddressBook

This commit is contained in:
Thomas Tanghus 2012-02-14 00:56:50 +01:00
parent 024405e4f1
commit 3adaacc0ce

View 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;
}
}