diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-04-12 22:31:28 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-04-12 23:10:49 +0200 |
commit | fa853102e41ec4308af024bc0fce48a1a9ef7274 (patch) | |
tree | 7c6b59d365830586761551f7aa15fa59a2924d39 /apps/contacts/lib | |
parent | bc81179163642098ee27cf43aff25c4c68f3e12c (diff) | |
download | nextcloud-server-fa853102e41ec4308af024bc0fce48a1a9ef7274.tar.gz nextcloud-server-fa853102e41ec4308af024bc0fce48a1a9ef7274.zip |
Contacts: Move use of OC_Contacts_App::$categories to inside of OC_Contacts_App
This is in preparation of making $categories protected and initialized
with default categories.
Diffstat (limited to 'apps/contacts/lib')
-rw-r--r-- | apps/contacts/lib/app.php | 40 | ||||
-rw-r--r-- | apps/contacts/lib/vcard.php | 4 |
2 files changed, 41 insertions, 3 deletions
diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index cc33c733007..f6f6e619075 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -156,7 +156,45 @@ class OC_Contacts_App { } public static function getCategories() { - return self::$categories->categories(); + $categories = self::$categories->categories(); + if(count($categories) == 0) { + self::scanCategories(); + $categories = self::$categories->categories(); + } + return $categories; + } + + /** + * scan vcards for categories. + * @param $vccontacts VCards to scan. null to check all vcards for the current user. + */ + public static function scanCategories($vccontacts = null) { + if (is_null($vccontacts)) { + $vcaddressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); + if(count($vcaddressbooks) > 0) { + $vcaddressbookids = array(); + foreach($vcaddressbooks as $vcaddressbook) { + $vcaddressbookids[] = $vcaddressbook['id']; + } + $vccontacts = OC_Contacts_VCard::all($vcaddressbookids); + } + } + if(is_array($vccontacts) && count($vccontacts) > 0) { + $cards = array(); + foreach($vccontacts as $vccontact) { + $cards[] = $vccontact['carddata']; + } + + self::$categories->rescan($cards); + } + } + + /** + * check VCard for new categories. + * @see OC_VCategories::loadFromVObject + */ + public static function loadCategoriesFromVCard(OC_VObject $contact) { + self::$categories->loadFromVObject($contact); } public static function setLastModifiedHeader($contact) { diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index 15a6176d40c..1502423b90f 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -234,7 +234,7 @@ class OC_Contacts_VCard{ return null; }; - OC_Contacts_App::$categories->loadFromVObject($card); + OC_Contacts_App::loadCategoriesFromVCard($card); self::updateValuesFromAdd($card); @@ -306,7 +306,7 @@ class OC_Contacts_VCard{ return false; } - OC_Contacts_App::$categories->loadFromVObject($card); + OC_Contacts_App::loadCategoriesFromVCard($card); $fn = $card->getAsString('FN'); if (empty($fn)) { |