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-17 21:19:50 +0400
committerraimund-schluessler <raimund.schluessler@googlemail.com>2014-07-17 21:19:50 +0400
commit65978357c0279930efeac3cbb90aa9323e923813 (patch)
tree3c9c8e86698dd22c420638c379c65c33acc69e38 /lib
parent51266fb34025dfb0b752bdc06a4e1a00ddb9877b (diff)
Add functions for setting and deleting comments
Diffstat (limited to 'lib')
-rw-r--r--lib/controller/taskscontroller.php68
1 files changed, 54 insertions, 14 deletions
diff --git a/lib/controller/taskscontroller.php b/lib/controller/taskscontroller.php
index ca78f5f8..4a071079 100644
--- a/lib/controller/taskscontroller.php
+++ b/lib/controller/taskscontroller.php
@@ -486,30 +486,70 @@ class TasksController extends Controller {
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;
- // $vtodo->setString('COMMENT', 'haha');
- // $vtodo->setString('COMMENT', 'haha2');
- // $vtodo->setString('COMMENT', 'haha3');
- // $vtodo->offsetSet('USERID','offsetSet');
- // $vtodo->addProperty('COMMENT','haha4');
- $tmp = $vtodo->addProperty('COMMENT','haha6');
- $tmp->offsetSet('USERID','offsetSet');
- // unset($vtodo->COMMENT);
- \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
- $test = $vtodo->getAsArray('COMMENT');
- $test = $vtodo->COMMENT['USERID']->value;
- $response->setData($test);
+ // 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();
+ $now = $now->format('Ymd\THis\Z');
+ $tmp = $vtodo->addProperty('COMMENT',$comment,
+ array(
+ 'ID' => $commentId,
+ 'USERID' => $userId,
+ 'DATE-TIME' => $now
+ )
+ );
+ \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
+ $response->setData();
} catch(\Exception $e) {
// throw new BusinessLayerException($e->getMessage());
}
-
return $response;
}
+ /**
+ * @NoAdminRequired
+ */
+ public function deleteCommentById(){
+ $taskId = $this->params('taskID');
+ $commentId = $this->params('commentID');
+ $userId = $this->api->getUserId();
+ $response = new JSONResponse();
+ $test = array();
+ try {
+ $vcalendar = \OC_Calendar_App::getVCalendar($taskId);
+ $vtodo = $vcalendar->VTODO;
+ $commentIndex = $this->getCommentById($vtodo,$commentId);
+ unset($vtodo->children[$commentIndex]);
+ \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
+ } catch(\Exception $e) {
+ // throw new BusinessLayerException($e->getMessage());
+ }
+ $response->setData($test);
+ 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