示例#1
0
 /**
  * @brief Save the list with categories
  */
 private function save()
 {
     if (is_array($this->categories)) {
         foreach ($this->categories as $category) {
             OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, array('uid' => $this->user, 'type' => $this->type, 'category' => $category));
         }
         // reload categories to get the proper ids.
         $this->loadCategories();
         // Loop through temporarily cached objectid/categoryname pairs
         // and save relations.
         $categories = $this->categories;
         // For some reason this is needed or array_search(i) will return 0..?
         ksort($categories);
         foreach (self::$relations as $relation) {
             $catid = $this->array_searchi($relation['category'], $categories);
             OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG);
             if ($catid) {
                 OCP\DB::insertIfNotExist(self::RELATION_TABLE, array('objid' => $relation['objid'], 'categoryid' => $catid, 'type' => $this->type));
             }
         }
         self::$relations = array();
         // reset
     } else {
         OC_Log::write('core', __METHOD__ . ', $this->categories is not an array! ' . print_r($this->categories, true), OC_Log::ERROR);
     }
 }
示例#2
0
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())));
示例#3
0
 /**
  * @depends testAddToCategory
  */
 public function testRemoveFromCategory()
 {
     $objids = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
     // Is this "legal"?
     $this->testAddToCategory();
     $catmgr = new OC_VCategories($this->objectType, $this->user);
     foreach ($objids as $id) {
         $this->assertTrue(in_array($id, $catmgr->idsForCategory('Family')));
         $catmgr->removeFromCategory($id, 'Family');
         $this->assertFalse(in_array($id, $catmgr->idsForCategory('Family')));
     }
     $this->assertEqual(1, count($catmgr->categories()));
     $this->assertEqual(0, count($catmgr->idsForCategory('Family')));
 }
示例#4
0
require_once __DIR__ . '/../loghandler.php';
$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
$fromobjects = isset($_POST['fromobjects']) && ($_POST['fromobjects'] === 'true' || $_POST['fromobjects'] === '1') ? true : false;
if (is_null($categories)) {
    bailOut(OCA\Contacts\App::$l10n->t('No categories selected for deletion.'));
}
debug(print_r($categories, true));
if ($fromobjects) {
    $addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser());
    if (count($addressbooks) == 0) {
        bailOut(OCA\Contacts\App::$l10n->t('No address books found.'));
    }
    $addressbookids = array();
    foreach ($addressbooks as $addressbook) {
        $addressbookids[] = $addressbook['id'];
    }
    $contacts = OCA\Contacts\VCard::all($addressbookids);
    if (count($contacts) == 0) {
        bailOut(OCA\Contacts\App::$l10n->t('No contacts found.'));
    }
    $cards = array();
    foreach ($contacts as $contact) {
        $cards[] = array($contact['id'], $contact['carddata']);
    }
}
$catman = new OC_VCategories('contact');
$catman->delete($categories, $cards);
if ($fromobjects) {
    OCA\Contacts\VCard::updateDataByID($cards);
}
OCP\JSON::success();
示例#5
0
文件: app.php 项目: nanowish/apps
 /**
  * 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 = Addressbook::all(\OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 if ($vcaddressbook['userid'] === \OCP\User::getUser()) {
                     $vcaddressbookids[] = $vcaddressbook['id'];
                 }
             }
             $start = 0;
             $batchsize = 10;
             $categories = new \OC_VCategories('contact');
             while ($vccontacts = VCard::all($vcaddressbookids, $start, $batchsize)) {
                 $cards = array();
                 foreach ($vccontacts as $vccontact) {
                     $cards[] = array($vccontact['id'], $vccontact['carddata']);
                 }
                 \OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, \OCP\Util::DEBUG);
                 // only reset on first batch.
                 $categories->rescan($cards, true, $start == 0 ? true : false);
                 $start += $batchsize;
             }
         }
     }
 }
示例#6
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
$category = isset($_POST['category']) ? trim(strip_tags($_POST['category'])) : null;
if (is_null($category) || $category === "") {
    bailOut(OCA\Contacts\App::$l10n->t('No category name given.'));
}
$catman = new OC_VCategories('contact');
$id = $catman->add($category);
if ($id !== false) {
    OCP\JSON::success(array('data' => array('id' => $id)));
} else {
    bailOut(OCA\Contacts\App::$l10n->t('Error adding group.'));
}
 * 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/removeFromFavorites.php: ' . $msg, OC_Log::DEBUG);
    exit;
}
function debug($msg)
{
    OC_Log::write('core', 'ajax/vcategories/removeFromFavorites.php: ' . $msg, OC_Log::DEBUG);
}
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$l = OC_L10N::get('core');
$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
$type = isset($_POST['type']) ? $_POST['type'] : null;
if (is_null($type)) {
    bailOut($l->t('Object type not provided.'));
}
if (is_null($id)) {
    bailOut($l->t('%s ID not provided.', array($type)));
}
$categories = new OC_VCategories($type);
if (!$categories->removeFromFavorites($id, $type)) {
    bailOut($l->t('Error removing %s from favorites.', array($id)));
}
OC_JSON::success();
示例#8
0
/**
 * 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())));
示例#9
0
文件: add.php 项目: noci2012/owncloud
 * See the COPYING-README file.
 */
function bailOut($msg)
{
    OC_JSON::error(array('data' => array('message' => $msg)));
    OC_Log::write('core', 'ajax/vcategories/add.php: ' . $msg, OC_Log::DEBUG);
    exit;
}
function debug($msg)
{
    OC_Log::write('core', 'ajax/vcategories/add.php: ' . $msg, OC_Log::DEBUG);
}
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
$category = isset($_GET['category']) ? strip_tags($_GET['category']) : null;
$app = isset($_GET['app']) ? $_GET['app'] : null;
if (is_null($app)) {
    bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
}
OC_JSON::checkAppEnabled($app);
if (is_null($category)) {
    bailOut(OC_Contacts_App::$l10n->t('No category to add?'));
}
debug(print_r($category, true));
$categories = new OC_VCategories($app);
if ($categories->hasCategory($category)) {
    bailOut(OC_Contacts_App::$l10n->t('This category already exists: ' . $category));
} else {
    $categories->add($category, true);
}
OC_JSON::success(array('data' => array('categories' => $categories->categories())));
示例#10
0
<?php

/**
 * 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/addToFavorites.php: ' . $msg, OC_Log::DEBUG);
    exit;
}
function debug($msg)
{
    OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: ' . $msg, OC_Log::DEBUG);
}
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$type = isset($_GET['type']) ? $_GET['type'] : null;
if (is_null($type)) {
    $l = OC_L10N::get('core');
    bailOut($l->t('Object type not provided.'));
}
$categories = new OC_VCategories($type);
$ids = $categories->getFavorites($type);
OC_JSON::success(array('ids' => $ids));
示例#11
0
 /**
  * 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);
                 }
             }
         }
     }
 }
示例#12
0
 * 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/addToFavorites.php: ' . $msg, OC_Log::DEBUG);
    exit;
}
function debug($msg)
{
    OC_Log::write('core', 'ajax/vcategories/addToFavorites.php: ' . $msg, OC_Log::DEBUG);
}
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$l = OC_L10N::get('core');
$id = isset($_POST['id']) ? strip_tags($_POST['id']) : null;
$type = isset($_POST['type']) ? $_POST['type'] : null;
if (is_null($type)) {
    bailOut($l->t('Object type not provided.'));
}
if (is_null($id)) {
    bailOut($l->t('%s ID not provided.', $type));
}
$categories = new OC_VCategories($type);
if (!$categories->addToFavorites($id, $type)) {
    bailOut($l->t('Error adding %s to favorites.', $id));
}
OC_JSON::success();
示例#13
0
<?php

/**
 * 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/edit.php: ' . $msg, OC_Log::DEBUG);
    exit;
}
function debug($msg)
{
    OC_Log::write('core', 'ajax/vcategories/edit.php: ' . $msg, OC_Log::DEBUG);
}
require_once '../../../lib/base.php';
OC_JSON::checkLoggedIn();
$app = isset($_GET['app']) ? $_GET['app'] : null;
if (is_null($app)) {
    bailOut('Application name not provided.');
}
OC_JSON::checkAppEnabled($app);
$tmpl = new OC_TEMPLATE("core", "edit_categories_dialog");
$vcategories = new OC_VCategories($app);
$categories = $vcategories->categories();
debug(print_r($categories, true));
$tmpl->assign('categories', $categories);
$tmpl->printpage();