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-05-06 22:12:03 +0400
committerraimund-schluessler <raimund.schluessler@googlemail.com>2014-05-06 22:12:03 +0400
commit6cdfb6cb6895d77fc08d62d2543c3c33a415281f (patch)
tree9cd42d795689b212c8b7f9e77aa97289f6dbf02a /lib
parentb4d84ffdb830691bea1452eb94c67fa29bcb8478 (diff)
Set reminders of any type
Diffstat (limited to 'lib')
-rw-r--r--lib/controller/taskscontroller.php51
-rw-r--r--lib/helper.php55
2 files changed, 93 insertions, 13 deletions
diff --git a/lib/controller/taskscontroller.php b/lib/controller/taskscontroller.php
index c4b6f1c0..6d77aed6 100644
--- a/lib/controller/taskscontroller.php
+++ b/lib/controller/taskscontroller.php
@@ -356,6 +356,8 @@ class TasksController extends Controller {
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)) {
@@ -369,21 +371,60 @@ class TasksController extends Controller {
} else {
unset($valarm->TRIGGER);
}
- $triggervalue = '';
+ $tv = '';
+ $related = null;
if ($type == 'DATE-TIME') {
$date = new \DateTime('@'.$this->params('date'));
- $triggervalue = $date->format('Ymd\THis\Z');
+ $tv = $date->format('Ymd\THis\Z');
} elseif ($type == 'DURATION') {
- // TODO
- $triggervalue = '-PT5M';
+ $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';
+ }
}
- $valarm->addProperty('TRIGGER', $triggervalue, array('VALUE' => $type));
+ 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;
}
diff --git a/lib/helper.php b/lib/helper.php
index 86165bf2..016d6bf0 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -36,6 +36,7 @@ Class helper {
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');
@@ -70,30 +71,68 @@ Class helper {
try {
$reminderType = $reminder->TRIGGER['VALUE']->value;
- $reminderTrigger = $reminder->TRIGGER->value;
$reminderAction = $reminder->ACTION->value;
- $parsed1 = null;
+
if($reminderType == 'DATE-TIME'){
$reminderDate = $reminder->TRIGGER->getDateTime();
$reminderDate->setTimezone(new \DateTimeZone($user_timezone));
$reminderDate = $reminderDate->format('Ymd\THis');
- } elseif ($reminderType == 'DURATION' && $start) {
- $parsed_complete = VObject\DateTimeParser::parseDuration($reminder->TRIGGER);
+ } elseif ($reminderType == 'DURATION' && ($start || $due)) {
+
$parsed = VObject\DateTimeParser::parseDuration($reminder->TRIGGER,true);
// Calculate the reminder date from duration and start date
- $reminderDate = $start->modify($parsed)->format('Ymd\THis');
+ if($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.');
+ }
+ $result = 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)($reminder->TRIGGER['RELATED']->value == 'END'),
+ 'related'=> $reminder->TRIGGER['RELATED']->value?$reminder->TRIGGER['RELATED']->value:'START',
+ 'invert'=> $invert
+ );
+
} else {
$reminderDate = null;
+ $reminderDuration = null;
}
-
$task['reminder'] = array(
'type' => $reminderType,
- 'trigger' => $reminderTrigger,
'action' => $reminderAction,
'date' => $reminderDate,
- 'duration' => $parsed_complete
+ 'duration' => $reminderDuration
);
} catch(\Exception $e) {