Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorraimund-schluessler <raimund.schluessler@googlemail.com>2014-07-22 02:13:34 +0400
committerraimund-schluessler <raimund.schluessler@googlemail.com>2014-07-22 02:13:34 +0400
commit6ddb0b8cb9d8b5610fbfc6628c938f71157e8838 (patch)
treef8cb75e8cecc042f8ac178075064524d1ecf6213 /lib
parent7190774cd16a2b21a75ac9a2011e7b3a0108f208 (diff)
parenta07bd3439446296c553adc2f80224fd950013b82 (diff)
Merge pull request #42 from raimund-schluessler/Enable_commenting
Enable commenting
Diffstat (limited to 'lib')
-rw-r--r--lib/controller/settingscontroller.php4
-rw-r--r--lib/controller/taskscontroller.php98
-rw-r--r--lib/helper.php17
3 files changed, 112 insertions, 7 deletions
diff --git a/lib/controller/settingscontroller.php b/lib/controller/settingscontroller.php
index eb6504a5..d02d0e2a 100644
--- a/lib/controller/settingscontroller.php
+++ b/lib/controller/settingscontroller.php
@@ -36,7 +36,9 @@ class SettingsController extends Controller {
array(
'id' => 'various',
'showHidden' => (int)\OCP\Config::getUserValue($this->api->getUserId(), 'tasks_enhanced','various_showHidden'),
- 'startOfWeek' => (int)\OCP\Config::getUserValue($this->api->getUserId(), 'tasks_enhanced','various_startOfWeek')
+ 'startOfWeek' => (int)\OCP\Config::getUserValue($this->api->getUserId(), 'tasks_enhanced','various_startOfWeek'),
+ 'userID' => $this->api->getUserId()
+
)
);
$result = array(
diff --git a/lib/controller/taskscontroller.php b/lib/controller/taskscontroller.php
index 5ac072f0..e18f7811 100644
--- a/lib/controller/taskscontroller.php
+++ b/lib/controller/taskscontroller.php
@@ -149,7 +149,7 @@ class TasksController extends Controller {
/**
* @NoAdminRequired
*/
- public function percentComplete( $percentCompete ){
+ public function percentComplete(){
$response = new JSONResponse();
try{
$percent_complete = $this->params('complete');
@@ -439,15 +439,13 @@ class TasksController extends Controller {
}
}
-
-
return $response;
}
/**
* @NoAdminRequired
*/
- public function setCategories($taskId, $categories){
+ public function setCategories(){
$taskId = $this->params('taskID');
$categories = $this->params('categories');
$response = new JSONResponse();
@@ -465,7 +463,7 @@ class TasksController extends Controller {
/**
* @NoAdminRequired
*/
- public function setLocation($taskId, $location){
+ public function setLocation(){
$taskId = $this->params('taskID');
$location = $this->params('location');
$response = new JSONResponse();
@@ -480,5 +478,93 @@ class TasksController extends Controller {
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/helper.php b/lib/helper.php
index aabecbf7..94ab287a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -169,6 +169,23 @@ Class helper {
$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;
}