Remove server side CalDAV stuff
This commit is contained in:
parent
9becb0831e
commit
2868021064
23 changed files with 25 additions and 2205 deletions
|
@ -22,24 +22,18 @@
|
|||
|
||||
namespace OCA\Tasks\AppInfo;
|
||||
|
||||
if(\OCP\App::isEnabled('calendar')) {
|
||||
\OC::$server->getNavigationManager()->add(function () {
|
||||
$urlGenerator = \OC::$server->getURLGenerator();
|
||||
return [
|
||||
'id' => 'tasks',
|
||||
\OC::$server->getNavigationManager()->add(function () {
|
||||
$urlGenerator = \OC::$server->getURLGenerator();
|
||||
return [
|
||||
'id' => 'tasks',
|
||||
|
||||
'order' => 100,
|
||||
'order' => 100,
|
||||
|
||||
'href' => $urlGenerator->linkToRoute('tasks.page.index'),
|
||||
'href' => $urlGenerator->linkToRoute('tasks.page.index'),
|
||||
|
||||
'icon' => $urlGenerator->imagePath('tasks', 'tasks.svg'),
|
||||
'icon' => $urlGenerator->imagePath('tasks', 'tasks.svg'),
|
||||
|
||||
'name' => \OC::$server->getL10N('tasks')->t('Tasks'),
|
||||
];
|
||||
});
|
||||
\OC::$server->getSearch()->registerProvider('OCA\Tasks\Controller\SearchProvider', array('apps' => array('tasks')));
|
||||
} else {
|
||||
$msg = 'Can not enable the Tasks app because the Calendar App is disabled.';
|
||||
\OCP\Util::addScript('tasks', 'calendar-missing');
|
||||
\OCP\Util::writeLog('tasks', $msg, \OCP\Util::ERROR);
|
||||
}
|
||||
'name' => \OC::$server->getL10N('tasks')->t('Tasks'),
|
||||
];
|
||||
});
|
||||
\OC::$server->getSearch()->registerProvider('OCA\Tasks\Controller\SearchProvider', array('apps' => array('tasks')));
|
||||
|
|
|
@ -25,19 +25,9 @@ namespace OCA\Tasks\AppInfo;
|
|||
use \OCP\AppFramework\App;
|
||||
use \OCA\Tasks\Controller\PageController;
|
||||
use \OCA\Tasks\Controller\CollectionsController;
|
||||
use \OCA\Tasks\Controller\ListsController;
|
||||
use \OCA\Tasks\Controller\SettingsController;
|
||||
use \OCA\Tasks\Controller\TasksController;
|
||||
use \OCA\Tasks\Service\TasksService;
|
||||
use \OCA\Tasks\Service\ListsService;
|
||||
use \OCA\Tasks\Service\CollectionsService;
|
||||
use \OCA\Tasks\Service\SettingsService;
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
use \OCA\Tasks\Service\MapperHelper;
|
||||
use \OCA\Tasks\Service\TaskParser;
|
||||
use \OCA\Tasks\Service\ReminderService;
|
||||
use \OCA\Tasks\Service\CommentsService;
|
||||
use \OCA\Tasks\Db\TasksMapper;
|
||||
|
||||
class Application extends App {
|
||||
|
||||
|
@ -66,14 +56,6 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$container->registerService('ListsController', function($c) {
|
||||
return new ListsController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('ListsService')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('SettingsController', function($c) {
|
||||
return new SettingsController(
|
||||
$c->query('AppName'),
|
||||
|
@ -82,35 +64,9 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$container->registerService('TasksController', function($c) {
|
||||
return new TasksController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->query('TasksService'),
|
||||
$c->query('ReminderService'),
|
||||
$c->query('CommentsService')
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Services
|
||||
*/
|
||||
$container->registerService('TasksService', function($c) {
|
||||
return new TasksService(
|
||||
$c->query('UserId'),
|
||||
$c->query('TasksMapper'),
|
||||
$c->query('MapperHelper'),
|
||||
$c->query('Helper'),
|
||||
$c->query('TaskParser')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ListsService', function($c) {
|
||||
return new ListsService(
|
||||
$c->query('UserId')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('CollectionsService', function($c) {
|
||||
return new CollectionsService(
|
||||
|
@ -129,39 +85,6 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$container->registerService('MapperHelper', function($c) {
|
||||
return new MapperHelper(
|
||||
$c->query('TasksMapper'),
|
||||
$c->query('Helper'),
|
||||
$c->query('TaskParser')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('TaskParser', function($c) {
|
||||
return new TaskParser(
|
||||
$c->query('ReminderService'),
|
||||
$c->query('Helper')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('ReminderService', function($c) {
|
||||
return new ReminderService(
|
||||
$c->query('Helper')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('CommentsService', function($c) {
|
||||
return new CommentsService(
|
||||
$c->query('UserId'),
|
||||
$c->query('Helper')
|
||||
);
|
||||
});
|
||||
|
||||
$container->registerService('Helper', function() {
|
||||
return new Helper(
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Core
|
||||
*/
|
||||
|
@ -178,17 +101,5 @@ class Application extends App {
|
|||
$container->registerService('Settings', function($c) {
|
||||
return $c->query('ServerContainer')->getConfig();
|
||||
});
|
||||
|
||||
/**
|
||||
* Database Layer
|
||||
*/
|
||||
$container->registerService('TasksMapper', function($c) {
|
||||
return new TasksMapper(
|
||||
$c->query('ServerContainer')->getDb()
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
<info>
|
||||
<id>tasks</id>
|
||||
<name>Tasks</name>
|
||||
<version>0.8.1</version>
|
||||
<version>0.9.0</version>
|
||||
<namespace>Tasks</namespace>
|
||||
<category>productivity</category>
|
||||
<licence>AGPL</licence>
|
||||
<author>Raimund Schlüßler</author>
|
||||
<requiremin>8.1</requiremin>
|
||||
<requiremin>9.0</requiremin>
|
||||
<description>Task App for Calender TODOs</description>
|
||||
<ocsid>164356</ocsid>
|
||||
<dependencies>
|
||||
<owncloud min-version="8.1" max-version="9.0"/>
|
||||
<owncloud min-version="9.0" max-version="9.2"/>
|
||||
</dependencies>
|
||||
</info>
|
||||
|
|
|
@ -35,33 +35,6 @@ $application->registerRoutes($this, array('routes' => array(
|
|||
array('name' => 'collections#getCollections', 'url' => '/collections', 'verb' => 'GET'),
|
||||
array('name' => 'collections#setVisibility', 'url' => '/collection/{collectionID}/visibility/{visibility}', 'verb' => 'POST'),
|
||||
|
||||
// lists
|
||||
array('name' => 'lists#getLists', 'url' => '/lists', 'verb' => 'GET'),
|
||||
array('name' => 'lists#addList', 'url' => '/lists/add', 'verb' => 'POST'),
|
||||
array('name' => 'lists#deleteList', 'url' => '/lists/{listID}/delete', 'verb' => 'POST'),
|
||||
array('name' => 'lists#setListName','url' => '/lists/{listID}/name', 'verb' => 'POST'),
|
||||
|
||||
// tasks
|
||||
array('name' => 'tasks#getTasks', 'url' => '/tasks/{type}/{listID}', 'verb' => 'GET'),
|
||||
array('name' => 'tasks#getTask', 'url' => '/task/{taskID}', 'verb' => 'GET'),
|
||||
array('name' => 'tasks#addTask', 'url' => '/tasks/add', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#deleteTask', 'url' => '/tasks/{taskID}/delete', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setTaskName', 'url' => '/tasks/{taskID}/name', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setTaskCalendar','url' => '/tasks/{taskID}/calendar', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setTaskNote', 'url' => '/tasks/{taskID}/note', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setDueDate', 'url' => '/tasks/{taskID}/due', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setStartDate', 'url' => '/tasks/{taskID}/start', 'verb' => 'POST'),
|
||||
|
||||
array('name' => 'tasks#percentComplete','url' => '/tasks/{taskID}/percentcomplete', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setPriority', 'url' => '/tasks/{taskID}/priority', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setReminderDate','url' => '/tasks/{taskID}/reminder', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#addComment', 'url' => '/tasks/{taskID}/comment', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#deleteComment', 'url' => '/tasks/{taskID}/comment/{commentID}/delete', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#addCategory', 'url' => '/tasks/{taskID}/category/add', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#removeCategory', 'url' => '/tasks/{taskID}/category/remove', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#setHideSubtasks','url' => '/tasks/{taskID}/hidesubtasks', 'verb' => 'POST'),
|
||||
array('name' => 'tasks#changeParent', 'url' => '/tasks/{taskID}/parent', 'verb' => 'POST'),
|
||||
|
||||
// settings
|
||||
array('name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'),
|
||||
array('name' => 'settings#set', 'url' => '/settings/{type}/{setting}/{value}', 'verb' => 'POST'),
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
$installedVersionTasks=OCP\Config::getAppValue('tasks', 'installed_version');
|
||||
$installedVersionTasksEnhanced=OCP\Config::getAppValue('tasks_enhanced', 'installed_version');
|
||||
|
||||
\OC::$CLASSPATH['OC_Calendar_Calendar'] = 'calendar/lib/calendar.php';
|
||||
\OC::$CLASSPATH['OC_Calendar_Object'] = 'calendar/lib/object.php';
|
||||
|
||||
if ( version_compare($installedVersionTasksEnhanced, '0.4.1', '<=') && version_compare($installedVersionTasks, '0.5.0', '<=') ) {
|
||||
try {
|
||||
|
||||
$stmt = \OCP\DB::prepare( 'SELECT * FROM `*PREFIX*clndr_calendars`');
|
||||
$result = $stmt->execute();
|
||||
|
||||
$calendars = array();
|
||||
while( $row = $result->fetchRow()) {
|
||||
$calendars[] = $row;
|
||||
}
|
||||
|
||||
foreach( $calendars as $calendar ) {
|
||||
$calendar_entries = \OC_Calendar_Object::all($calendar['id']);
|
||||
|
||||
foreach( $calendar_entries as $task ) {
|
||||
if($task['objecttype']!='VTODO') {
|
||||
continue;
|
||||
}
|
||||
$vcalendar = \Sabre\VObject\Reader::read($task['calendardata']);
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
$children = $vtodo->children;
|
||||
$taskId = $task['id'];
|
||||
|
||||
$comments = $vtodo->COMMENT;
|
||||
if($comments){
|
||||
foreach($comments as $com) {
|
||||
|
||||
$idx = 0;
|
||||
foreach ($children as $i => &$property) {
|
||||
if ( $property['ID'] && $com['ID']) {
|
||||
if ( $property->name == 'COMMENT' && $property['ID']->getValue() == (int)$com['ID']->getValue() ) {
|
||||
unset($vtodo->children[$idx]);
|
||||
}
|
||||
}
|
||||
$idx += 1;
|
||||
}
|
||||
if ( $com['ID'] && $com['USERID'] && $com['DATE-TIME'] ) {
|
||||
$vtodo->add('COMMENT',$com->getValue(),
|
||||
array(
|
||||
'X-OC-ID' => (int)$com['ID']->getValue(),
|
||||
'X-OC-USERID' => $com['USERID']->getValue(),
|
||||
'X-OC-DATE-TIME' => $com['DATE-TIME']->getValue()
|
||||
)
|
||||
);
|
||||
}
|
||||
OCP\Util::emitHook('OC_Calendar', 'editEvent', $taskId);
|
||||
}
|
||||
$data = $vcalendar->serialize();
|
||||
$oldobject = \OC_Calendar_Object::find($taskId);
|
||||
|
||||
$object = \Sabre\VObject\Reader::read($data);
|
||||
|
||||
$type = 'VTODO';
|
||||
$startdate = null;
|
||||
$enddate = null;
|
||||
$summary = '';
|
||||
$repeating = 0;
|
||||
$uid = null;
|
||||
|
||||
foreach($object->children as $property) {
|
||||
if($property->name == 'VTODO') {
|
||||
foreach($property->children as &$element) {
|
||||
if($element->name == 'SUMMARY') {
|
||||
$summary = $element->getValue();
|
||||
}
|
||||
elseif($element->name == 'UID') {
|
||||
$uid = $element->getValue();
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*clndr_objects` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ? WHERE `id` = ?' );
|
||||
$stmt->execute(array($type,$startdate,$enddate,$repeating,$summary,$data,time(),$taskId));
|
||||
|
||||
\OC_Calendar_Calendar::touchCalendar($oldobject['calendarid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e){
|
||||
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Controller;
|
||||
|
||||
use \OCA\Tasks\Service\ListsService;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Controller;
|
||||
|
||||
class ListsController extends Controller {
|
||||
|
||||
private $listsService;
|
||||
|
||||
use Response;
|
||||
|
||||
public function __construct($appName, IRequest $request, ListsService $listsService){
|
||||
parent::__construct($appName, $request);
|
||||
$this->listsService = $listsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getLists(){
|
||||
return $this->generateResponse(function () {
|
||||
return ['lists' => $this->listsService->getAll()];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addList($name, $tmpID){
|
||||
return $this->generateResponse(function () use ($name, $tmpID) {
|
||||
return ['list' => $this->listsService->add($name, $tmpID)];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteList($listID){
|
||||
return $this->generateResponse(function () use ($listID) {
|
||||
return $this->listsService->delete($listID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setListName($listID, $name){
|
||||
return $this->generateResponse(function () use ($listID, $name) {
|
||||
return $this->listsService->setName($listID, $name);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -57,8 +57,7 @@ class PageController extends Controller {
|
|||
\OCP\Util::addStyle('tasks', 'style');
|
||||
\OCP\Util::addStyle('tasks', 'vendor/angularui/ui-select/select2');
|
||||
|
||||
$date = new \DateTimeZone(\OC_Calendar_App::getTimezone());
|
||||
$day = new \DateTime('today', $date);
|
||||
$day = new \DateTime('today');
|
||||
$day = $day->format('d');
|
||||
|
||||
// TODO: Make a HTMLTemplateResponse class
|
||||
|
|
|
@ -29,13 +29,13 @@ use OCA\Tasks\AppInfo\Application;
|
|||
*/
|
||||
class SearchProvider extends \OCP\Search\Provider {
|
||||
|
||||
private $tasksService;
|
||||
// private $tasksService;
|
||||
|
||||
public function __construct() {
|
||||
$app = new Application();
|
||||
$container = $app->getContainer();
|
||||
$this->app = $app;
|
||||
$this->tasksService = $container->query('TasksService');
|
||||
// $this->tasksService = $container->query('TasksService');
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,6 @@ class SearchProvider extends \OCP\Search\Provider {
|
|||
* @return array
|
||||
*/
|
||||
public function search($query) {
|
||||
return $this->tasksService->search($query);
|
||||
// return $this->tasksService->search($query);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,217 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Controller;
|
||||
|
||||
use \OCA\Tasks\Service\TasksService;
|
||||
use \OCA\Tasks\Service\ReminderService;
|
||||
use \OCA\Tasks\Service\CommentsService;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\AppFramework\Controller;
|
||||
|
||||
|
||||
class TasksController extends Controller {
|
||||
|
||||
private $tasksService;
|
||||
private $reminderService;
|
||||
private $commentsService;
|
||||
|
||||
use Response;
|
||||
|
||||
public function __construct($appName, IRequest $request, TasksService $tasksService, ReminderService $reminderService, CommentsService $commentsService){
|
||||
parent::__construct($appName, $request);
|
||||
$this->tasksService = $tasksService;
|
||||
$this->reminderService = $reminderService;
|
||||
$this->commentsService = $commentsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getTasks($listID = 'all', $type = 'all'){
|
||||
return $this->generateResponse(function () use ($listID, $type) {
|
||||
return $this->tasksService->getAll($listID, $type);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getTask($taskID){
|
||||
return $this->generateResponse(function () use ($taskID) {
|
||||
return $this->tasksService->getTask($taskID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setPriority($taskID,$priority){
|
||||
return $this->generateResponse(function () use ($taskID, $priority) {
|
||||
return $this->tasksService->setPriority($taskID, $priority);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setHideSubtasks($taskID,$hide){
|
||||
return $this->generateResponse(function () use ($taskID, $hide) {
|
||||
return $this->tasksService->hideSubtasks($taskID, $hide);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function changeParent($taskID,$related){
|
||||
return $this->generateResponse(function () use ($taskID, $related) {
|
||||
return $this->tasksService->parent($taskID, $related);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function percentComplete($taskID, $complete){
|
||||
return $this->generateResponse(function () use ($taskID, $complete) {
|
||||
return $this->tasksService->setPercentComplete($taskID, $complete);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addTask($name, $related, $calendarID, $starred, $due, $start, $tmpID){
|
||||
return $this->generateResponse(function () use ($name, $related, $calendarID, $starred, $due, $start, $tmpID) {
|
||||
return $this->tasksService->add($name, $related, $calendarID, $starred, $due, $start, $tmpID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteTask($taskID){
|
||||
return $this->generateResponse(function () use ($taskID) {
|
||||
return $this->tasksService->delete($taskID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setTaskName($taskID, $name){
|
||||
return $this->generateResponse(function () use ($taskID, $name) {
|
||||
return $this->tasksService->setName($taskID, $name);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setTaskCalendar($taskID, $calendarID){
|
||||
return $this->generateResponse(function () use ($taskID, $calendarID) {
|
||||
return $this->tasksService->setCalendarId($taskID, $calendarID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setTaskNote($taskID, $note){
|
||||
return $this->generateResponse(function () use ($taskID, $note) {
|
||||
return $this->tasksService->setDescription($taskID, $note);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setDueDate($taskID, $due){
|
||||
return $this->generateResponse(function () use ($taskID, $due) {
|
||||
return $this->tasksService->setDueDate($taskID, $due);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setStartDate($taskID, $start){
|
||||
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){
|
||||
return $this->generateResponse(function () use ($taskID, $type, $action, $date, $invert, $related, $week, $day, $hour, $minute, $second) {
|
||||
return $this->reminderService->createReminder($taskID, $type, $action, $date, $invert, $related, $week, $day, $hour, $minute, $second);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addCategory($taskID, $category){
|
||||
return $this->generateResponse(function () use ($taskID, $category) {
|
||||
return $this->tasksService->addCategory($taskID, $category);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function removeCategory($taskID, $category){
|
||||
return $this->generateResponse(function () use ($taskID, $category) {
|
||||
return $this->tasksService->removeCategory($taskID, $category);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setLocation($taskID, $location){
|
||||
return $this->generateResponse(function () use ($taskID, $location) {
|
||||
return $this->tasksService->setLocation($taskID, $location);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function addComment($taskID, $comment, $tmpID){
|
||||
return $this->generateResponse(function () use ($taskID, $comment, $tmpID) {
|
||||
return $this->commentsService->addComment($taskID, $comment, $tmpID);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteComment($taskID, $commentID){
|
||||
return $this->generateResponse(function () use ($taskID, $commentID) {
|
||||
return $this->commentsService->deleteComment($taskID, $commentID);
|
||||
});
|
||||
}
|
||||
}
|
42
db/tasks.php
42
db/tasks.php
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Db;
|
||||
|
||||
use \OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Tasks extends Entity {
|
||||
|
||||
public $calendarid;
|
||||
public $objecttype;
|
||||
public $startdate;
|
||||
public $enddate;
|
||||
public $repeating;
|
||||
public $summary;
|
||||
public $calendardata;
|
||||
public $uri;
|
||||
public $lastmodified;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('calendarid', 'integer');
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Db;
|
||||
|
||||
use OCP\IDb;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
|
||||
class TasksMapper extends Mapper {
|
||||
|
||||
public function __construct(IDb $db) {
|
||||
parent::__construct($db, 'tasks_tasks', '\OCA\Tasks\Db\Tasks');
|
||||
}
|
||||
|
||||
public function findAllVTODOs($calendarID, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*clndr_objects` WHERE `calendarid` = ? AND `objecttype`= ?';
|
||||
return $this->findEntities($sql, array($calendarID, 'VTODO'), $limit, $offset);
|
||||
}
|
||||
|
||||
public function findVTODOById($taskID, $limit=null, $offset=null) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*clndr_objects` WHERE `id` = ? AND `objecttype`= ?';
|
||||
return $this->findEntity($sql, array($taskID, 'VTODO'), $limit, $offset);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ You should have received a copy of the GNU Affero General Public
|
|||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
###
|
||||
angular.module('Tasks',['ngRoute','ngAnimate','ui.bootstrap','ui.select',
|
||||
angular.module('Tasks',['ngRoute','ngAnimate','ui.select',
|
||||
'ngSanitize', 'dndLists'])
|
||||
.config ['$provide','$routeProvider', '$interpolateProvider', '$httpProvider'
|
||||
($provide, $routeProvider, $interpolateProvider, $httpProvider) ->
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3
|
||||
* or later.
|
||||
*
|
||||
* See the COPYING-README file.
|
||||
*
|
||||
*/
|
||||
$(function(){
|
||||
$(document).ready(function () {
|
||||
OC.Notification.showTemporary(t('tasks', 'Tasks app is unavailable because the calendar is not installed'));
|
||||
});
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "task",
|
||||
"description": "ownCloud Task App",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"author": {
|
||||
"name": "Raimund Schlüßler",
|
||||
"email": "raimund.schluessler@googlemail.com"
|
||||
|
@ -16,6 +16,7 @@
|
|||
"contributors": [],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"bower": "*",
|
||||
"coffee-script": "~1.4.0",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-cli": "~0.1.6",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
(function(angular, $, moment, undefined){
|
||||
|
||||
/**
|
||||
* ownCloud Task App - v0.8.1
|
||||
* ownCloud Task App - v0.9.0
|
||||
*
|
||||
* Copyright (c) 2015 - Raimund Schlüßler <raimund.schluessler@googlemail.com>
|
||||
* Copyright (c) 2016 - Raimund Schlüßler <raimund.schluessler@googlemail.com>
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later.
|
||||
* See the COPYING file
|
||||
|
@ -12,7 +12,7 @@
|
|||
|
||||
|
||||
(function() {
|
||||
angular.module('Tasks', ['ngRoute', 'ngAnimate', 'ui.bootstrap', 'ui.select', 'ngSanitize', 'dndLists']).config([
|
||||
angular.module('Tasks', ['ngRoute', 'ngAnimate', 'ui.select', 'ngSanitize', 'dndLists']).config([
|
||||
'$provide', '$routeProvider', '$interpolateProvider', '$httpProvider', function($provide, $routeProvider, $interpolateProvider, $httpProvider) {
|
||||
var config;
|
||||
$provide.value('Config', config = {
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
|
||||
Class CommentsService {
|
||||
|
||||
private $userId;
|
||||
private $helper;
|
||||
|
||||
public function __construct($userId, Helper $helper){
|
||||
$this->userId = $userId;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* add comment to task by id
|
||||
* @param int $taskID
|
||||
* @param string $comment
|
||||
* @param int $tmpID
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addComment($taskID, $comment, $tmpID){
|
||||
$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);
|
||||
}
|
||||
|
||||
$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')
|
||||
)
|
||||
);
|
||||
$this->helper->editVCalendar($vcalendar, $taskID);
|
||||
$user_timezone = \OC_Calendar_App::getTimezone();
|
||||
$now->setTimezone(new \DateTimeZone($user_timezone));
|
||||
$comment = array(
|
||||
'taskID' => $taskID,
|
||||
'id' => $commentId,
|
||||
'tmpID' => $tmpID,
|
||||
'name' => \OC::$server->getUserManager()->get($this->userId)->getDisplayName(),
|
||||
'userID' => $this->userId,
|
||||
'comment' => $comment,
|
||||
'time' => $now->format('Ymd\THis')
|
||||
);
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete comment of task by id
|
||||
* @param int $taskID
|
||||
* @param int $commentID
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteComment($taskID, $commentID){
|
||||
$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 $this->helper->editVCalendar($vcalendar, $taskID);
|
||||
} else {
|
||||
throw new \Exception('Not allowed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sort get comment by ID
|
||||
*
|
||||
* @param object $vtodo
|
||||
* @param string $commentID
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getCommentById($vtodo,$commentID) {
|
||||
$idx = 0;
|
||||
foreach ($vtodo->children as $i => &$property) {
|
||||
if ( $property->name == 'COMMENT' && $property['X-OC-ID']->getValue() == $commentID ) {
|
||||
return $idx;
|
||||
}
|
||||
$idx += 1;
|
||||
}
|
||||
throw new \Exception('Commment not found.');
|
||||
}
|
||||
}
|
|
@ -1,323 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
Class Helper {
|
||||
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
/**
|
||||
* check if task is valid
|
||||
*
|
||||
* @param \OCA\Tasks\Db\Tasks $task
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkTask($task) {
|
||||
$object = $this->readTask($task);
|
||||
if(!$object){
|
||||
return false;
|
||||
}
|
||||
if(\OC_Calendar_Object::getowner($task->getId()) !== \OC::$server->getUserSession()->getUser()->getUID()){
|
||||
$sharedAccessClassPermissions = \OC_Calendar_Object::getAccessClassPermissions($object);
|
||||
if (!($sharedAccessClassPermissions & \OCP\Constants::PERMISSION_READ)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$taskID = $task->getId();
|
||||
$object = \OC_Calendar_Object::cleanByAccessClass($taskID, $object);
|
||||
$vtodo = $object->VTODO;
|
||||
$vtodo->ID = $taskID;
|
||||
return $vtodo;
|
||||
}
|
||||
|
||||
/**
|
||||
* read object from calendar data
|
||||
*
|
||||
* @param \OCA\Tasks\Db\Tasks $task
|
||||
* @return mixed
|
||||
*/
|
||||
private function readTask($task){
|
||||
if (is_null($task->getSummary())) {
|
||||
return false;
|
||||
}
|
||||
return \Sabre\VObject\Reader::read($task->getCalendardata());
|
||||
}
|
||||
|
||||
/**
|
||||
* select tasks
|
||||
*
|
||||
* @param array $tasks
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
public function selectTasks($tasks, $type) {
|
||||
$notLoaded = 0;
|
||||
switch($type){
|
||||
case 'init': // Only select uncompleted tasks and the five most recent completed ones
|
||||
$count = count($tasks);
|
||||
$tasks_completed = $this->selectCompletedTasks($tasks);
|
||||
usort($tasks_completed, array($this, 'sortCompletedDate'));
|
||||
$tasks = array_merge($this->selectUncompletedTasks($tasks), array_slice($tasks_completed,0,5));
|
||||
$notLoaded = $count - count($tasks);
|
||||
break;
|
||||
case 'completed':
|
||||
$tasks = $this->selectCompletedTasks($tasks);
|
||||
break;
|
||||
case 'uncompleted':
|
||||
$tasks = $this->selectUncompletedTasks($tasks);
|
||||
break;
|
||||
}
|
||||
return array($notLoaded, $tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* select completed tasks
|
||||
*
|
||||
* @param array $tasks
|
||||
* @return array
|
||||
*/
|
||||
private function selectCompletedTasks($tasks) {
|
||||
return array_filter($tasks, function($task) {
|
||||
return $task['completed'];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* select uncompleted tasks
|
||||
*
|
||||
* @param array $tasks
|
||||
* @return array
|
||||
*/
|
||||
private function selectUncompletedTasks($tasks) {
|
||||
return array_filter($tasks, function($task) {
|
||||
return !$task['completed'];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* set property of a task
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $property
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setProperty($taskID,$property,$value){
|
||||
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
if($value){
|
||||
$vtodo->{$property} = $value;
|
||||
}else{
|
||||
unset($vtodo->{$property});
|
||||
}
|
||||
return $this->editVCalendar($vcalendar, $taskID);
|
||||
}
|
||||
|
||||
/**
|
||||
* edit VCalendar and set modification dates
|
||||
*
|
||||
* @param mixed $vcalendar
|
||||
* @param string $taskID
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function editVCalendar($vcalendar, $taskID) {
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
* format date
|
||||
*
|
||||
* @param string $date
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function createDateFromUNIX($date) {
|
||||
if (!$date) {
|
||||
return null;
|
||||
}
|
||||
$timezone = \OC_Calendar_App::getTimezone();
|
||||
$date = new \DateTime('@'.$date);
|
||||
return $date->setTimezone(new \DateTimeZone($timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder string
|
||||
*
|
||||
* @param string $date
|
||||
* @return string
|
||||
*/
|
||||
public function parseDateString($date) {
|
||||
$date = new \DateTime($date);
|
||||
return $this->formatDate($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder object
|
||||
*
|
||||
* @param object $date
|
||||
* @param string $modifier
|
||||
* @return string
|
||||
*/
|
||||
public function parseDateObject($date, $modifier='+0 days') {
|
||||
if(!$date) {
|
||||
return null;
|
||||
}
|
||||
return $this->formatDate($date->getDateTime(), $modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* format date object
|
||||
*
|
||||
* @param object $date
|
||||
* @param string $modifier
|
||||
* @return string
|
||||
*/
|
||||
private function formatDate($date, $modifier='+0 days') {
|
||||
$user_timezone = \OC_Calendar_App::getTimezone();
|
||||
$date->setTimezone(new \DateTimeZone($user_timezone));
|
||||
return $date->modify($modifier)->format('Ymd\THis');
|
||||
}
|
||||
|
||||
/**
|
||||
* sort tasks
|
||||
*
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
* @return array
|
||||
*/
|
||||
public function sortCompletedDate($a, $b) {
|
||||
return $this->sort(\DateTime::createFromFormat('Ymd\THis', $b['completed_date']), \DateTime::createFromFormat('Ymd\THis', $a['completed_date']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sort tasks by completed
|
||||
*
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
* @return int
|
||||
*/
|
||||
public function sortCompleted($a, $b) {
|
||||
return $this->sort($a['completed'], $b['completed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* sort tasks by completed
|
||||
*
|
||||
* @param mixed $t1
|
||||
* @param mixed $t2
|
||||
* @return int
|
||||
*/
|
||||
public function sort($t1, $t2) {
|
||||
if ($t1 == $t2) {
|
||||
return 0;
|
||||
}
|
||||
return $t1 > $t2 ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* create calendar entry from request
|
||||
*
|
||||
* @param array $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function createVCalendar($request){
|
||||
$vcalendar = new \Sabre\VObject\Component\VCalendar();
|
||||
$vcalendar->PRODID = 'ownCloud Calendar';
|
||||
$vcalendar->VERSION = '2.0';
|
||||
|
||||
$vtodo = $vcalendar->createComponent('VTODO');
|
||||
$vcalendar->add($vtodo);
|
||||
|
||||
$vtodo->CREATED = new \DateTime('now', new \DateTimeZone('UTC'));
|
||||
|
||||
$vtodo->UID = \Sabre\VObject\UUIDUtil::getUUID();
|
||||
return $this->addVTODO($vcalendar, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* update task from request
|
||||
*
|
||||
* @param array $request
|
||||
* @param mixed $vcalendar
|
||||
* @return mixed
|
||||
*/
|
||||
public function addVTODO($vcalendar, $request){
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
$timezone = \OC_Calendar_App::getTimezone();
|
||||
$timezone = new \DateTimeZone($timezone);
|
||||
|
||||
$vtodo->{'LAST-MODIFIED'} = new \DateTime('now', new \DateTimeZone('UTC'));
|
||||
$vtodo->DTSTAMP = new \DateTime('now', new \DateTimeZone('UTC'));
|
||||
$vtodo->SUMMARY = $request['summary'];
|
||||
|
||||
if($request['starred']) {
|
||||
$vtodo->PRIORITY = 1; // prio: high
|
||||
}
|
||||
$due = $request['due'];
|
||||
if ($due) {
|
||||
$vtodo->DUE = new \DateTime($due, $timezone);
|
||||
}
|
||||
$start = $request['start'];
|
||||
if ($start) {
|
||||
$vtodo->DTSTART = new \DateTime($start, $timezone);
|
||||
}
|
||||
$related = $request['related'];
|
||||
if ($related) {
|
||||
$vtodo->{'RELATED-TO'} = $related;
|
||||
}
|
||||
|
||||
return $vcalendar;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if task contains query
|
||||
*
|
||||
* @param mixed $vtodo
|
||||
* @param string $query
|
||||
* @return array
|
||||
*/
|
||||
public function checkTaskByQuery($vtodo, $query) {
|
||||
// check these properties
|
||||
$properties = array('SUMMARY', 'DESCRIPTION', 'LOCATION', 'CATEGORIES', 'COMMENT');
|
||||
foreach ($properties as $property) {
|
||||
$strings = $vtodo->{$property};
|
||||
if ($strings) {
|
||||
foreach ($strings as $string) {
|
||||
$needle = $string->getValue();
|
||||
if (stripos($needle, $query) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
class ListsService {
|
||||
|
||||
private $userId;
|
||||
|
||||
public function __construct($userId) {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all calendars
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll() {
|
||||
return \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a list
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $tmpID
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add($name, $tmpID) {
|
||||
if(trim($name) == '') {
|
||||
throw new \Exception('An empty name is not allowed.');
|
||||
}
|
||||
if ($this->isListnameUsed($name)) {
|
||||
throw new \Exception('Calendar name already used.');
|
||||
}
|
||||
$color = '#CCCCCC';
|
||||
$listID = \OC_Calendar_Calendar::addCalendar($this->userId, strip_tags($name), 'VEVENT,VTODO,VJOURNAL', null, 0, $color);
|
||||
\OC_Calendar_Calendar::setCalendarActive($listID, 1);
|
||||
$list = \OC_Calendar_Calendar::find($listID);
|
||||
|
||||
$list['tmpID'] = $tmpID;
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete list by listID
|
||||
*
|
||||
* @param string $listID
|
||||
* @return array
|
||||
*/
|
||||
public function delete($listID) {
|
||||
$del = \OC_Calendar_Calendar::deleteCalendar($listID);
|
||||
if(!$del) {
|
||||
throw new \Exception('Calendar cannot be deleted.');
|
||||
}
|
||||
return array(
|
||||
'data' => array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* set name of list by listID
|
||||
*
|
||||
* @param string $listID
|
||||
* @param string $name
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setName($listID, $name) {
|
||||
if(trim($name) == '') {
|
||||
throw new \Exception('An empty name is not allowed.');
|
||||
}
|
||||
if ($this->isListnameUsed($name, $listID)) {
|
||||
throw new \Exception('Calendar name already used.');
|
||||
}
|
||||
$color = '#CCCCCC';
|
||||
\OC_Calendar_Calendar::editCalendar($listID, strip_tags($name), null, null, null, $color);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if list name is used by other list
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $listID
|
||||
* @return bool
|
||||
*/
|
||||
private function isListnameUsed($name, $listID=null) {
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
foreach($calendars as $cal) {
|
||||
if($cal['displayname'] == $name && $cal['id'] != $listID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
use \OCA\Tasks\Service\TaskParser;
|
||||
use \OCA\Tasks\Db\TasksMapper;
|
||||
|
||||
Class MapperHelper {
|
||||
|
||||
private $tasksMapper;
|
||||
private $helper;
|
||||
private $taskParser;
|
||||
|
||||
public function __construct(TasksMapper $tasksMapper, Helper $helper, TaskParser $taskParser){
|
||||
$this->tasksMapper = $tasksMapper;
|
||||
$this->helper = $helper;
|
||||
$this->taskParser = $taskParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a map of the tasks to find tasks by UID and RELATED-TO
|
||||
* checks the calendar entries and returns and array with two arrays as content:
|
||||
* [0] -> an array of the parsed tasks with the UIDs as keys
|
||||
* [1] -> an array of arrays containing the child UIDs with the parent UIDs as keys
|
||||
* [2] -> an array of the UIDs with the IDs as keys
|
||||
*
|
||||
* this function should be removed once the UID and the RELATED-TO property is directly stored in the database
|
||||
* and tasks can be found by querying the UID or RELATED-TO properties
|
||||
* TODO
|
||||
*
|
||||
* @param string $calendarID
|
||||
* @return array
|
||||
*/
|
||||
public function createTasksMap($calendarID) {
|
||||
$calendar_entries = $this->tasksMapper->findAllVTODOs($calendarID);
|
||||
$host = $this;
|
||||
$VTODOs = array_map(function($task) use ($host) {
|
||||
return $host->helper->checkTask($task);
|
||||
}, $calendar_entries);
|
||||
$VTODOs = array_filter($VTODOs);
|
||||
$tasks = array_map(function($task) use ($host, $calendarID) {
|
||||
return $host->taskParser->parseTask($task, $calendarID);
|
||||
},$VTODOs);
|
||||
|
||||
$mapUID = array();
|
||||
$mapRelatedTo = array();
|
||||
$mapID = array();
|
||||
foreach ($tasks as $task) {
|
||||
$mapUID[$task['uid']] = $task; // create UID map
|
||||
$mapID[$task['id']] = $task['uid']; // create ID map
|
||||
if ($task['related']) { // create RELATED-TO map
|
||||
$mapRelatedTo[$task['related']][] = $task['uid'];
|
||||
}
|
||||
}
|
||||
return array($mapUID, $mapRelatedTo, $mapID);
|
||||
}
|
||||
|
||||
/**
|
||||
* find a task by its UID
|
||||
*
|
||||
* currently needs the tasks Map created by $this->createTasksMap
|
||||
* has to find the task only by its UID by a database query once that's possible
|
||||
* TODO
|
||||
*
|
||||
* @param string $UID
|
||||
* @param array $tasksMap
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTaskByUID($UID, $tasksMap) {
|
||||
if (isset($tasksMap[0][$UID])) {
|
||||
return $tasksMap[0][$UID];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* find tasks by their parent UID
|
||||
*
|
||||
* currently needs the tasks Map created by $this->createTasksMap
|
||||
* has to find the tasks only by their RELATED-TO property by a database query once that's possible
|
||||
* TODO
|
||||
*
|
||||
* @param string $parentUID
|
||||
* @param array $tasksMap
|
||||
* @return array
|
||||
*/
|
||||
private function getTasksByParentUID($parentUID, $tasksMap) {
|
||||
$tasks = array();
|
||||
if (isset($tasksMap[1][$parentUID])){
|
||||
$UIDs = $tasksMap[1][$parentUID];
|
||||
foreach ($UIDs as $UID) {
|
||||
$task = $this->getTaskByUID($UID, $tasksMap);
|
||||
if ($task) {
|
||||
$tasks[] = $task;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* get tasks
|
||||
*
|
||||
* @param array $tasksMap
|
||||
* @param string $type
|
||||
* @param string $calendarID
|
||||
* @return array
|
||||
*/
|
||||
public function getRootTasks($tasksMap, $type, $calendarID) {
|
||||
$list = array(
|
||||
'id' => $calendarID,
|
||||
'notLoaded' => 0
|
||||
);
|
||||
$host = $this;
|
||||
$rootTasks = array_filter($tasksMap[0], function($task) use ($host, $tasksMap) {
|
||||
return $host->isRootTask($task, $tasksMap);
|
||||
});
|
||||
|
||||
list($list['notLoaded'], $rootTasks) = $this->helper->selectTasks($rootTasks, $type);
|
||||
return array($list, $rootTasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if root task
|
||||
*
|
||||
* @param array $task
|
||||
* @param array $tasksMap
|
||||
* @return bool
|
||||
*/
|
||||
private function isRootTask($task, $tasksMap) {
|
||||
if ($task['related']) {
|
||||
return !(bool) $this->getTaskByUID($task['related'], $tasksMap);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* find taskID of root task
|
||||
*
|
||||
* @param string $taskUID
|
||||
* @param array $tasksMap
|
||||
* @return string
|
||||
*/
|
||||
public function findRootUID($taskUID, $tasksMap) {
|
||||
$task = $this->getTaskByUID($taskUID, $tasksMap);
|
||||
if ($this->isRootTask($task, $tasksMap)) {
|
||||
return $taskUID;
|
||||
}
|
||||
$parent = $this->getTaskByUID($task['related'], $tasksMap);
|
||||
return $this->findRootUID($parent['uid'], $tasksMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* find taskUID by taskID
|
||||
*
|
||||
* @param string $taskID
|
||||
* @param array $tasksMap
|
||||
* @return string
|
||||
*/
|
||||
public function getUIDbyID($taskID, $tasksMap) {
|
||||
if (isset($tasksMap[2][$taskID])) {
|
||||
return $tasksMap[2][$taskID];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get child tasks by parentUID
|
||||
*
|
||||
* @param string $parentUID
|
||||
* @param array $tasksMap
|
||||
* @param bool $deep
|
||||
* @return array
|
||||
*/
|
||||
public function getChildTasks($parentUID, $tasksMap, $deep=true) {
|
||||
$childTasks = $this->getTasksByParentUID($parentUID, $tasksMap);
|
||||
if ($deep) {
|
||||
$subChildTasks = array();
|
||||
foreach ($childTasks as $childTask) {
|
||||
$subChildTasks = array_merge($subChildTasks, $this->getChildTasks($childTask['uid'], $tasksMap, $deep));
|
||||
}
|
||||
$childTasks = array_merge($childTasks, $subChildTasks);
|
||||
}
|
||||
return $childTasks;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
use Sabre\VObject;
|
||||
|
||||
Class ReminderService {
|
||||
|
||||
private $helper;
|
||||
|
||||
public function __construct(Helper $helper){
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* create reminder for task
|
||||
* @param int $taskID
|
||||
* @param string $type
|
||||
* @param mixed $action
|
||||
* @param mixed $date
|
||||
* @param bool $invert
|
||||
* @param string $related
|
||||
* @param mixed $week
|
||||
* @param mixed $day
|
||||
* @param mixed $hour
|
||||
* @param mixed $minute
|
||||
* @param mixed $second
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createReminder($taskID, $type, $action, $date, $invert, $related = null, $week, $day, $hour, $minute, $second) {
|
||||
$types = array('DATE-TIME','DURATION');
|
||||
$vcalendar = \OC_Calendar_App::getVCalendar($taskID);
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
$valarm = $vtodo->VALARM;
|
||||
|
||||
if (in_array($type,$types)) {
|
||||
if($valarm == null) {
|
||||
$valarm = $vcalendar->createComponent('VALARM');
|
||||
$valarm->ACTION = $action;
|
||||
$valarm->DESCRIPTION = 'Default Event Notification';
|
||||
$vtodo->add($valarm);
|
||||
} else {
|
||||
unset($valarm->TRIGGER);
|
||||
}
|
||||
$string = '';
|
||||
if ($type == 'DATE-TIME') {
|
||||
$string = $this->createReminderDateTime($date);
|
||||
} elseif ($type == 'DURATION') {
|
||||
$string = $this->createReminderDuration($week, $day, $hour, $minute, $second, $invert);
|
||||
}
|
||||
if($related == 'END'){
|
||||
$valarm->add('TRIGGER', $string, array('VALUE' => $type, 'RELATED' => $related));
|
||||
} else {
|
||||
$valarm->add('TRIGGER', $string, array('VALUE' => $type));
|
||||
}
|
||||
} else {
|
||||
unset($vtodo->VALARM);
|
||||
}
|
||||
return $this->helper->editVCalendar($vcalendar, $taskID);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder date-time
|
||||
*
|
||||
* @param string $date
|
||||
* @return string
|
||||
*/
|
||||
private function createReminderDateTime($date) {
|
||||
$date = new \DateTime('@'.$date);
|
||||
return $date->format('Ymd\THis\Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder duration
|
||||
*
|
||||
* @param bool $invert
|
||||
* @param mixed $week
|
||||
* @param mixed $day
|
||||
* @param mixed $hour
|
||||
* @param mixed $minute
|
||||
* @param mixed $second
|
||||
* @return string
|
||||
*/
|
||||
private function createReminderDuration($week, $day, $hour, $minute, $second, $invert) {
|
||||
// Create duration string
|
||||
$string = 'PT0S';
|
||||
$P = array(
|
||||
'W' => $week,
|
||||
'D' => $day,
|
||||
);
|
||||
$P = array_filter($P);
|
||||
$T = array(
|
||||
'H' => $hour,
|
||||
'M' => $minute,
|
||||
'S' => $second,
|
||||
);
|
||||
$T = array_filter($T);
|
||||
if(count($P) || count($T)) {
|
||||
$string = '';
|
||||
$string .= $invert ? '-' : '';
|
||||
$string .= 'P';
|
||||
$string .= implode('' , array_map(function($value, $key) {
|
||||
return $value.$key;
|
||||
}, $P, array_keys($P))
|
||||
);
|
||||
$string .= 'T';
|
||||
$string .= implode('' , array_map(function($value, $key) {
|
||||
return $value.$key;
|
||||
}, $T, array_keys($T))
|
||||
);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder
|
||||
*
|
||||
* @param mixed $reminder
|
||||
* @param object $start
|
||||
* @param object $due
|
||||
* @return array
|
||||
*/
|
||||
public function parseReminder($reminder, $start, $due) {
|
||||
if(!$reminder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$reminder->TRIGGER['VALUE']){
|
||||
throw new \Exception('Reminder type not specified.');
|
||||
}
|
||||
$reminderType = $reminder->TRIGGER['VALUE']->getValue();
|
||||
|
||||
if (!$reminder->ACTION) {
|
||||
throw new \Exception('Reminder action not specified.');
|
||||
}
|
||||
$reminderAction = $reminder->ACTION->getValue();
|
||||
|
||||
$reminderDate = null;
|
||||
$reminderDuration = null;
|
||||
|
||||
if($reminderType == 'DATE-TIME'){
|
||||
$reminderDate = $this->helper->parseDateString($reminder->TRIGGER);
|
||||
} elseif ($reminderType == 'DURATION') {
|
||||
list($related, $reminderDate) = $this->parseReminderDuration($reminder, $due, $start);
|
||||
$reminderDuration = $this->parseReminderDurationString($reminder, $related);
|
||||
}
|
||||
return array(
|
||||
'type' => $reminderType,
|
||||
'action' => $reminderAction,
|
||||
'date' => $reminderDate,
|
||||
'duration' => $reminderDuration,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder duration
|
||||
*
|
||||
* @param mixed $reminder
|
||||
* @param object $due
|
||||
* @param object $start
|
||||
* @return string
|
||||
*/
|
||||
private function parseReminderDuration($reminder, $due, $start) {
|
||||
$parsed = VObject\DateTimeParser::parseDuration($reminder->TRIGGER,true);
|
||||
// Calculate the reminder date from duration and start date
|
||||
$related = null;
|
||||
if(is_object($reminder->TRIGGER['RELATED'])){
|
||||
$related = $reminder->TRIGGER['RELATED']->getValue();
|
||||
if($related == 'END' && $due){
|
||||
$reminderDate = $this->helper->parseDateObject($due, $parsed);
|
||||
} else {
|
||||
throw new \Exception('Reminder duration related to not available date.');
|
||||
}
|
||||
} elseif ($start) {
|
||||
$reminderDate = $this->helper->parseDateObject($start, $parsed);
|
||||
} else{
|
||||
throw new \Exception('Reminder duration related to not available date.');
|
||||
};
|
||||
return array($related, $reminderDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse reminder date-time
|
||||
*
|
||||
* @param mixed $reminder
|
||||
* @param string $related
|
||||
* @return string
|
||||
*/
|
||||
private function parseReminderDurationString($reminder, $related) {
|
||||
preg_match('/^(?P<plusminus>\+|-)?P((?P<week>\d+)W)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>\d+)S)?)?$/', $reminder->TRIGGER, $matches);
|
||||
$invert = $matches['plusminus']==='-' ? true: false;
|
||||
$keys = array('week', 'day', 'hour', 'minute', 'second');
|
||||
$reminderDuration = array();
|
||||
foreach($keys as $key) {
|
||||
$reminderDuration[$key] = empty($matches[$key]) ? 0 : (int) $matches[$key];
|
||||
}
|
||||
$tmp = array_keys(array_filter($reminderDuration));
|
||||
$reminderDuration['token'] = count($tmp) ? $tmp[0] : 'week';
|
||||
$reminderDuration['params'] = array(
|
||||
'id' => (int)$invert.(int)($related == 'END'),
|
||||
'related' => $related?$related:'START',
|
||||
'invert' => $invert,
|
||||
);
|
||||
return $reminderDuration;
|
||||
}
|
||||
}
|
|
@ -47,8 +47,7 @@ class SettingsService {
|
|||
'id' => 'various',
|
||||
'showHidden' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_showHidden'),
|
||||
'startOfWeek' => (int)$this->settings->getUserValue($this->userId, $this->appName,'various_startOfWeek'),
|
||||
'userID' => $this->userId,
|
||||
'categories' => \OC_Calendar_App::getCategoryOptions()
|
||||
'userID' => $this->userId
|
||||
)
|
||||
);
|
||||
return $settings;
|
||||
|
|
|
@ -1,192 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use \OCA\Tasks\Service\ReminderService;
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
use Sabre\VObject;
|
||||
|
||||
Class TaskParser {
|
||||
|
||||
private $reminderService;
|
||||
private $helper;
|
||||
|
||||
public function __construct(ReminderService $reminderService, Helper $helper){
|
||||
$this->reminderService = $reminderService;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse task
|
||||
*
|
||||
* @param mixed $vtodo
|
||||
* @param string $calendarID
|
||||
* @return string
|
||||
*/
|
||||
public function parseTask($vtodo, $calendarID){
|
||||
$task = array( 'id' => (string) $vtodo->ID);
|
||||
$task['calendarid'] = (string) $calendarID;
|
||||
$task['type'] = 'task';
|
||||
$task['name'] = (string) $vtodo->SUMMARY;
|
||||
$task['created'] = (string) $vtodo->CREATED;
|
||||
$task['note'] = (string) $vtodo->DESCRIPTION;
|
||||
$task['location'] = (string) $vtodo->LOCATION;
|
||||
$task['categories'] = $this->parseCategories($vtodo->CATEGORIES);
|
||||
$task['start'] = $this->helper->parseDateObject($vtodo->DTSTART);
|
||||
$task['due'] = $this->helper->parseDateObject($vtodo->DUE);
|
||||
$task['completed_date'] = $this->helper->parseDateObject($vtodo->COMPLETED);
|
||||
$task['completed'] = (bool) $task['completed_date'];
|
||||
try {
|
||||
$task['reminder'] = $this->reminderService->parseReminder($vtodo->VALARM, $vtodo->DTSTART, $vtodo->DUE);
|
||||
} catch(\Exception $e) {
|
||||
\OCP\Util::writeLog('tasks', 'TaskID '.$vtodo->ID.': '.$e->getMessage(), \OCP\Util::DEBUG);
|
||||
$task['reminder'] = false;
|
||||
}
|
||||
$task['uid'] = (string) $vtodo->UID;
|
||||
$task['related'] = (string) $vtodo->{'RELATED-TO'};
|
||||
$task['hidesubtasks'] = $this->parseHideSubtasks((string) $vtodo->{'X-OC-HIDESUBTASKS'});
|
||||
$task['priority'] = $this->parsePriority($vtodo->PRIORITY);
|
||||
$task['starred'] = $this->parseStarred($task['priority']);
|
||||
$task['complete'] = $this->parsePercentCompleted($vtodo->{'PERCENT-COMPLETE'});
|
||||
$task['comments'] = $this->parseComments($vtodo->COMMENT);
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse starred
|
||||
*
|
||||
* @param mixed $priority
|
||||
* @return bool
|
||||
*/
|
||||
private function parseStarred($priority) {
|
||||
if ((int) $priority > 5) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse priority
|
||||
*
|
||||
* @param mixed $priority
|
||||
* @return string
|
||||
*/
|
||||
private function parsePriority($priority) {
|
||||
if(isset($priority)){
|
||||
return (string) ((10 - $priority->getValue()) % 10);
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse categories
|
||||
*
|
||||
* @param mixed $categories
|
||||
* @return array
|
||||
*/
|
||||
private function parseCategories($categories) {
|
||||
if ($categories){
|
||||
return $categories->getParts();
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse hiding subtasks
|
||||
*
|
||||
* @param mixed $hidesubtasks
|
||||
* @return bool
|
||||
*/
|
||||
private function parseHideSubtasks($hidesubtasks) {
|
||||
// show subtasks on default
|
||||
if ($hidesubtasks == '1'){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse percent completed
|
||||
*
|
||||
* @param mixed $percentComplete
|
||||
* @return string
|
||||
*/
|
||||
private function parsePercentCompleted($percentComplete) {
|
||||
if($percentComplete){
|
||||
return $percentComplete->getValue();
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* parse comments
|
||||
*
|
||||
* @param mixed $comments
|
||||
* @return array
|
||||
*/
|
||||
private function parseComments($comments){
|
||||
$comments_parsed = array();
|
||||
if($comments){
|
||||
foreach($comments as $com) {
|
||||
// parse time
|
||||
$time = $this->helper->parseDateString($com['X-OC-DATE-TIME']);
|
||||
// parse comment ID
|
||||
$comID = $com['X-OC-ID'];
|
||||
// parse user ID
|
||||
$userID = $com['X-OC-USERID'];
|
||||
|
||||
if ($this->isCommentValid($time, $comID, $userID)) {
|
||||
$userID = (string) $userID->getValue();
|
||||
$user = \OC::$server->getUserManager()->get($userID);
|
||||
if ($user) {
|
||||
$comments_parsed[] = array(
|
||||
'id' => $comID->getValue(),
|
||||
'userID' => $userID,
|
||||
'name' => $user->getDisplayName(),
|
||||
'comment' => $com->getValue(),
|
||||
'time' => $time,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $comments_parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if comment is valid
|
||||
*
|
||||
* @param string $time
|
||||
* @param string $comID
|
||||
* @param string $userID
|
||||
* @return bool
|
||||
*/
|
||||
private function isCommentValid($time, $comID, $userID) {
|
||||
return ($time && $comID && $userID);
|
||||
}
|
||||
}
|
|
@ -1,363 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2015 Raimund Schlüßler raimund.schluessler@googlemail.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Tasks\Service;
|
||||
|
||||
use \OCA\Tasks\Service\Helper;
|
||||
use \OCA\Tasks\Service\TaskParser;
|
||||
use \OCA\Tasks\Db\TasksMapper;
|
||||
use \OCA\Tasks\Service\MapperHelper;
|
||||
|
||||
class TasksService {
|
||||
|
||||
private $userId;
|
||||
private $tasksMapper;
|
||||
private $mapperHelper;
|
||||
private $helper;
|
||||
private $taskParser;
|
||||
|
||||
public function __construct($userId, TasksMapper $tasksMapper, MapperHelper $mapperHelper, Helper $helper, TaskParser $taskParser){
|
||||
$this->userId = $userId;
|
||||
$this->tasksMapper = $tasksMapper;
|
||||
$this->mapperHelper = $mapperHelper;
|
||||
$this->helper = $helper;
|
||||
$this->taskParser = $taskParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of Tasks filtered by listID and type
|
||||
*
|
||||
* @param string $listID
|
||||
* @param string $type
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getAll($listID = 'all', $type = 'all'){
|
||||
|
||||
if ($listID == 'all'){
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
} else {
|
||||
$calendar = \OC_Calendar_App::getCalendar($listID, true, false);
|
||||
$calendars = array($calendar);
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
$lists = array();
|
||||
foreach( $calendars as $calendar ) {
|
||||
$tasksMap = $this->mapperHelper->createTasksMap($calendar['id']);
|
||||
|
||||
list($lists[], $rootTasks) = $this->mapperHelper->getRootTasks($tasksMap, $type, $calendar['id']);
|
||||
|
||||
$tasks = array_merge($tasks, $rootTasks);
|
||||
|
||||
foreach($rootTasks as $rootTask) {
|
||||
$tasks = array_merge($tasks, $this->mapperHelper->getChildTasks($rootTask['uid'], $tasksMap, true));
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'tasks' => array_values($tasks),
|
||||
'lists' => $lists
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* get task by id
|
||||
*
|
||||
* @param string $taskID
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getTask($taskID){
|
||||
$tasks = array();
|
||||
$calendar_entry = $this->tasksMapper->findVTODOById($taskID);
|
||||
$tasksMap = $this->mapperHelper->createTasksMap($calendar_entry->getCalendarid());
|
||||
$rootUID = $this->mapperHelper->findRootUID($this->mapperHelper->getUIDbyID($taskID, $tasksMap), $tasksMap);
|
||||
|
||||
$rootTask = $this->mapperHelper->getTaskByUID($rootUID, $tasksMap);
|
||||
if ($rootTask) {
|
||||
$tasks = array_merge(array($rootTask), $this->mapperHelper->getChildTasks($rootUID, $tasksMap, true));
|
||||
}
|
||||
|
||||
return array(
|
||||
'tasks' => $tasks
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for query in tasks
|
||||
*
|
||||
* @param string $query
|
||||
* @return array
|
||||
*/
|
||||
public function search($query) {
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
$results = array();
|
||||
foreach ($calendars as $calendar) {
|
||||
$calendar_entries = $this->tasksMapper->findAllVTODOs($calendar['id']);
|
||||
// search all calendar objects, one by one
|
||||
foreach ($calendar_entries as $calendar_entry) {
|
||||
$vtodo = $this->helper->checkTask($calendar_entry);
|
||||
if(!$vtodo){
|
||||
continue;
|
||||
}
|
||||
if($this->helper->checkTaskByQuery($vtodo, $query)) {
|
||||
$results[] = $this->taskParser->parseTask($vtodo, $calendar_entry->getCalendarid());
|
||||
}
|
||||
}
|
||||
}
|
||||
usort($results, array($this->helper, 'sortCompleted'));
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* create new task
|
||||
*
|
||||
* @param string $taskName
|
||||
* @param int $calendarId
|
||||
* @param bool $starred
|
||||
* @param mixed $due
|
||||
* @param mixed $start
|
||||
* @param int $tmpID
|
||||
* @return array
|
||||
*/
|
||||
public function add($taskName, $related, $calendarId, $starred, $due, $start, $tmpID){
|
||||
$request = array(
|
||||
'summary' => $taskName,
|
||||
'related' => $related,
|
||||
'starred' => $starred,
|
||||
'due' => $due,
|
||||
'start' => $start,
|
||||
);
|
||||
$vcalendar = $this->helper->createVCalendar($request);
|
||||
$vtodo = $vcalendar->VTODO;
|
||||
$vtodo->ID = \OC_Calendar_Object::add($calendarId, $vcalendar->serialize());
|
||||
|
||||
$task = $this->taskParser->parseTask($vtodo, $calendarId);
|
||||
|
||||
$task['tmpID'] = $tmpID;
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($taskID) {
|
||||
return \OC_Calendar_Object::delete($taskID);
|
||||
}
|
||||
|
||||
/**
|
||||
* set name of task by id
|
||||
* @param int $taskID
|
||||
* @param string $name
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setName($taskID, $name) {
|
||||
return $this->helper->setProperty($taskID,'SUMMARY',$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* set calendar id of task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $calendarID
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setCalendarId($taskID, $calendarID) {
|
||||
$data = \OC_Calendar_App::getEventObject($taskID);
|
||||
if ($data['calendarid'] != $calendarID) {
|
||||
return \OC_Calendar_Object::moveToCalendar($taskID, $calendarID);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set completeness of task in percent by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $percent_complete
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setPercentComplete($taskID, $percent_complete) {
|
||||
$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 $this->helper->editVCalendar($vcalendar, $taskID);
|
||||
}
|
||||
|
||||
/**
|
||||
* set priority of task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $priority
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setPriority($taskID, $priority){
|
||||
$priority = (10 - $priority) % 10;
|
||||
return $this->helper->setProperty($taskID,'PRIORITY',$priority);
|
||||
}
|
||||
|
||||
/**
|
||||
* set view state of subtasks
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $show
|
||||
* @return bool
|
||||
*/
|
||||
public function hideSubtasks($taskID, $show){
|
||||
return $this->helper->setProperty($taskID,'X-OC-HIDESUBTASKS',$show);
|
||||
}
|
||||
|
||||
/**
|
||||
* set parent of subtask
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param int $related
|
||||
* @return bool
|
||||
*/
|
||||
public function parent($taskID, $related){
|
||||
return $this->helper->setProperty($taskID,'RELATED-TO',$related);
|
||||
}
|
||||
|
||||
/**
|
||||
* set due date of task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param mixed $dueDate
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setDueDate($taskID, $dueDate) {
|
||||
return $this->helper->setProperty($taskID, 'DUE', $this->helper->createDateFromUNIX($dueDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* set start date of task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param mixed $startDate
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setStartDate($taskID, $startDate) {
|
||||
return $this->helper->setProperty($taskID, 'DTSTART', $this->helper->createDateFromUNIX($startDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* add category to task by id
|
||||
* @param int $taskID
|
||||
* @param string $category
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addCategory($taskID, $category){
|
||||
$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 $this->helper->editVCalendar($vcalendar, $taskID);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove category from task by id
|
||||
* @param int $taskID
|
||||
* @param string $category
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function removeCategory($taskID, $category){
|
||||
$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'});
|
||||
}
|
||||
return $this->helper->editVCalendar($vcalendar, $taskID);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* set location of task by id
|
||||
* @param int $taskID
|
||||
* @param string $location
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setLocation($taskID, $location){
|
||||
return $this->helper->setProperty($taskID,'LOCATION',$location);
|
||||
}
|
||||
|
||||
/**
|
||||
* set description of task by id
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $description
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setDescription($taskID, $description){
|
||||
return $this->helper->setProperty($taskID,'DESCRIPTION',$description);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue