Skip to content

Commit

Permalink
Revert "Revert "Display the exceptions in the viewer.""
Browse files Browse the repository at this point in the history
This reverts commit 5afffb0.
  • Loading branch information
mrubinsk committed Jul 29, 2014
1 parent de810b7 commit 5e299e6
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 28 deletions.
184 changes: 158 additions & 26 deletions imp/lib/Mime/Viewer/Itip.php
Expand Up @@ -117,15 +117,16 @@ protected function _renderInline()
}

$out = array();
foreach ($vCal->getComponents() as $key => $component) {
$components = $vCal->getComponents();
foreach ($components as $key => $component) {
switch ($component->getType()) {
case 'vEvent':
try {
if ($component->getAttribute('RECURRENCE-ID')) {
continue;
break;
}
} catch (Horde_ICalendar_Exception $e) {}
$out[] = $this->_vEvent($component, $key, $method);
$out[] = $this->_vEvent($component, $key, $method, $components);
break;

case 'vTodo':
Expand Down Expand Up @@ -245,7 +246,7 @@ protected function _vFreebusy($vfb, $id, $method)
/**
* Generate the HTML for a vEvent.
*/
protected function _vEvent($vevent, $id, $method = 'PUBLISH')
protected function _vEvent($vevent, $id, $method = 'PUBLISH', $components = array())
{
global $injector, $prefs, $registry, $notification;

Expand Down Expand Up @@ -403,34 +404,166 @@ protected function _vEvent($vevent, $id, $method = 'PUBLISH')
$view->loc = $vevent->getAttribute('LOCATION');
} catch (Horde_Icalendar_Exception $e) {}

try {
$rrule = $vevent->getAttribute('RRULE');
if (!is_array($rrule)) {
$recurrence = new Horde_Date_Recurrence(new Horde_Date($view->start));
if (strpos($rrule, '=') !== false) {
$recurrence->fromRRule20($rrule);
} else {
$recurrence->fromRRule10($rrule);
$rrule = $vevent->getAttribute('RRULE');
if (!is_array($rrule)) {
$recurrence = new Horde_Date_Recurrence(new Horde_Date($view->start));
if (strpos($rrule, '=') !== false) {
$recurrence->fromRRule20($rrule);
} else {
$recurrence->fromRRule10($rrule);
}

// Add exceptions
try {
$exdates = $vevent->getAttributeValues('EXDATE');
if (is_array($exdates)) {
foreach ($exdates as $exdate) {
if (is_array($exdate)) {
$recurrence->addException(
(int)$exdate['year'],
(int)$exdate['month'],
(int)$exdate['mday']);
}
}
}
} catch (Horde_ICalendar_Exception $e) {}

// Add exceptions
$view->recurrence = $recurrence->toString($prefs->getValue('date_format'));
$view->exceptions = array();
foreach ($components as $key => $component) {
try {
$exdates = $vevent->getAttributeValues('EXDATE');
if (is_array($exdates)) {
foreach ($exdates as $exdate) {
if (is_array($exdate)) {
$recurrence->addException(
(int)$exdate['year'],
(int)$exdate['month'],
(int)$exdate['mday']);
}
if ($component->getAttribute('RECURRENCE-ID') && $component->getAttribute('UID') == $vevent->getAttribute('UID')) {
$view->exceptions[] = $this->_vEventException($component, $key, $method);
}
} catch (Horde_Icalendar_Exception $e) {}
}
}

if (!empty($attendees)) {
$view->attendees = $this->_parseAttendees($vevent, $attendees);
}

if (!is_null($start) &&
!is_null($end) &&
in_array($method, array('PUBLISH', 'REQUEST', 'ADD')) &&
$registry->hasMethod('calendar/getFbCalendars') &&
$registry->hasMethod('calendar/listEvents')) {
try {
$calendars = $registry->call('calendar/getFbCalendars');

$vevent_start = new Horde_Date($start);
$vevent_end = new Horde_Date($end);

// Check if it's an all-day event.
if (is_array($start)) {
$vevent_allDay = true;
$vevent_end = $vevent_end->sub(1);
} else {
$vevent_allDay = false;
$time_span_start = $vevent_start->sub($prefs->getValue('conflict_interval') * 60);
$time_span_end = $vevent_end->add($prefs->getValue('conflict_interval') * 60);
}

$events = $registry->call('calendar/listEvents', array($start, $vevent_end, $calendars, false));

// TODO: Check if there are too many events to show.
$conflicts = array();
foreach ($events as $calendar) {
foreach ($calendar as $event) {
// TODO: WTF? Why are we using Kronolith constants
// here?
if (in_array($event->status, array(Kronolith::STATUS_CANCELLED, Kronolith::STATUS_FREE))) {
continue;
}

if ($vevent_allDay || $event->isAllDay()) {
$type = 'collision';
} elseif (($event->end->compareDateTime($time_span_start) <= -1) ||
($event->start->compareDateTime($time_span_end) >= 1)) {
continue;
} elseif (($event->end->compareDateTime($vevent_start) <= -1) ||
($event->start->compareDateTime($vevent_end) >= 1)) {
$type = 'nearcollision';
} else {
$type = 'collision';
}

$conflicts[] = array(
'collision' => ($type == 'collision'),
'range' => $event->getTimeRange(),
'title' => $event->getTitle()
);
}
} catch (Horde_ICalendar_Exception $e) {}
}

$view->recurrence = $recurrence->toString($prefs->getValue('date_format'));
if (!empty($conflicts)) {
$view->conflicts = $conflicts;
}
} catch (Horde_Exception $e) {}
}

if (!empty($options)) {
reset($options);
$view->options = $options;
$view->options_id = $id;
}

return $view->render('action');
}

/**
* Generate the HTML for a vEvent.
*/
protected function _vEventException($vevent, $id, $method = 'PUBLISH')
{
global $injector, $prefs, $registry, $notification;

$attendees = null;
$desc = '';
$options = array();

try {
if (($attendees = $vevent->getAttribute('ATTENDEE')) &&
!is_array($attendees)) {
$attendees = array($attendees);
}
} catch (Horde_ICalendar_Exception $e) {}
} catch (Horde_Icalendar_Exception $e) {}

$view = $this->_getViewOb();

try {
$start = $vevent->getAttribute('DTSTART');
$view->start = is_array($start)
? strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $start['month'], $start['mday'], $start['year']))
: strftime($prefs->getValue('date_format'), $start) . ' ' . date($prefs->getValue('twentyFour') ? ' G:i' : ' g:i a', $start);
} catch (Horde_Icalendar_Exception $e) {
$start = null;
}

try {
$end = $vevent->getAttribute('DTEND');
$view->end = is_array($end)
? strftime($prefs->getValue('date_format'), mktime(0, 0, 0, $end['month'], $end['mday'] - 1, $end['year']))
: strftime($prefs->getValue('date_format'), $end - 1) . ' ' . date($prefs->getValue('twentyFour') ? ' G:i' : ' g:i a', $end - 1);
} catch (Horde_Icalendar_Exception $e) {
$end = null;
}

try {
$summary = $vevent->getAttribute('SUMMARY');
$view->summary = $summary;
} catch (Horde_Icalendar_Exception $e) {
$summary = _("Unknown Meeting");
$view->summary_error = _("None");
}

try {
$view->desc2 = $vevent->getAttribute('DESCRIPTION');
} catch (Horde_Icalendar_Exception $e) {}

try {
$view->loc = $vevent->getAttribute('LOCATION');
} catch (Horde_Icalendar_Exception $e) {}

if (!empty($attendees)) {
$view->attendees = $this->_parseAttendees($vevent, $attendees);
Expand All @@ -443,7 +576,6 @@ protected function _vEvent($vevent, $id, $method = 'PUBLISH')
$registry->hasMethod('calendar/listEvents')) {
try {
$calendars = $registry->call('calendar/getFbCalendars');

$vevent_start = new Horde_Date($start);
$vevent_end = new Horde_Date($end);

Expand Down
11 changes: 9 additions & 2 deletions imp/templates/itip/action.html.php
@@ -1,5 +1,6 @@
<?php if (strlen($this->desc)): ?>
<h2 class="header"><?php echo $this->h($this->desc) ?></h2>

<?php endif; ?>
<table class="horde-table imp-itip">
<?php if (strlen($this->start)): ?>
<tr>
Expand Down Expand Up @@ -55,9 +56,15 @@
<td><?php echo nl2br($this->h($this->recurrence)) ?></td>
</tr>
<?php endif; ?>

</table>

<?php if (!empty($this->exceptions)): ?>
<h2 class="smallheader"><?php echo _("Exceptions") ?>:</h2>
<?php foreach ($this->exceptions as $exception): ?>
<?php echo $exception ?><br />
<?php endforeach; ?>
<?php endif; ?>

<?php if (isset($this->attendees)): ?>
<h2 class="smallheader"><?php echo _("Attendees") ?>:</h2>

Expand Down

0 comments on commit 5e299e6

Please sign in to comment.