Add RSVP status to an event attendee (currently true by default)

This commit is contained in:
Thomas 2011-08-14 15:35:22 +02:00
parent 79ef805743
commit 944da9228f
4 changed files with 39 additions and 5 deletions

View file

@ -1245,11 +1245,14 @@ class calendar extends rcube_plugin
$organizer = true; $organizer = true;
if ($attendee['email'] == $identity['email']) if ($attendee['email'] == $identity['email'])
$owner = $i; $owner = $i;
else if (!isset($attendee['rsvp']))
$event['attendees'][$i]['rsvp'] = true;
} }
// set owner as organizer if yet missing // set owner as organizer if yet missing
if (!$organizer && $owner !== false) { if (!$organizer && $owner !== false) {
$event['attendees'][$i]['role'] = 'ORGANIZER'; $event['attendees'][$i]['role'] = 'ORGANIZER';
unset($event['attendees'][$i]['rsvp']);
} }
else if (!$organizer && $identity['email'] && $action == 'new') { else if (!$organizer && $identity['email'] && $action == 'new') {
array_unshift($event['attendees'], array('role' => 'ORGANIZER', 'name' => $identity['name'], 'email' => $identity['email'], 'status' => 'ACCEPTED')); array_unshift($event['attendees'], array('role' => 'ORGANIZER', 'name' => $identity['name'], 'email' => $identity['email'], 'status' => 'ACCEPTED'));

View file

@ -64,6 +64,7 @@
* 'email' => 'Participant e-mail address', // used as identifier * 'email' => 'Participant e-mail address', // used as identifier
* 'role' => 'ORGANIZER|REQ-PARTICIPANT|OPT-PARTICIPANT|CHAIR', * 'role' => 'ORGANIZER|REQ-PARTICIPANT|OPT-PARTICIPANT|CHAIR',
* 'status' => 'NEEDS-ACTION|UNKNOWN|ACCEPTED|TENTATIVE|DECLINED' * 'status' => 'NEEDS-ACTION|UNKNOWN|ACCEPTED|TENTATIVE|DECLINED'
* 'rsvp' => true|false,
* ), * ),
* ); * );
*/ */

View file

@ -550,6 +550,7 @@ class kolab_calendar
'name' => $attendee['display-name'], 'name' => $attendee['display-name'],
'email' => $attendee['smtp-address'], 'email' => $attendee['smtp-address'],
'status' => $status_map[$attendee['status']], 'status' => $status_map[$attendee['status']],
'rsvp' => $attendee['request-response'],
); );
$_attendees .= $rec['organizer']['display-name'] . ' ' . $rec['organizer']['smtp-address'] . ' '; $_attendees .= $rec['organizer']['display-name'] . ' ' . $rec['organizer']['smtp-address'] . ' ';
} }
@ -737,6 +738,7 @@ class kolab_calendar
'smtp-address' => $attendee['email'], 'smtp-address' => $attendee['email'],
'status' => $this->status_map[$attendee['status']], 'status' => $this->status_map[$attendee['status']],
'role' => $this->role_map[$role], 'role' => $this->role_map[$role],
'request-response' => $attendee['rsvp'],
); );
} }
} }

View file

@ -41,6 +41,9 @@ class calendar_ical
private $cal; private $cal;
private $timezone = 'Z'; private $timezone = 'Z';
public $method;
public $events = array();
function __construct($cal) function __construct($cal)
{ {
$this->cal = $cal; $this->cal = $cal;
@ -70,15 +73,16 @@ class calendar_ical
$parser = new Horde_iCalendar; $parser = new Horde_iCalendar;
$parser->parsevCalendar($vcal, 'VCALENDAR', $charset); $parser->parsevCalendar($vcal, 'VCALENDAR', $charset);
$events = array(); $this->method = $parser->getAttributeDefault('METHOD', '');
$this->events = array();
if ($data = $parser->getComponents()) { if ($data = $parser->getComponents()) {
foreach ($data as $comp) { foreach ($data as $comp) {
if ($comp->getType() == 'vEvent') if ($comp->getType() == 'vEvent')
$events[] = $this->_to_rcube_format($comp); $this->events[] = $this->_to_rcube_format($comp);
} }
} }
return $events; return $this->events;
} }
/** /**
@ -100,11 +104,11 @@ class calendar_ical
// check for all-day dates // check for all-day dates
if (is_array($event['start'])) { if (is_array($event['start'])) {
// create timestamp at 00:00 in user's timezone // create timestamp at 00:00 in user's timezone
$event['start'] = strtotime(sprintf('%04d%02d%02dT000000%s', $event['start']['year'], $event['start']['month'], $event['start']['mday'], $this->timezone)); $event['start'] = $this->_date2time($event['start']);
$event['allday'] = true; $event['allday'] = true;
} }
if (is_array($event['end'])) { if (is_array($event['end'])) {
$event['end'] = strtotime(sprintf('%04d%02d%02dT000000%s', $event['end']['year'], $event['end']['month'], $event['end']['mday'], $this->timezone)) - 60; $event['end'] = $this->_date2time($event['end']) - 60;
} }
// map other attributes to internal fields // map other attributes to internal fields
@ -172,6 +176,10 @@ class calendar_ical
case 'EXDATE': case 'EXDATE':
break; break;
case 'RECURRENCE-ID':
$event['recurrence_id'] = $this->_date2time($attr['value']);
break;
case 'DESCRIPTION': case 'DESCRIPTION':
case 'LOCATION': case 'LOCATION':
$event[strtolower($attr['name'])] = $attr['value']; $event[strtolower($attr['name'])] = $attr['value'];
@ -203,6 +211,24 @@ class calendar_ical
return $event; return $event;
} }
/**
* Helper method to correctly interpret an all-day date value
*/
private function _date2time($prop)
{
// create timestamp at 00:00 in user's timezone
return is_array($prop) ? strtotime(sprintf('%04d%02d%02dT000000%s', $prop['year'], $prop['month'], $prop['mday'], $this->timezone)) : $prop;
}
/**
* Free resources by clearing member vars
*/
public function reset()
{
$this->method = '';
$this->events = array();
}
/** /**
* Export events to iCalendar format * Export events to iCalendar format
@ -329,6 +355,8 @@ class calendar_ical
else { else {
//I am an attendee //I am an attendee
$attendees .= "ATTENDEE;ROLE=" . $at['role'] . ";PARTSTAT=" . $at['status']; $attendees .= "ATTENDEE;ROLE=" . $at['role'] . ";PARTSTAT=" . $at['status'];
if ($at['rsvp'])
$attendees .= ";RSVP=TRUE";
if (!empty($at['name'])) if (!empty($at['name']))
$attendees .= ';CN="' . $at['name'] . '"'; $attendees .= ';CN="' . $at['name'] . '"';
$attendees .= ":mailto:" . $at['email'] . self::EOL; $attendees .= ":mailto:" . $at['email'] . self::EOL;