use response trait in taskscontroller

This commit is contained in:
Hendrik Leppelsack 2015-06-30 14:39:53 +02:00
parent 698b5f1660
commit 9500dd3c1f
5 changed files with 323 additions and 371 deletions

View file

@ -253,7 +253,7 @@ Class Helper {
public static function updateVCalendarFromRequest($request, $vcalendar){
$vtodo = $vcalendar->VTODO;
$lastModified = $vtodo->LAST-MODIFIED;
$lastModified = $vtodo->{'LAST-MODIFIED'};
if(is_null($lastModified)) {
$lastModified = $vtodo->add('LAST-MODIFIED');
}

View file

@ -26,13 +26,14 @@ namespace OCA\Tasks\Controller;
use \OCA\Tasks\Service\TasksService;
use \OCP\IRequest;
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\JSONResponse;
class TasksController extends Controller {
private $tasksService;
use Response;
public function __construct($appName, IRequest $request, TasksService $tasksService){
parent::__construct($appName, $request);
$this->tasksService = $tasksService;
@ -42,190 +43,152 @@ class TasksController extends Controller {
* @NoAdminRequired
*/
public function getTasks($listID = 'all', $type = 'all'){
$result = $this->tasksService->getAll($listID, $type);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($listID, $type) {
return $this->tasksService->getAll($listID, $type);
});
}
/**
* @NoAdminRequired
*/
public function getTask($taskID){
$result = $this->tasksService->get($taskID);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID) {
return $this->tasksService->get($taskID);
});
}
/**
* @NoAdminRequired
*/
public function setPriority($taskID,$priority){
$result = $this->tasksService->setPriority($taskID, $priority);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $priority) {
return $this->tasksService->setPriority($taskID, $priority);
});
}
/**
* @NoAdminRequired
*/
public function percentComplete($taskID, $complete){
$result = $this->tasksService->setPercentComplete($taskID, $complete);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $complete) {
return $this->tasksService->setPercentComplete($taskID, $complete);
});
}
/**
* @NoAdminRequired
*/
public function addTask($name, $calendarID, $starred, $due, $start, $tmpID){
$result = $this->tasksService->add($name, $calendarID, $starred, $due, $start, $tmpID);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($name, $calendarID, $starred, $due, $start, $tmpID) {
return $this->tasksService->add($name, $calendarID, $starred, $due, $start, $tmpID);
});
}
/**
* @NoAdminRequired
*/
public function deleteTask($taskID){
$result = $this->tasksService->delete($taskID);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID) {
return $this->tasksService->delete($taskID);
});
}
/**
* @NoAdminRequired
*/
public function setTaskName($taskID, $name){
$result = $this->tasksService->setName($taskID, $name);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $name) {
return $this->tasksService->setName($taskID, $name);
});
}
/**
* @NoAdminRequired
*/
public function setTaskCalendar($taskID, $calendarID){
$result = $this->tasksService->setCalendarId($taskID, $calendarID);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $calendarID) {
return $this->tasksService->setCalendarId($taskID, $calendarID);
});
}
/**
* @NoAdminRequired
*/
public function setTaskNote($taskID, $note){
$result = $this->tasksService->setDescription($taskID, $note);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $note) {
return $this->tasksService->setDescription($taskID, $note);
});
}
/**
* @NoAdminRequired
*/
public function setDueDate($taskID, $due){
$result = $this->tasksService->setDueDate($taskID, $due);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $due) {
return $this->tasksService->setDueDate($taskID, $due);
});
}
/**
* @NoAdminRequired
*/
public function setStartDate($taskID, $start){
$result = $this->tasksService->setStartDate($taskID, $start);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $start) {
return $this->tasksService->setStartDate($taskID, $start);
});
}
/**
* @NoAdminRequired
*/
public function setReminderDate($taskID, $type, $action, $date, $invert, $related = null, $week, $day, $hour, $minute, $second){
$result = $this->tasksService->setReminderDate($taskID, $type, $action, $date, $invert, $related, $week, $day, $hour, $minute, $second);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $type, $action, $date, $invert, $related, $week, $day, $hour, $minute, $second) {
return $this->tasksService->setReminderDate($taskID, $type, $action, $date, $invert, $related, $week, $day, $hour, $minute, $second);
});
}
/**
* @NoAdminRequired
*/
public function addCategory($taskID, $category){
$result = $this->tasksService->addCategory($taskID, $category);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $category) {
return $this->tasksService->addCategory($taskID, $category);
});
}
/**
* @NoAdminRequired
*/
public function removeCategory($taskID, $category){
$result = $this->tasksService->removeCategory($taskID, $category);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $category) {
return $this->tasksService->removeCategory($taskID, $category);
});
}
/**
* @NoAdminRequired
*/
public function setLocation($taskID, $location){
$result = $this->tasksService->setLocation($taskID, $location);
$response = array(
'data' => $result
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $location) {
return $this->tasksService->setLocation($taskID, $location);
});
}
/**
* @NoAdminRequired
*/
public function addComment($taskID, $comment, $tmpID){
$result = $this->tasksService->addComment($taskID, $comment, $tmpID);
$response = array(
'data' => array(
'comment' => $result
)
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $comment, $tmpID) {
return $this->tasksService->addComment($taskID, $comment, $tmpID);
});
}
/**
* @NoAdminRequired
*/
public function deleteComment($taskID, $commentID){
$result = $this->tasksService->deleteComment($taskID, $commentID);
$response = array(
'data' => array(
'comment' => $result
)
);
return (new JSONResponse())->setData($response);
return $this->generateResponse(function () use ($taskID, $commentID) {
return $this->tasksService->deleteComment($taskID, $commentID);
});
}
}

View file

@ -169,7 +169,7 @@ SettingsBusinessLayer, SearchBusinessLayer) ->
_tasksbusinesslayer.addTask task
, (data) =>
_$tasksmodel.add(data.task)
_$tasksmodel.add(data)
_$scope.isAddingTask = false
, =>
_$scope.isAddingTask = false

View file

@ -338,6 +338,53 @@
}).call(this);
(function() {
angular.module('Tasks').directive('pane', function() {
var directive;
return directive = {
scope: {
title: '@'
},
require: '^tabs',
restrict: 'E',
transclude: true,
replace: true,
link: function(scope, element, attrs, tabsCtrl) {
return tabsCtrl.addPane(scope);
},
template: '<div class="tab-pane" ng-class="{active: selected}"' + 'ng-transclude>[[ ]]</div>'
};
});
}).call(this);
(function() {
angular.module('Tasks').directive('tabs', function() {
var directive;
return directive = {
restrict: 'E',
scope: {},
controller: function($scope, $element) {
var panes;
panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
return pane.selected = false;
});
return pane.selected = true;
};
return this.addPane = function(pane) {
if (panes.length === 0) {
$scope.select(pane);
}
return panes.push(pane);
};
}
};
});
}).call(this);
(function() {
angular.module('Tasks').directive('timepicker', function() {
return {
@ -1204,7 +1251,7 @@
task.calendarID = _$scope.route.listID;
}
_tasksbusinesslayer.addTask(task, function(data) {
_$tasksmodel.add(data.task);
_$tasksmodel.add(data);
return _$scope.isAddingTask = false;
}, function() {
return _$scope.isAddingTask = false;

View file

@ -17,6 +17,7 @@ class TasksService {
* @param string $listID
* @param string $type
* @return array
* @throws \Exception
*/
public function getAll($listID = 'all', $type = 'all'){
@ -43,32 +44,28 @@ class TasksService {
if(!($vtodo = Helper::parseVTODO($task))){
continue;
}
try {
$task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone, $calendar['id']);
switch($type){
case 'all':
$task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone, $calendar['id']);
switch($type){
case 'all':
$tasks[] = $task_data;
break;
case 'init':
if (!$task_data['completed']){
$tasks[] = $task_data;
break;
case 'init':
if (!$task_data['completed']){
$tasks[] = $task_data;
} else {
$tasks_selected[] = $task_data;
}
break;
case 'completed':
if ($task_data['completed']){
$tasks[] = $task_data;
}
break;
case 'uncompleted':
if (!$task_data['completed']){
$tasks[] = $task_data;
}
break;
}
} catch(\Exception $e) {
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
} else {
$tasks_selected[] = $task_data;
}
break;
case 'completed':
if ($task_data['completed']){
$tasks[] = $task_data;
}
break;
case 'uncompleted':
if (!$task_data['completed']){
$tasks[] = $task_data;
}
break;
}
}
$nrCompleted = 0;
@ -98,6 +95,7 @@ class TasksService {
*
* @param string $taskID
* @return array
* @throws \Exception
*/
public function get($taskID){
$object = \OC_Calendar_App::getEventObject($taskID);
@ -105,17 +103,11 @@ class TasksService {
$task = array();
if($object['objecttype']=='VTODO' && !is_null($object['summary'])) {
if($vtodo = Helper::parseVTODO($object)){
try {
$task_data = Helper::arrayForJSON($object['id'], $vtodo, $user_timezone, $object['calendarid']);
$task[] = $task_data;
} catch(\Exception $e) {
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
}
$task_data = Helper::arrayForJSON($object['id'], $vtodo, $user_timezone, $object['calendarid']);
$task[] = $task_data;
}
}
return array(
'tasks' => $task
);
return $task;
}
/**
@ -146,9 +138,7 @@ class TasksService {
$task = Helper::arrayForJSON($taskID, $vcalendar->VTODO, $user_timezone, $calendarId);
$task['tmpID'] = $tmpID;
return array(
'task' => $task
);
return $task;
}
/**
@ -166,17 +156,13 @@ class TasksService {
* @param int $taskID
* @param string $name
* @return bool
* @throws \Exception
*/
public function setName($taskID, $name) {
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->SUMMARY = $name;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
}
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->SUMMARY = $name;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -185,18 +171,14 @@ class TasksService {
* @param int $taskID
* @param int $calendarID
* @return bool
* @throws \Exception
*/
public function setCalendarId($taskID, $calendarID) {
try {
$data = \OC_Calendar_App::getEventObject($taskID);
if ($data['calendarid'] != $calendarID) {
return \OC_Calendar_Object::moveToCalendar($taskID, $calendarID);
} else {
return true;
}
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
$data = \OC_Calendar_App::getEventObject($taskID);
if ($data['calendarid'] != $calendarID) {
return \OC_Calendar_Object::moveToCalendar($taskID, $calendarID);
} else {
return true;
}
}
@ -206,30 +188,27 @@ class TasksService {
* @param int $taskID
* @param int $percent_complete
* @return bool
* @throws \Exception
*/
public function setPercentComplete($taskID, $percent_complete) {
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if (!empty($percent_complete)) {
$vtodo->{'PERCENT-COMPLETE'} = $percent_complete;
}else{
unset($vtodo->{'PERCENT-COMPLETE'});
}
if ($percent_complete == 100) {
$vtodo->STATUS = 'COMPLETED';
$vtodo->COMPLETED = new \DateTime('now', new \DateTimeZone('UTC'));
} elseif ($percent_complete != 0) {
$vtodo->STATUS = 'IN-PROCESS';
unset($vtodo->COMPLETED);
} else{
$vtodo->STATUS = 'NEEDS-ACTION';
unset($vtodo->COMPLETED);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch(\Exception $e) {
return false;// throw new BusinessLayerException($e->getMessage());
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if (!empty($percent_complete)) {
$vtodo->{'PERCENT-COMPLETE'} = $percent_complete;
}else{
unset($vtodo->{'PERCENT-COMPLETE'});
}
if ($percent_complete == 100) {
$vtodo->STATUS = 'COMPLETED';
$vtodo->COMPLETED = new \DateTime('now', new \DateTimeZone('UTC'));
} elseif ($percent_complete != 0) {
$vtodo->STATUS = 'IN-PROCESS';
unset($vtodo->COMPLETED);
} else{
$vtodo->STATUS = 'NEEDS-ACTION';
unset($vtodo->COMPLETED);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -238,20 +217,17 @@ class TasksService {
* @param int $taskID
* @param int $priority
* @return bool
* @throws \Exception
*/
public function setPriority($taskID, $priority){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if($priority){
$vtodo->PRIORITY = (10 - $priority) % 10;
}else{
unset($vtodo->{'PRIORITY'});
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch(\Exception $e) {
return false;// throw new BusinessLayerException($e->getMessage());
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if($priority){
$vtodo->PRIORITY = (10 - $priority) % 10;
}else{
unset($vtodo->{'PRIORITY'});
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -260,45 +236,38 @@ class TasksService {
* @param int $taskID
* @param mixed $dueDate
* @return bool
* @throws \Exception
*/
public function setDueDate($taskID, $dueDate) {
try{
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if ($dueDate != false) {
$timezone = \OC_Calendar_App::getTimezone();
$timezone = new \DateTimeZone($timezone);
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if ($dueDate != false) {
$timezone = \OC_Calendar_App::getTimezone();
$timezone = new \DateTimeZone($timezone);
$dueDate = new \DateTime('@'.$dueDate);
$dueDate->setTimezone($timezone);
$vtodo->DUE = $dueDate;
} else {
unset($vtodo->DUE);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch (\Exception $e) {
return false;
$dueDate = new \DateTime('@'.$dueDate);
$dueDate->setTimezone($timezone);
$vtodo->DUE = $dueDate;
} else {
unset($vtodo->DUE);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
public function setStartDate($taskID, $startDate) {
try{
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if ($startDate != false) {
$timezone = \OC_Calendar_App::getTimezone();
$timezone = new \DateTimeZone($timezone);
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if ($startDate != false) {
$timezone = \OC_Calendar_App::getTimezone();
$timezone = new \DateTimeZone($timezone);
$startDate = new \DateTime('@'.$startDate);
$startDate->setTimezone($timezone);
$vtodo->DTSTART = $startDate;
} else {
unset($vtodo->DTSTART);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch (\Exception $e) {
return false;
$startDate = new \DateTime('@'.$startDate);
$startDate->setTimezone($timezone);
$vtodo->DTSTART = $startDate;
} else {
unset($vtodo->DTSTART);
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -315,6 +284,7 @@ class TasksService {
* @param mixed $minute
* @param mixed $second
* @return bool
* @throws \Exception
*/
public function setReminderDate($taskID, $type, $action, $date, $invert, $related = null, $week, $day, $hour, $minute, $second){
$types = array('DATE-TIME','DURATION');
@ -330,57 +300,53 @@ class TasksService {
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
elseif (in_array($type,$types)) {
try{
if($valarm == null) {
$valarm = $vcalendar->createComponent('VALARM');
$valarm->ACTION = $action;
$valarm->DESCRIPTION = 'Default Event Notification';
$vtodo->add($valarm);
} else {
unset($valarm->TRIGGER);
}
$tv = '';
if ($type == 'DATE-TIME') {
$date = new \DateTime('@'.$date);
$tv = $date->format('Ymd\THis\Z');
} elseif ($type == 'DURATION') {
// Create duration string
if($week || $day || $hour || $minute || $second) {
if ($invert){
$tv.='-';
}
$tv.='P';
if ($week){
$tv.=$week.'W';
}
if ($day){
$tv.=$day.'D';
}
$tv.='T';
if ($hour){
$tv.=$hour.'H';
}
if ($minute){
$tv.=$minute.'M';
}
if ($second){
$tv.=$second.'S';
}
}else{
$tv = 'PT0S';
}
}
if($related == 'END'){
$valarm->add('TRIGGER', $tv, array('VALUE' => $type, 'RELATED' => $related));
} else {
$valarm->add('TRIGGER', $tv, array('VALUE' => $type));
}
$vtodo->{'LAST-MODIFIED'}->setValue(new \DateTime('now', new \DateTimeZone('UTC')));
$vtodo->DTSTAMP = new \DateTime('now', new \DateTimeZone('UTC'));
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch (\Exception $e) {
return false;
if($valarm == null) {
$valarm = $vcalendar->createComponent('VALARM');
$valarm->ACTION = $action;
$valarm->DESCRIPTION = 'Default Event Notification';
$vtodo->add($valarm);
} else {
unset($valarm->TRIGGER);
}
$tv = '';
if ($type == 'DATE-TIME') {
$date = new \DateTime('@'.$date);
$tv = $date->format('Ymd\THis\Z');
} elseif ($type == 'DURATION') {
// Create duration string
if($week || $day || $hour || $minute || $second) {
if ($invert){
$tv.='-';
}
$tv.='P';
if ($week){
$tv.=$week.'W';
}
if ($day){
$tv.=$day.'D';
}
$tv.='T';
if ($hour){
$tv.=$hour.'H';
}
if ($minute){
$tv.=$minute.'M';
}
if ($second){
$tv.=$second.'S';
}
}else{
$tv = 'PT0S';
}
}
if($related == 'END'){
$valarm->add('TRIGGER', $tv, array('VALUE' => $type, 'RELATED' => $related));
} else {
$valarm->add('TRIGGER', $tv, array('VALUE' => $type));
}
$vtodo->{'LAST-MODIFIED'}->setValue(new \DateTime('now', new \DateTimeZone('UTC')));
$vtodo->DTSTAMP = new \DateTime('now', new \DateTimeZone('UTC'));
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
}
@ -389,28 +355,24 @@ class TasksService {
* @param int $taskID
* @param string $category
* @return bool
* @throws \Exception
*/
public function addCategory($taskID, $category){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
// fetch categories from TODO
$categories = $vtodo->CATEGORIES;
$taskcategories = array();
if ($categories){
$taskcategories = $categories->getParts();
}
// add category
if (!in_array($category, $taskcategories)){
$taskcategories[] = $category;
$vtodo->CATEGORIES = $taskcategories;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} else {
return true;
}
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
// fetch categories from TODO
$categories = $vtodo->CATEGORIES;
$taskcategories = array();
if ($categories){
$taskcategories = $categories->getParts();
}
// add category
if (!in_array($category, $taskcategories)){
$taskcategories[] = $category;
$vtodo->CATEGORIES = $taskcategories;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} else {
return true;
}
}
@ -419,30 +381,26 @@ class TasksService {
* @param int $taskID
* @param string $category
* @return bool
* @throws \Exception
*/
public function removeCategory($taskID, $category){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
// fetch categories from TODO
$categories = $vtodo->CATEGORIES;
if ($categories){
$taskcategories = $categories->getParts();
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
// fetch categories from TODO
$categories = $vtodo->CATEGORIES;
if ($categories){
$taskcategories = $categories->getParts();
}
// remove category
$key = array_search($category, $taskcategories);
if ($key !== null && $key !== false){
unset($taskcategories[$key]);
if(count($taskcategories)){
$vtodo->CATEGORIES = $taskcategories;
} else{
unset($vtodo->{'CATEGORIES'});
}
// remove category
$key = array_search($category, $taskcategories);
if ($key !== null && $key !== false){
unset($taskcategories[$key]);
if(count($taskcategories)){
$vtodo->CATEGORIES = $taskcategories;
} else{
unset($vtodo->{'CATEGORIES'});
}
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
}
@ -451,17 +409,13 @@ class TasksService {
* @param int $taskID
* @param string $location
* @return bool
* @throws \Exception
*/
public function setLocation($taskID, $location){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->LOCATION = $location;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
}
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->LOCATION = $location;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -470,17 +424,13 @@ class TasksService {
* @param int $taskID
* @param string $description
* @return bool
* @throws \Exception
*/
public function setDescription($taskID, $description){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->DESCRIPTION = $description;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
}
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vtodo->DESCRIPTION = $description;
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}
/**
@ -489,47 +439,44 @@ class TasksService {
* @param string $comment
* @param int $tmpID
* @return array
* @throws \Exception
*/
public function addComment($taskID, $comment, $tmpID){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
if($vtodo->COMMENT == "") {
// if this is the first comment set the id to 0
$commentId = 0;
} else {
// Determine new commentId by looping through all comments
$commentIds = array();
foreach($vtodo->COMMENT as $com) {
$commentIds[] = (int)$com['X-OC-ID']->getValue();
}
$commentId = 1+max($commentIds);
if($vtodo->COMMENT == "") {
// if this is the first comment set the id to 0
$commentId = 0;
} else {
// Determine new commentId by looping through all comments
$commentIds = array();
foreach($vtodo->COMMENT as $com) {
$commentIds[] = (int)$com['X-OC-ID']->getValue();
}
$now = new \DateTime();
$vtodo->add('COMMENT',$comment,
array(
'X-OC-ID' => $commentId,
'X-OC-USERID' => $this->userId,
'X-OC-DATE-TIME' => $now->format('Ymd\THis\Z')
)
);
\OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
$user_timezone = \OC_Calendar_App::getTimezone();
$now->setTimezone(new \DateTimeZone($user_timezone));
$comment = array(
'taskID' => $taskID,
'id' => $commentId,
'tmpID' => $tmpID,
'name' => \OCP\User::getDisplayName(),
'userID' => $this->userId,
'comment' => $comment,
'time' => $now->format('Ymd\THis')
);
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
$commentId = 1+max($commentIds);
}
$now = new \DateTime();
$vtodo->add('COMMENT',$comment,
array(
'X-OC-ID' => $commentId,
'X-OC-USERID' => $this->userId,
'X-OC-DATE-TIME' => $now->format('Ymd\THis\Z')
)
);
\OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
$user_timezone = \OC_Calendar_App::getTimezone();
$now->setTimezone(new \DateTimeZone($user_timezone));
$comment = array(
'taskID' => $taskID,
'id' => $commentId,
'tmpID' => $tmpID,
'name' => \OCP\User::getDisplayName(),
'userID' => $this->userId,
'comment' => $comment,
'time' => $now->format('Ymd\THis')
);
return $comment;
}
@ -538,24 +485,19 @@ class TasksService {
* @param int $taskID
* @param int $commentID
* @return bool
* @throws \Exception
*/
public function deleteComment($taskID, $commentID){
try {
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$commentIndex = $this->getCommentById($vtodo,$commentID);
$comment = $vtodo->children[$commentIndex];
if($comment['X-OC-USERID']->getValue() == $this->userId){
unset($vtodo->children[$commentIndex]);
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
}else{
throw new \Exception('Not allowed.');
}
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
return false;
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
$vtodo = $vcalendar->VTODO;
$commentIndex = $this->getCommentById($vtodo,$commentID);
$comment = $vtodo->children[$commentIndex];
if($comment['X-OC-USERID']->getValue() == $this->userId){
unset($vtodo->children[$commentIndex]);
return \OC_Calendar_Object::edit($taskID, $vcalendar->serialize());
} else {
throw new \Exception('Not allowed.');
}
return $response;
}