diff options
author | raimund-schluessler <raimund.schluessler@googlemail.com> | 2014-08-18 00:35:34 +0400 |
---|---|---|
committer | raimund-schluessler <raimund.schluessler@googlemail.com> | 2014-08-20 23:23:00 +0400 |
commit | eddd8595719cade74141f627df34153444e34909 (patch) | |
tree | 0cc123543f73da05c66bbbb624a04e8b3a1629c2 /lib | |
parent | fa261401bc76b7db6455139fb784a2f984821df5 (diff) |
Rework routing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/controller.php | 44 | ||||
-rw-r--r-- | lib/controller/collectionscontroller.php | 96 | ||||
-rw-r--r-- | lib/controller/listscontroller.php | 136 | ||||
-rw-r--r-- | lib/controller/pagecontroller.php | 58 | ||||
-rw-r--r-- | lib/controller/settingscontroller.php | 63 | ||||
-rw-r--r-- | lib/controller/taskscontroller.php | 570 | ||||
-rw-r--r-- | lib/dispatcher.php | 57 | ||||
-rw-r--r-- | lib/helper.php | 241 |
8 files changed, 0 insertions, 1265 deletions
diff --git a/lib/controller.php b/lib/controller.php deleted file mode 100644 index 281d485b..00000000 --- a/lib/controller.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php -/** - * @author Thomas Tanghus - * @author Thomas Tanghus - * @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net) - * - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCA\Tasks; - -use OCP\AppFramework\IAppContainer; -use OCP\AppFramework\Controller as BaseController; -use OCP\IRequest; - -/** - * Base Controller class for Issues App - */ -class Controller extends BaseController { - - /** - * @var Api - */ - protected $api; - - /** - * @var IRequest - */ - protected $request; - - /** - * @var OCP\IServerContainer - */ - protected $server; - - public function __construct(IAppContainer $container) { - $this->api = $container->query('API'); - $this->request = $container->query('Request'); - $this->server = $container->getServer(); - } - -} diff --git a/lib/controller/collectionscontroller.php b/lib/controller/collectionscontroller.php deleted file mode 100644 index d1cace93..00000000 --- a/lib/controller/collectionscontroller.php +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** -* ownCloud - Tasks -* -* @author Raimund Schlüßler -* @copyright 2014 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\Controller; -use OCP\AppFramework\Http\JSONResponse; - -class CollectionsController extends Controller { - - /** - * @NoAdminRequired - */ - public function getCollections(){ - $l = \OCP\Util::getL10N('tasks'); - $collections = array( - array( - 'id' => "starred", - 'displayname' => (string)$l->t('Important'), - 'show' => 2), - array( - 'id' => "today", - 'displayname' => (string)$l->t('Today'), - 'show' => 2), - array( - 'id' => "week", - 'displayname' => (string)$l->t('Week'), - 'show' => 2), - array( - 'id' => "all", - 'displayname' => (string)$l->t('All'), - 'show' => 2), - array( - 'id' => "current", - 'displayname' => (string)$l->t('Current'), - 'show' => 2), - array( - 'id' => "completed", - 'displayname' => (string)$l->t('Completed'), - 'show' => 2) - ); - foreach ($collections as $key => $collection){ - try{ - $tmp = \OCP\Config::getUserValue($this->api->getUserId(), 'tasks','show_'.$collection['id']); - if (!in_array((int)$tmp, array(0,1,2)) || $tmp === null) { - $tmp = 2; - \OCP\Config::setUserValue($this->api->getUserId(), 'tasks','show_'.$collection['id'],$tmp); - } - $collections[$key]['show'] = (int)$tmp; - }catch(\Exception $e) { - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } - $result = array( - 'data' => array( - 'collections' => $collections - ) - ); - $response = new JSONResponse(); - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function setVisibility(){ - $collectionId = (string) $this->params('collectionID'); - $vis = (int) $this->params('visibility'); - if (in_array($vis, array(0,1,2))){ - \OCP\Config::setUserValue($this->api->getUserId(), 'tasks','show_'.$collectionId,$vis); - } - $response = new JSONResponse(); - return $response; - } -}
\ No newline at end of file diff --git a/lib/controller/listscontroller.php b/lib/controller/listscontroller.php deleted file mode 100644 index 35506032..00000000 --- a/lib/controller/listscontroller.php +++ /dev/null @@ -1,136 +0,0 @@ -<?php - -/** -* ownCloud - Tasks -* -* @author Raimund Schlüßler -* @copyright 2013 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\Controller; -use OCP\AppFramework\Http\JSONResponse; - -class ListsController extends Controller { - - /** - * @NoAdminRequired - */ - public function getLists(){ - $userId = $this->api->getUserId(); - $calendar = new \OC_Calendar_Calendar(); - $lists = $calendar::allCalendars($userId, true); - $result = array( - 'data' => array( - 'lists' => $lists - ) - ); - $response = new JSONResponse(); - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function addList(){ - $listName = $this->params('name'); - $userId = $this->api->getUserId(); - - if(trim($listName) == '') { - // OCP\JSON::error(array('message'=>'empty')); - exit; - } - $calendars = \OC_Calendar_Calendar::allCalendars($userId, true); - foreach($calendars as $cal) { - if($cal['displayname'] == $listName) { - // OCP\JSON::error(array('message'=>'namenotavailable')); - exit; - } - } - $color = '#CCCCCC'; - $calendarId = \OC_Calendar_Calendar::addCalendar($userId, strip_tags($listName), 'VEVENT,VTODO,VJOURNAL', null, 0, $color); - \OC_Calendar_Calendar::setCalendarActive($calendarId, 1); - $list = \OC_Calendar_Calendar::find($calendarId); - - $list['tmpID'] = $this->params('tmpID'); - $result = array( - 'data' => array( - 'list' => $list - ) - ); - $response = new JSONResponse(); - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function deleteList(){ - $listId = $this->params('listID'); - $response = new JSONResponse(); - try { - $del = \OC_Calendar_Calendar::deleteCalendar($listId); - if($del == true) { - $result = array( - 'data' => array() - ); - }else{ - $result = array('error'=>'dberror'); - } - } catch(\Exception $e) { - $result = array('message'=>$e->getMessage()); - } - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function setListName(){ - $listId = (int) $this->params('listID'); - $listName = $this->params('name'); - $userId = $this->api->getUserId(); - $response = new JSONResponse(); - if(trim($listName) == '') { - // OCP\JSON::error(array('message'=>'empty')); - exit; - } - $calendars = \OC_Calendar_Calendar::allCalendars($userId, true); - foreach($calendars as $cal) { - if($cal['userid'] != $userId){ - continue; - } - if($cal['displayname'] == $listName && $cal['id'] != $listId) { - // OCP\JSON::error(array('message'=>'namenotavailable')); - exit; - } - } - - $color = '#CCCCCC'; - \OC_Calendar_Calendar::editCalendar($listId, strip_tags($listName), null, null, null, $color); - - $result = array( - 'data' => array() - ); - $response->setData($result); - return $response; - } -}
\ No newline at end of file diff --git a/lib/controller/pagecontroller.php b/lib/controller/pagecontroller.php deleted file mode 100644 index 5d4b49c3..00000000 --- a/lib/controller/pagecontroller.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -/** - * @author Thomas Tanghus - * @copyright 2014 Thomas Tanghus (thomas@tanghus.net) - * - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCA\Tasks\Controller; - -use OCA\Tasks\Controller; -use OCP\AppFramework\Http\TemplateResponse; - - -/** - * Controller class for main page. - */ -class PageController extends Controller { - - /** - * @NoAdminRequired - * @NoCSRFRequired - */ - public function index() { - if (defined('DEBUG') && DEBUG) { - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular'); - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-route'); - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-animate'); - \OCP\Util::addScript('tasks', 'vendor/momentjs/moment'); - \OCP\Util::addScript('tasks', 'vendor/bootstrap/ui-bootstrap-custom-tpls-0.10.0'); - } else { - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular.min'); - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-route.min'); - \OCP\Util::addScript('tasks', 'vendor/angularjs/angular-animate.min'); - \OCP\Util::addScript('tasks', 'vendor/momentjs/moment.min'); - \OCP\Util::addScript('tasks', 'vendor/bootstrap/ui-bootstrap-custom-tpls-0.10.0.min'); - } - \OCP\Util::addScript('tasks', 'public/app'); - \OCP\Util::addScript('tasks', 'vendor/appframework/app'); - \OCP\Util::addScript('tasks', 'vendor/timepicker/jquery.ui.timepicker'); - \OCP\Util::addStyle('tasks', 'style'); - \OCP\Util::addStyle('tasks', 'vendor/bootstrap/bootstrap'); - - $date = new \DateTimeZone(\OC_Calendar_App::getTimezone()); - $day = new \DateTime('today', $date); - $day = $day->format('d'); - - // TODO: Make a HTMLTemplateResponse class - $response = new TemplateResponse('tasks', 'main'); - $response->setParams(array( - 'DOM' => $day - )); - - return $response; - } -}
\ No newline at end of file diff --git a/lib/controller/settingscontroller.php b/lib/controller/settingscontroller.php deleted file mode 100644 index d7c03667..00000000 --- a/lib/controller/settingscontroller.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php - -/** -* ownCloud - Tasks -* -* @author Raimund Schlüßler -* @copyright 2014 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\Controller; -use OCP\AppFramework\Http\JSONResponse; - -class SettingsController extends Controller { - - /** - * @NoAdminRequired - */ - public function getSettings(){ - $settings = array( - array( - 'id' => 'various', - 'showHidden' => (int)\OCP\Config::getUserValue($this->api->getUserId(), 'tasks','various_showHidden'), - 'startOfWeek' => (int)\OCP\Config::getUserValue($this->api->getUserId(), 'tasks','various_startOfWeek'), - 'userID' => $this->api->getUserId() - - ) - ); - $result = array( - 'data' => array( - 'settings' => $settings - ) - ); - $response = new JSONResponse(); - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function set(){ - \OCP\Config::setUserValue($this->api->getUserId(), 'tasks',$this->params('type').'_'.$this->params('setting'), $this->params('value')); - $response = new JSONResponse(); - $response->setData(); - return $response; - } -}
\ No newline at end of file diff --git a/lib/controller/taskscontroller.php b/lib/controller/taskscontroller.php deleted file mode 100644 index 89741e31..00000000 --- a/lib/controller/taskscontroller.php +++ /dev/null @@ -1,570 +0,0 @@ -<?php - -/** -* ownCloud - Tasks -* -* @author Raimund Schlüßler -* @copyright 2013 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\Controller; -use OCA\Tasks\Helper; -use OCP\AppFramework\Http\JSONResponse; - -class TasksController extends Controller { - - /** - * @NoAdminRequired - */ - public function getTasks(){ - $userId = $this->api->getUserId(); - $calendars = \OC_Calendar_Calendar::allCalendars($userId, true); - $user_timezone = \OC_Calendar_App::getTimezone(); - - $tasks = array(); - foreach( $calendars as $calendar ) { - $calendar_tasks = \OC_Calendar_Object::all($calendar['id']); - foreach( $calendar_tasks as $task ) { - if($task['objecttype']!='VTODO') { - continue; - } - if(is_null($task['summary'])) { - continue; - } - $vtodo = Helper::parseVTODO($task['calendardata']); - try { - $task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone); - $task_data['calendarid'] = $calendar['id']; - $task_data['calendarcolor'] = $calendar['calendarcolor']; - $tasks[] = $task_data; - } catch(\Exception $e) { - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } - } - - $result = array( - 'data' => array( - 'tasks' => $tasks - ) - ); - $response = new JSONResponse(); - $response->setData($result); - return $response; - } - - /** - * @param boolean $isStarred - */ - private function setStarred($isStarred){ - $taskId = (int) $this->params('taskID'); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - if($isStarred){ - $vtodo->setString('PRIORITY',1); - }else{ - $vtodo->__unset('PRIORITY'); - } - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - } - - /** - * @NoAdminRequired - */ - public function starTask(){ - $response = new JSONResponse(); - try { - $this->setStarred(true); - return $response; - } catch(\Exception $e) { - return $response; - // return $this->renderJSON(array(), $e->getMessage()); - } - } - - /** - * @NoAdminRequired - */ - public function unstarTask(){ - $response = new JSONResponse(); - try { - $this->setStarred(false); - return $response; - } catch(\Exception $e) { - return $response; - // return $this->renderJSON(array(), $e->getMessage()); - } - } - - private function setPercentComplete($percent_complete){ - $taskId = (int) $this->params('taskID'); - $isCompleted = null; - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - if (!empty($percent_complete)) { - $vtodo->setString('PERCENT-COMPLETE', $percent_complete); - }else{ - $vtodo->__unset('PERCENT-COMPLETE'); - } - - if ($percent_complete == 100) { - if (!$isCompleted) { - $isCompleted = 'now'; - } - } else { - $isCompleted = null; - } - if ($isCompleted) { - $timezone = \OC_Calendar_App::getTimezone(); - $timezone = new \DateTimeZone($timezone); - $isCompleted = new \DateTime($isCompleted, $timezone); - $vtodo->setDateTime('COMPLETED', $isCompleted); - } else { - unset($vtodo->COMPLETED); - } - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - } - - /** - * @NoAdminRequired - */ - public function percentComplete(){ - $response = new JSONResponse(); - try{ - $percent_complete = $this->params('complete'); - $this->setPercentComplete( $percent_complete ); - return $response; - } catch(\Exception $e) { - return $response; - // return $this->renderJSON(array(), $e->getMessage()); - } - } - - - /** - * @NoAdminRequired - */ - public function completeTask(){ - $response = new JSONResponse(); - try { - $this->setPercentComplete(100); - return $response; - } catch(\Exception $e) { - return $response; - // return $this->renderJSON(array(), $e->getMessage()); - } - } - - /** - * @NoAdminRequired - */ - public function uncompleteTask(){ - $response = new JSONResponse(); - try { - $this->setPercentComplete(0); - return $response; - } catch(\Exception $e) { - return $response; - // return $this->renderJSON(array(), $e->getMessage()); - } - } - - /** - * @NoAdminRequired - */ - public function addTask(){ - $taskName = $this->params('name'); - $calendarId = $this->params('calendarID'); - $starred = $this->params('starred'); - $due = $this->params('due'); - $start = $this->params('start'); - $response = new JSONResponse(); - $user_timezone = \OC_Calendar_App::getTimezone(); - $request = array( - 'summary' => $taskName, - 'categories' => null, - 'priority' => $starred, - 'location' => null, - 'due' => $due, - 'start' => $start, - 'description' => null - ); - $vcalendar = Helper::createVCalendarFromRequest($request); - $taskId = \OC_Calendar_Object::add($calendarId, $vcalendar->serialize()); - - $task = Helper::arrayForJSON($taskId, $vcalendar->VTODO, $user_timezone); - $task['calendarid'] = $calendarId; - - $task['tmpID'] = $this->params('tmpID'); - $result = array( - 'data' => array( - 'task' => $task - ) - ); - $response->setData($result); - return $response; - } - - /** - * @NoAdminRequired - */ - public function deleteTask(){ - $response = new JSONResponse(); - $taskId = $this->params('taskID'); - \OC_Calendar_Object::delete($taskId); - return $response; - } - - /** - * @NoAdminRequired - */ - public function setTaskName(){ - $taskId = (int) $this->params('taskID'); - $taskName = $this->params('name'); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $vtodo->setString('SUMMARY', $taskName); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setTaskCalendar(){ - $taskId = $this->params('taskID'); - $calendarId = $this->params('calendarID'); - $response = new JSONResponse(); - try { - $data = \OC_Calendar_App::getEventObject($taskId); - if ($data['calendarid'] != $calendarId) { - \OC_Calendar_Object::moveToCalendar($taskId, $calendarId); - } - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setTaskNote(){ - $taskId = $this->params('taskID'); - $note = $this->params('note'); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $vtodo->setString('DESCRIPTION', $note); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setDueDate(){ - $taskId = $this->params('taskID'); - $due = $this->params('due'); - $response = new JSONResponse(); - try{ - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $type = null; - if ($due != 'false') { - $timezone = \OC_Calendar_App::getTimezone(); - $timezone = new \DateTimeZone($timezone); - - $due = new \DateTime('@'.$due); - $due->setTimezone($timezone); - $type = \Sabre\VObject\Property\DateTime::LOCALTZ; - // if ($due_date_only) { - // $type = \Sabre\VObject\Property\DateTime::DATE; - // } - } - $vtodo->setDateTime('DUE', $due, $type); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch (\Exception $e) { - - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setStartDate(){ - $taskId = $this->params('taskID'); - $start = $this->params('start'); - $response = new JSONResponse(); - - try{ - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $type = null; - if ($start != 'false') { - $timezone = \OC_Calendar_App::getTimezone(); - $timezone = new \DateTimeZone($timezone); - - $start = new \DateTime('@'.$start); - $start->setTimezone($timezone); - $type = \Sabre\VObject\Property\DateTime::LOCALTZ; - // if ($due_date_only) { - // $type = \Sabre\VObject\Property\DateTime::DATE; - // } - } - $vtodo->setDateTime('DTSTART', $start, $type); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch (\Exception $e) { - - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setReminderDate(){ - $taskId = $this->params('taskID'); - $type = $this->params('type'); - $action = $this->params('action'); - // $date = $this->params('date'); - $response = new JSONResponse(); - - $types = array('DATE-TIME','DURATION'); - - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $valarm = $vtodo->VALARM; - - if ($type == false){ - unset($vtodo->VALARM); - $vtodo->setDateTime('LAST-MODIFIED', 'now', \Sabre\VObject\Property\DateTime::UTC); - $vtodo->setDateTime('DTSTAMP', 'now', \Sabre\VObject\Property\DateTime::UTC); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } - elseif (in_array($type,$types)) { - try{ - if($valarm == null) { - $valarm = new \OC_VObject('VALARM'); - $valarm->setString('ACTION', $action); - $valarm->setString('DESCRIPTION', 'Default Event Notification'); - $valarm->setString(''); - $vtodo->add($valarm); - } else { - unset($valarm->TRIGGER); - } - $tv = ''; - $related = null; - if ($type == 'DATE-TIME') { - $date = new \DateTime('@'.$this->params('date')); - $tv = $date->format('Ymd\THis\Z'); - } elseif ($type == 'DURATION') { - $invert = $this->params('invert'); - $related= $this->params('related'); - $week = (int)$this->params('week'); - $day = (int)$this->params('day'); - $hour = (int)$this->params('hour'); - $minute = (int)$this->params('minute'); - $second = (int)$this->params('second'); - - // 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->addProperty('TRIGGER', $tv, array('VALUE' => $type, 'RELATED' => $related)); - } else { - $valarm->addProperty('TRIGGER', $tv, array('VALUE' => $type)); - } - $vtodo->setDateTime('LAST-MODIFIED', 'now', \Sabre\VObject\Property\DateTime::UTC); - $vtodo->setDateTime('DTSTAMP', 'now', \Sabre\VObject\Property\DateTime::UTC); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch (\Exception $e) { - - } - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setCategories(){ - $taskId = $this->params('taskID'); - $categories = $this->params('categories'); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $vtodo->setString('CATEGORIES', $categories); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function setLocation(){ - $taskId = $this->params('taskID'); - $location = $this->params('location'); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $vtodo->setString('LOCATION', $location); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function addComment(){ - $taskId = $this->params('taskID'); - $comment = $this->params('comment'); - $userId = $this->api->getUserId(); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - - // Determine new commentId by looping through all comments - $commentIds = array(); - foreach($vtodo->COMMENT as $com) { - $commentIds[] = (int)$com['ID']->value; - } - $commentId = 1+max($commentIds); - - $now = new \DateTime(); - $vtodo->addProperty('COMMENT',$comment, - array( - 'ID' => $commentId, - 'USERID' => $userId, - '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' => $this->params('tmpID'), - 'name' => \OCP\USER::getDisplayName(), - 'userID' => $userId, - 'comment' => $comment, - 'time' => $now->format('Ymd\THis') - ); - $result = array( - 'data' => array( - 'comment' => $comment - ) - ); - $response->setData($result); - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function deleteComment(){ - $taskId = $this->params('taskID'); - $commentId = $this->params('commentID'); - $userId = $this->api->getUserId(); - $response = new JSONResponse(); - try { - $vcalendar = \OC_Calendar_App::getVCalendar($taskId); - $vtodo = $vcalendar->VTODO; - $commentIndex = $this->getCommentById($vtodo,$commentId); - $comment = $vtodo->children[$commentIndex]; - if($comment['USERID'] == $userId){ - unset($vtodo->children[$commentIndex]); - \OC_Calendar_Object::edit($taskId, $vcalendar->serialize()); - }else{ - throw new \Exception('Not allowed.'); - } - } catch(\Exception $e) { - // throw new BusinessLayerException($e->getMessage()); - } - return $response; - } - - /** - * @NoAdminRequired - */ - public function getCommentById($vtodo,$commentId) { - $idx = 0; - foreach ($vtodo->children as $i => &$property) { - if ( $property->name == 'COMMENT' && $property['ID']->value == $commentId ) { - return $idx; - } - $idx += 1; - } - throw new \Exception('Commment not found.'); - } -}
\ No newline at end of file diff --git a/lib/dispatcher.php b/lib/dispatcher.php deleted file mode 100644 index ce9fe1f3..00000000 --- a/lib/dispatcher.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php -/** - * @author Thomas Tanghus - * @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net) - * - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OCA\Tasks; - -use OCP\AppFramework\App as MainApp; -use OCP\AppFramework\IAppContainer; -use OCA\Tasks\Controller\PageController; -use OCA\Tasks\Controller\CollectionsController; -use OCA\Tasks\Controller\ListsController; -use OCA\Tasks\Controller\TasksController; -use OCA\Tasks\Controller\SettingsController; - -/** - * This class manages our app actions - * - * TODO: Merge with App - */ - -class Dispatcher extends MainApp { - /** - * @var App - */ - protected $app; - - public function __construct($params) { - parent::__construct('tasks', $params); - $this->container = $this->getContainer(); - $this->registerServices(); - } - - public function registerServices() { - $this->container->registerService('PageController', function(IAppContainer $container) { - return new PageController($container); - }); - $this->container->registerService('CollectionsController', function(IAppContainer $container) { - return new CollectionsController($container); - }); - $this->container->registerService('ListsController', function(IAppContainer $container) { - return new ListsController($container); - }); - $this->container->registerService('TasksController', function(IAppContainer $container) { - return new TasksController($container); - }); - $this->container->registerService('SettingsController', function(IAppContainer $container) { - return new SettingsController($container); - }); - } - -} diff --git a/lib/helper.php b/lib/helper.php deleted file mode 100644 index c5577829..00000000 --- a/lib/helper.php +++ /dev/null @@ -1,241 +0,0 @@ -<?php -/** - * ownCloud - Utility class for VObject properties - * - * @author Thomas Tanghus - * @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net) - * - * 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; - -use Sabre\VObject; -// use OCA\Tasks\App; - -Class helper { - - public static function parseVTODO($data) { - $object = \OC_VObject::parse($data); - $vtodo = $object->VTODO; - return $vtodo; - } - - public static function arrayForJSON($id, $vtodo, $user_timezone){ - $task = array( 'id' => $id ); - $task['name'] = $vtodo->getAsString('SUMMARY'); - $task['created'] = $vtodo->getAsString('CREATED'); - $task['note'] = $vtodo->getAsString('DESCRIPTION'); - $task['location'] = $vtodo->getAsString('LOCATION'); - $task['categories'] = $vtodo->getAsArray('CATEGORIES'); - $start = $vtodo->DTSTART; - if ($start) { - try { - $start = $start->getDateTime(); - $start->setTimezone(new \DateTimeZone($user_timezone)); - $task['start'] = $start->format('Ymd\THis'); - } catch(\Exception $e) { - $task['start'] = null; - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } else { - $task['start'] = null; - } - $due = $vtodo->DUE; - if ($due) { - try { - $due = $due->getDateTime(); - $due->setTimezone(new \DateTimeZone($user_timezone)); - $task['due'] = $due->format('Ymd\THis'); - } catch(\Exception $e) { - $task['due'] = null; - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } else { - $task['due'] = null; - } - $reminder = $vtodo->VALARM; - if($reminder) { - try { - - $reminderType = $reminder->TRIGGER['VALUE']->value; - $reminderAction = $reminder->ACTION->value; - $reminderDate = null; - $reminderDuration = null; - - - if($reminderType == 'DATE-TIME'){ - $reminderDate = $reminder->TRIGGER->getDateTime(); - $reminderDate->setTimezone(new \DateTimeZone($user_timezone)); - $reminderDate = $reminderDate->format('Ymd\THis'); - } elseif ($reminderType == 'DURATION' && ($start || $due)) { - - $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']->value; - if(is_object($reminder->TRIGGER['RELATED']) && $reminder->TRIGGER['RELATED']->value == 'END' && $due){ - $reminderDate = $due->modify($parsed)->format('Ymd\THis'); - } elseif ($start) { - $reminderDate = $start->modify($parsed)->format('Ymd\THis'); - } - } else{ - throw new \Exception('Reminder duration related to not available date.'); - } - 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 = false; - if ($matches['plusminus']==='-') { - $invert = true; - } - - $parts = array( - 'week', - 'day', - 'hour', - 'minute', - 'second', - ); - - $reminderDuration = array( - 'token' => null - ); - foreach($parts as $part) { - $matches[$part] = isset($matches[$part])&&$matches[$part]?(int)$matches[$part]:0; - $reminderDuration[$part] = $matches[$part]; - if($matches[$part] && !$reminderDuration['token']){ - $reminderDuration['token'] = $part; - } - } - if($reminderDuration['token'] == null){ - $reminderDuration['token'] = $parts[0]; - } - - $reminderDuration['params'] = array( - 'id' => (int)$invert.(int)($related == 'END'), - 'related'=> $related?$related:'START', - 'invert'=> $invert - ); - - } else { - $reminderDate = null; - $reminderDuration = null; - } - - $task['reminder'] = array( - 'type' => $reminderType, - 'action' => $reminderAction, - 'date' => $reminderDate, - 'duration' => $reminderDuration - ); - - } catch(\Exception $e) { - $task['reminder'] = null; - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } else { - $task['reminder'] = null; - } - $starred = $vtodo->getAsString('PRIORITY'); - if($starred){ - $task['starred'] = true; - } else { - $task['starred'] = false; - } - $completed = $vtodo->COMPLETED; - if ($completed) { - try { - $completed = $completed->getDateTime(); - $completed->setTimezone(new \DateTimeZone($user_timezone)); - $task['completed_date'] = $completed->format('Ymd\THis'); - $task['completed'] = true; - } catch(\Exception $e) { - $task['completed'] = false; - \OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR); - } - } else { - $task['completed'] = false; - } - $task['complete'] = $vtodo->getAsString('PERCENT-COMPLETE')==''?'0':$vtodo->getAsString('PERCENT-COMPLETE'); - $comments = $vtodo->COMMENT; - if($comments){ - $comments_parsed = array(); - foreach($comments as $com) { - $time = new \DateTime($com['DATE-TIME']->value); - $time->setTimezone(new \DateTimeZone($user_timezone)); - $time = $time->format('Ymd\THis'); - $comments_parsed[] = array( - 'id' => (int)$com['ID']->value, - 'userID' => $com['USERID']->value, - 'name' => \OCP\USER::getDisplayName($com['USERID']->value), - 'comment' => $com->value, - 'time' => $time - ); - } - $task['comments'] = $comments_parsed; - } - return $task; - } - - - public static function createVCalendarFromRequest($request){ - $vcalendar = new \OC_VObject('VCALENDAR'); - $vcalendar->add('PRODID', 'ownCloud Calendar'); - $vcalendar->add('VERSION', '2.0'); - - $vtodo = new \OC_VObject('VTODO'); - $vcalendar->add($vtodo); - - $vtodo->setDateTime('CREATED', 'now', \Sabre\VObject\Property\DateTime::UTC); - - $vtodo->setUID(); - return self::updateVCalendarFromRequest($request, $vcalendar); - } - - public static function updateVCalendarFromRequest($request, $vcalendar){ - $vtodo = $vcalendar->VTODO; - - $vtodo->setDateTime('LAST-MODIFIED', 'now', \Sabre\VObject\Property\DateTime::UTC); - $vtodo->setDateTime('DTSTAMP', 'now', \Sabre\VObject\Property\DateTime::UTC); - $vtodo->setString('SUMMARY', $request['summary']); - - $vtodo->setString('LOCATION', $request['location']); - $vtodo->setString('DESCRIPTION', $request['description']); - $vtodo->setString('CATEGORIES', $request["categories"]); - $vtodo->setString('PRIORITY', $request['priority']); - $vtodo->setString('PERCENT-COMPLETE', $request['complete']); - - $due = $request['due']; - if ($due) { - $timezone = \OC_Calendar_App::getTimezone(); - $timezone = new \DateTimeZone($timezone); - $due = new \DateTime($due, $timezone); - $vtodo->setDateTime('DUE', $due); - } else { - unset($vtodo->DUE); - } - $start = $request['start']; - if ($start) { - $timezone = \OC_Calendar_App::getTimezone(); - $timezone = new \DateTimeZone($timezone); - $start = new \DateTime($start, $timezone); - $vtodo->setDateTime('DTSTART', $start); - } else { - unset($vtodo->DTSTART); - } - - return $vcalendar; - } -} |