示例#1
0
 public function testAddCategories()
 {
     $categories = array('Friends', 'Family', 'Work', 'Other');
     $catmgr = new OC_VCategories($this->objectType, $this->user);
     foreach ($categories as $category) {
         $result = $catmgr->add($category);
         $this->assertTrue($result);
     }
     $this->assertFalse($catmgr->add('Family'));
     $this->assertFalse($catmgr->add('fAMILY'));
     $this->assertEqual(4, count($catmgr->categories()));
 }
示例#2
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.'));
}
示例#3
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())));