From: Michael J. Rubinsky Date: Thu, 17 Sep 2009 00:32:21 +0000 (-0400) Subject: Provide feedback on resource availability as soon as it's added to the attendees... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4215f05a7283992ea4c2fb83b6733a4c4e06c674;p=horde.git Provide feedback on resource availability as soon as it's added to the attendees form. If response type is Kronolith_Resource::RESPONSETYPE_AUTO then use the start and end datetime values that are now passed from the event form to determine if the resource is free. Still need to figure out how to (efficiently) pass the datetime values to take into account AM/PM. Probably break out the javascript from the onClick handler into it's function and provide logic to check the am/pm fields? Is there an easier/prettier way? --- diff --git a/kronolith/attendees.php b/kronolith/attendees.php index d12ff3e2e..0e2fd1e21 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -109,6 +109,15 @@ case 'add': $response = Kronolith::RESPONSE_ACCEPTED; } elseif ($type == Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE) { $response = Kronolith::RESPONSE_DECLINED; + } elseif ($type == Kronolith_Resource::RESPONSETYPE_AUTO) { + // Try to figure out the expected response + $date = new Horde_Date(Horde_Util::getFormData('date')); + $end = new Horde_Date(Horde_Util::getFormData('enddate')); + if ($resource->isFree(array('start' => $date, 'end' => $end))) { + $response = Kronolith::RESPONSE_ACCEPTED; + } else { + $response = Kronolith::RESPONSE_DECLINED; + } } else { $response = Kronolith::RESPONSE_NONE; } diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index 55f230403..241e55ae5 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -16,14 +16,24 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * Determine if the resource is free during the time period for the * supplied event. * - * @param Kronolith_Event $event + * @param mixed $event Either a Kronolith_Event object or an array + * containing start and end times. + * * * @return boolean */ public function isFree($event) { + if (is_array($event)) { + $start = $event['start']; + $end = $event['end']; + } else { + $start = $event->start; + $end = $event->end; + } + /* Fetch events. */ - $busy = Kronolith::listEvents($event->start, $event->end, array($this->get('calendar'))); + $busy = Kronolith::listEvents($start, $end, array($this->get('calendar'))); if ($busy instanceof PEAR_Error) { throw new Horde_Exception($busy->getMessage()); } @@ -35,7 +45,11 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base /* Check for conflicts, ignoring the conflict if it's for the * same event that is passed. */ - $uid = $event->getUID(); + if (!is_array($event)) { + $uid = $event->getUID(); + } else { + $uid = 0; + } $conflicts = 0; foreach ($busy as $events) { foreach ($events as $e) { @@ -43,8 +57,8 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base $e->hasStatus(Kronolith::STATUS_FREE)) && $e->getUID() !== $uid) { - if (!($e->start->compareDateTime($event->end) >= 1 || - $e->end->compareDateTime($event->start) <= -1)) { + if (!($e->start->compareDateTime($end) >= 1 || + $e->end->compareDateTime($start) <= -1)) { $conflicts++; } diff --git a/kronolith/templates/attendees/attendees.inc b/kronolith/templates/attendees/attendees.inc index e8754f34d..77105fe24 100644 --- a/kronolith/templates/attendees/attendees.inc +++ b/kronolith/templates/attendees/attendees.inc @@ -35,7 +35,8 @@ function switchDateView(view, date) - +hour, $date->min) ?>" /> +dateString() . sprintf("%02d%02d00", $end->hour, $end->min) ?>" />

diff --git a/kronolith/templates/edit/edit.inc b/kronolith/templates/edit/edit.inc index 1e1eba902..135a1b03c 100644 --- a/kronolith/templates/edit/edit.inc +++ b/kronolith/templates/edit/edit.inc @@ -244,7 +244,7 @@ if ($event->alarm) { - ' ?> + ' ?>