From 6b8c1d5c45edc2e5f30c2ba081f81022cb434380 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Tue, 18 Aug 2009 20:16:39 -0400 Subject: [PATCH] First attempt at displaying resource FreeBusy info on the attendee view --- kronolith/attendees.php | 13 +++++++++++++ kronolith/lib/Driver/Sql.php | 20 +++++++++++++++++--- kronolith/lib/FreeBusy.php | 15 +++++++++++---- kronolith/lib/FreeBusy/View.php | 27 +++++++++++++++++++++++++++ kronolith/lib/Resource.php | 8 ++++++++ kronolith/lib/Resource/Single.php | 6 +++++- kronolith/lib/View/EditEvent.php | 2 +- kronolith/resources.php | 4 +++- kronolith/templates/attendees/attendees.inc | 29 +++++++++++++++++++++++++++++ 9 files changed, 114 insertions(+), 10 deletions(-) diff --git a/kronolith/attendees.php b/kronolith/attendees.php index ed45d39ef..9c28a9e9d 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -17,6 +17,12 @@ $attendees = (isset($_SESSION['kronolith']['attendees']) && : array(); $editAttendee = null; +$resources = (isset($_SESSION['kronolith']['resources']) && + is_array($_SESSION['kronolith']['resources'])) + ? $_SESSION['kronolith']['resources'] + : array(); +$editResource = null; + // Get the action ID and value. This specifies what action the user initiated. $actionID = Horde_Util::getFormData('actionID'); if (Horde_Util::getFormData('clearAll')) { @@ -242,6 +248,13 @@ foreach ($attendees as $email => $status) { } } +// Add Free/Busy for resources +foreach ($resources as $r_id => $resource) { + $r = Kronolith_Resource::getResource($r_id); + $vfb = $r->getFreeBusy(null, null, true); + $attendee_view->addResourceMember($vfb); +} + $date = Horde_Util::getFormData('date', date('Ymd')) . '000000'; $date = new Horde_Date($date); $vfb_html = $attendee_view->render($date); diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 65bea9a35..7a11f3387 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -308,7 +308,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver ' event_recurtype, event_recurenddate, event_recurinterval,' . ' event_recurdays, event_start, event_end, event_allday,' . ' event_alarm, event_alarm_methods, event_modified,' . - ' event_exceptions, event_creator_id' . + ' event_exceptions, event_creator_id, event_resources' . ' FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?'; $values = array($this->_calendar); @@ -419,7 +419,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver ' event_recurtype, event_recurenddate, event_recurinterval,' . ' event_recurdays, event_start, event_end, event_allday,' . ' event_alarm, event_alarm_methods, event_modified,' . - ' event_exceptions, event_creator_id' . + ' event_exceptions, event_creator_id, event_resources' . ' FROM ' . $this->_params['table'] . ' WHERE event_id = ? AND calendar_id = ?'; $values = array($eventId, $this->_calendar); @@ -460,7 +460,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver ' event_recurtype, event_recurenddate, event_recurinterval,' . ' event_recurdays, event_start, event_end, event_allday,' . ' event_alarm, event_alarm_methods, event_modified,' . - ' event_exceptions, event_creator_id' . + ' event_exceptions, event_creator_id, event_resources' . ' FROM ' . $this->_params['table'] . ' WHERE event_uid = ?'; $values = array($uid); @@ -807,6 +807,20 @@ class Kronolith_Driver_Sql extends Kronolith_Driver return $return; } + public function getResourceIdByCalendar($calendar) + { + $query = 'SELECT resource_id FROM kronolith_resources WHERE resource_calendar = ?'; + $results = $this->_db->getOne($query, array($calendar)); + if ($results instanceof PEAR_Error) { + throw new Horde_Exception($results->getMessage()); + } + if (empty($results)) { + throw new Horde_Exception('Resource not found'); + } + + return $results; + } + /** * Attempts to open a connection to the SQL server. * diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index 27ffc9037..a5d1a676a 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -6,7 +6,6 @@ * @package Kronolith */ class Kronolith_FreeBusy { - /** * Generates the free/busy text for $calendar. Cache it for at least an * hour, as well. @@ -34,7 +33,15 @@ class Kronolith_FreeBusy { /* Fetch the appropriate share and check permissions. */ $share = &$kronolith_shares->getShare($calendar[0]); if (is_a($share, 'PEAR_Error')) { - return $returnObj ? $share : ''; + // Might be a Kronolith_Resource + try { + $resource = Kronolith_Resource::isResourceCalendar($calendar[0]); + $owner = $calendar[0]; + } catch (Horde_Exception $e) { + return $returnObj ? $share : ''; + } + } else { + $owner = $share->get('owner'); } /* Default the start date to today. */ @@ -53,7 +60,7 @@ class Kronolith_FreeBusy { /* Get the Identity for the owner of the share. */ $identity = &Identity::singleton('none', - $user ? $user : $share->get('owner')); + $user ? $user : $owner); $email = $identity->getValue('from_addr'); $cn = $identity->getValue('fullname'); @@ -83,7 +90,7 @@ class Kronolith_FreeBusy { $vFb->setAttribute('DTSTAMP', $_SERVER['REQUEST_TIME']); $vFb->setAttribute('DTSTART', $startstamp); $vFb->setAttribute('DTEND', $endstamp); - $vFb->setAttribute('URL', Horde::applicationUrl('fb.php?u=' . $share->get('owner'), true, -1)); + $vFb->setAttribute('URL', Horde::applicationUrl('fb.php?u=' . $owner, true, -1)); /* Add all the busy periods. */ foreach ($busy as $events) { diff --git a/kronolith/lib/FreeBusy/View.php b/kronolith/lib/FreeBusy/View.php index f1351bd89..8788c5536 100644 --- a/kronolith/lib/FreeBusy/View.php +++ b/kronolith/lib/FreeBusy/View.php @@ -14,6 +14,7 @@ class Kronolith_FreeBusy_View { var $_requiredMembers = array(); var $_optionalMembers = array(); + var $_resourceMembers = array(); var $_timeBlocks = array(); var $_startHour; @@ -32,6 +33,11 @@ class Kronolith_FreeBusy_View { $this->_optionalMembers[] = clone $vFreebusy; } + function addResourceMember($vFreebusy) + { + $this->_resourceMembers[] = clone $vFreebusy; + } + function render($day = null) { global $prefs; @@ -118,6 +124,27 @@ class Kronolith_FreeBusy_View { $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); } + // Resources + if (count($this->_resourceMembers) > 0) { + $template = new Horde_Template(); + $rows = ''; + foreach ($this->_resourceMembers as $member) { + $member->simplify(); + $blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy")); + $template = new Horde_Template(); + $template->set('blocks', $blocks); + $template->set('name', $member->getName()); + $rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html'); + } + $template = new Horde_Template(); + $template->set('title', _("Resources")); + $template->set('rows', $rows); + $template->set('span', count($this->_timeBlocks)); + $template->set('hours', $hours_html); + $template->set('legend', ''); + $html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html'); + } + // Possible meeting times. $optimal->setAttribute('ORGANIZER', _("All Attendees")); $blocks = $this->_getBlocks($optimal, diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index 15bc6a74c..33e2ba4ee 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -62,4 +62,12 @@ class Kronolith_Resource return new Kronolith_Resource_Single($driver->getResource($id)); } + static public function isResourceCalendar($calendar) + { + $driver = Kronolith::getDriver('Sql'); + $resource = $driver->getResourceIdByCalendar($calendar); + + return $resource > 0; + } + } \ No newline at end of file diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index 1181ef6b2..7a71f7252 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -68,9 +68,13 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * for all the resources in the group. * @return unknown_type */ - public function getFreeBusy() + public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false) { + $vfb = Kronolith_Freebusy::generate($this->calendar, $startstamp, $endstamp, $asObject); + $vfb->removeAttribute('ORGANIZER'); + $vfb->setAttribute('ORGANIZER', $this->name); + return $vfb; } public function setId($id) diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index 23c7498bd..d5359618a 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -51,7 +51,7 @@ class Kronolith_View_EditEvent { $calendar_id .= ':' . $share->get('owner'); } $_SESSION['kronolith']['attendees'] = $this->event->getAttendees(); - + $_SESSION['kronolith']['resources'] = $this->event->getResources(); if ($datetime = Horde_Util::getFormData('datetime')) { $datetime = new Horde_Date($datetime); $month = $datetime->month; diff --git a/kronolith/resources.php b/kronolith/resources.php index 251c6a3f9..abec90c16 100644 --- a/kronolith/resources.php +++ b/kronolith/resources.php @@ -19,6 +19,8 @@ $new = array('name' => _("N329SP"), /* Test adding resource to event */ $resource = Kronolith_Resource::getResource(6); $driver = Kronolith::getDriver('Sql'); -$event = $driver->getByUID('20090610181329.12687chinwtntsg8@localhost'); +$event = $driver->getByUID('20090817131028.10427ipjxgq69hk4@localhost'); $event->addResource($resource, Kronolith::RESPONSE_NONE); $event->save(); + +var_dump($resource->getFreeBusy(null, null, true)); \ No newline at end of file diff --git a/kronolith/templates/attendees/attendees.inc b/kronolith/templates/attendees/attendees.inc index b650a0252..203ab20bc 100644 --- a/kronolith/templates/attendees/attendees.inc +++ b/kronolith/templates/attendees/attendees.inc @@ -76,6 +76,35 @@ function switchDateView(view, date) + + + +   + + + + + + + + $resource): ?> + + getImageDir('horde')) . ' ' . Horde::img('edit.png', '', null, $registry->getImageDir('horde')) . ' ' ?> + + + + + + + +
-- 2.11.0