public function testdeleteCategories() { $defcategories = array('Friends', 'Family', 'Work', 'Other'); $catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories); $this->assertEqual(4, count($catmgr->categories())); $catmgr->delete('family'); $this->assertEqual(3, count($catmgr->categories())); $catmgr->delete(array('Friends', 'Work', 'Other')); $this->assertEqual(0, count($catmgr->categories())); }
function debug($msg) { OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG); } $categories = isset($_POST['categories']) ? $_POST['categories'] : null; if (is_null($categories)) { bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.')); } debug(print_r($categories, true)); $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser()); if (count($addressbooks) == 0) { bailOut(OC_Contacts_App::$l10n->t('No address books found.')); } $addressbookids = array(); foreach ($addressbooks as $addressbook) { $addressbookids[] = $addressbook['id']; } $contacts = OC_Contacts_VCard::all($addressbookids); if (count($contacts) == 0) { bailOut(OC_Contacts_App::$l10n->t('No contacts found.')); } $cards = array(); foreach ($contacts as $contact) { $cards[] = array($contact['id'], $contact['carddata']); } debug('Before delete: ' . print_r($categories, true)); $catman = new OC_VCategories('contacts'); $catman->delete($categories, $cards); debug('After delete: ' . print_r($catman->categories(), true)); OC_Contacts_VCard::updateDataByID($cards); OCP\JSON::success(array('data' => array('categories' => $catman->categories())));
/** * Copyright (c) 2012 Thomas Tanghus <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ function bailOut($msg) { OC_JSON::error(array('data' => array('message' => $msg))); OC_Log::write('core', 'ajax/vcategories/delete.php: ' . $msg, OC_Log::DEBUG); exit; } function debug($msg) { OC_Log::write('core', 'ajax/vcategories/delete.php: ' . $msg, OC_Log::DEBUG); } OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); $l = OC_L10N::get('core'); $type = isset($_POST['type']) ? $_POST['type'] : null; $categories = isset($_POST['categories']) ? $_POST['categories'] : null; if (is_null($type)) { bailOut($l->t('Object type not provided.')); } debug('The application using category type "' . $type . '" uses the default file for deletion. OC_VObjects will not be updated.'); if (is_null($categories)) { bailOut($l->t('No categories selected for deletion.')); } $vcategories = new OC_VCategories($type); $vcategories->delete($categories); OC_JSON::success(array('data' => array('categories' => $vcategories->categories())));
/** * scan events for categories. * @param $events VEVENTs to scan. null to check all events for the current user. */ public static function scanCategories($events = null) { if (is_null($events)) { $calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); if (count($calendars) > 0) { $events = array(); foreach ($calendars as $calendar) { if ($calendar['userid'] === OCP\User::getUser()) { $calendar_events = OC_Calendar_Object::all($calendar['id']); $events = $events + $calendar_events; } } } } if (is_array($events) && count($events) > 0) { $vcategories = new OC_VCategories('event'); $vcategories->delete($vcategories->categories()); foreach ($events as $event) { $vobject = OC_VObject::parse($event['calendardata']); if (!is_null($vobject)) { $object = null; if (isset($calendar->VEVENT)) { $object = $calendar->VEVENT; } else { if (isset($calendar->VTODO)) { $object = $calendar->VTODO; } else { if (isset($calendar->VJOURNAL)) { $object = $calendar->VJOURNAL; } } } if ($object) { $vcategories->loadFromVObject($event['id'], $vobject, true); } } } } }