mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
Contacts: Add 'fields' argument to VCard:all and VCard::find.
This commit is contained in:
parent
84006b59ae
commit
775cce38f0
@ -46,18 +46,25 @@ class VCard {
|
|||||||
/**
|
/**
|
||||||
* @brief Returns all cards of an address book
|
* @brief Returns all cards of an address book
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
|
* @param integer $offset
|
||||||
|
* @param integer $limit
|
||||||
|
* @param array $fields An array of the fields to return. Defaults to all.
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*
|
*
|
||||||
* The cards are associative arrays. You'll find the original vCard in
|
* The cards are associative arrays. You'll find the original vCard in
|
||||||
* ['carddata']
|
* ['carddata']
|
||||||
*/
|
*/
|
||||||
public static function all($id, $start=null, $num=null) {
|
public static function all($id, $offset=null, $limit=null, $fields = array()) {
|
||||||
$result = null;
|
$result = null;
|
||||||
|
\OCP\Util::writeLog('contacts', __METHOD__.'count fields:' . count($fields), \OCP\Util::DEBUG);
|
||||||
|
$qfields = count($fields) > 0
|
||||||
|
? '`' . implode('`,`', $fields) . '`'
|
||||||
|
: '*';
|
||||||
if(is_array($id) && count($id)) {
|
if(is_array($id) && count($id)) {
|
||||||
$id_sql = join(',', array_fill(0, count($id), '?'));
|
$id_sql = join(',', array_fill(0, count($id), '?'));
|
||||||
$sql = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` IN ('.$id_sql.') ORDER BY `fullname`';
|
$sql = 'SELECT ' . $qfields . ' FROM `*PREFIX*contacts_cards` WHERE `addressbookid` IN ('.$id_sql.') ORDER BY `fullname`';
|
||||||
try {
|
try {
|
||||||
$stmt = \OCP\DB::prepare($sql, $num, $start);
|
$stmt = \OCP\DB::prepare($sql, $limit, $offset);
|
||||||
$result = $stmt->execute($id);
|
$result = $stmt->execute($id);
|
||||||
if (\OC_DB::isError($result)) {
|
if (\OC_DB::isError($result)) {
|
||||||
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
||||||
@ -71,8 +78,8 @@ class VCard {
|
|||||||
}
|
}
|
||||||
} elseif(is_int($id) || is_string($id)) {
|
} elseif(is_int($id) || is_string($id)) {
|
||||||
try {
|
try {
|
||||||
$sql = 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? ORDER BY `fullname`';
|
$sql = 'SELECT ' . $qfields . ' FROM `*PREFIX*contacts_cards` WHERE `addressbookid` = ? ORDER BY `fullname`';
|
||||||
$stmt = \OCP\DB::prepare($sql, $num, $start);
|
$stmt = \OCP\DB::prepare($sql, $limit, $limit);
|
||||||
$result = $stmt->execute(array($id));
|
$result = $stmt->execute(array($id));
|
||||||
if (\OC_DB::isError($result)) {
|
if (\OC_DB::isError($result)) {
|
||||||
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
||||||
@ -102,11 +109,15 @@ class VCard {
|
|||||||
/**
|
/**
|
||||||
* @brief Returns a card
|
* @brief Returns a card
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
|
* @param array $fields An array of the fields to return. Defaults to all.
|
||||||
* @return associative array or false.
|
* @return associative array or false.
|
||||||
*/
|
*/
|
||||||
public static function find($id) {
|
public static function find($id, $fields = array() ) {
|
||||||
try {
|
try {
|
||||||
$stmt = \OCP\DB::prepare( 'SELECT * FROM `*PREFIX*contacts_cards` WHERE `id` = ?' );
|
$qfields = count($fields) > 0
|
||||||
|
? '`' . implode('`,`', $fields) . '`'
|
||||||
|
: '*';
|
||||||
|
$stmt = \OCP\DB::prepare( 'SELECT ' . $qfields . ' FROM `*PREFIX*contacts_cards` WHERE `id` = ?' );
|
||||||
$result = $stmt->execute(array($id));
|
$result = $stmt->execute(array($id));
|
||||||
if (\OC_DB::isError($result)) {
|
if (\OC_DB::isError($result)) {
|
||||||
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
|
||||||
|
Loading…
Reference in New Issue
Block a user