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.
This commit is contained in:
Bart Visscher 2012-04-12 22:31:28 +02:00
parent bc81179163
commit fa853102e4
5 changed files with 44 additions and 30 deletions

View File

@ -10,7 +10,7 @@ require_once('../../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$categories = OC_Contacts_App::$categories->categories();
$categories = OC_Contacts_App::getCategories();
OC_JSON::success(array('data' => array('categories'=>$categories)));

View File

@ -36,13 +36,8 @@ if(count($contacts) == 0) {
bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
$cards = array();
foreach($contacts as $contact) {
$cards[] = $contact['carddata'];
}
OC_Contacts_App::$categories->rescan($cards);
$categories = OC_Contacts_App::$categories->categories();
OC_Contacts_App::scanCategories($contacts);
$categories = OC_Contacts_App::getCategories();
OC_JSON::success(array('data' => array('categories'=>$categories)));

View File

@ -35,25 +35,6 @@ if(!is_null($id)) {
$property_types = OC_Contacts_App::getAddPropertyOptions();
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$categories = OC_Contacts_App::getCategories();
if(count($categories) == 0) {
$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(count($vccontacts) > 0) {
$cards = array();
foreach($vccontacts as $vccontact) {
$cards[] = $vccontact['carddata'];
}
OC_Contacts_App::$categories->rescan($cards);
$categories = OC_Contacts_App::$categories->categories();
}
}
}
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));

View File

@ -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) {

View File

@ -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)) {