Added ajax files for favorite category handling.

This commit is contained in:
Thomas Tanghus 2012-10-19 00:07:41 +02:00
parent f4fd4a5a52
commit 26719005a4
3 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
/**
* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
* 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);
}
require_once '../../../lib/base.php';
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();

View File

@ -0,0 +1,33 @@
<?php
/**
* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
* 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);
}
require_once '../../../lib/base.php';
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$type = isset($_POST['type']) ? $_POST['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));

View File

@ -0,0 +1,40 @@
<?php
/**
* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
* 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);
}
require_once '../../../lib/base.php';
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->removeFromFavorites($id, $type)) {
bailOut($l->t('Error removing %s from favorites.', $id));
}
OC_JSON::success();