First attempt at displaying resource FreeBusy info on the attendee view
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 19 Aug 2009 00:16:39 +0000 (20:16 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:48 +0000 (16:53 -0400)
kronolith/attendees.php
kronolith/lib/Driver/Sql.php
kronolith/lib/FreeBusy.php
kronolith/lib/FreeBusy/View.php
kronolith/lib/Resource.php
kronolith/lib/Resource/Single.php
kronolith/lib/View/EditEvent.php
kronolith/resources.php
kronolith/templates/attendees/attendees.inc

index ed45d39..9c28a9e 100644 (file)
@@ -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);
index 65bea9a..7a11f33 100644 (file)
@@ -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.
      *
index 27ffc90..a5d1a67 100644 (file)
@@ -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) {
index f1351bd..8788c55 100644 (file)
@@ -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,
index 15bc6a7..33e2ba4 100644 (file)
@@ -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
index 1181ef6..7a71f72 100644 (file)
@@ -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)
index 23c7498..d535961 100644 (file)
@@ -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;
index 251c6a3..abec90c 100644 (file)
@@ -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
index b650a02..203ab20 100644 (file)
@@ -76,6 +76,35 @@ function switchDateView(view, date)
  <?php $i++; ?>
 <?php endforeach; ?>
 <?php endif; ?>
+
+<!-- resource list header -->
+<tr class="item nowrap leftAlign">
+ <th width="2%">&nbsp;</th>
+ <th width="48%"><?php echo htmlspecialchars(_("Resource")) ?></th>
+ <th width="25%"><?php echo htmlspecialchars(_("Status")) ?></th>
+</tr>
+
+<!--  resources -->
+<?php $i = 0; if (empty($resources)): ?>
+ <tr><td colspan="4"><em><?php echo _("No attendees") ?></em></td></tr>
+<?php else: foreach ($resources as $id => $resource): ?>
+ <tr>
+  <td class="nowrap"><?php echo Horde::img('delete.png', '', null, $registry->getImageDir('horde')) . ' ' . Horde::img('edit.png', '', null, $registry->getImageDir('horde')) . ' ' ?></td>
+  <td><?php echo htmlspecialchars($resource['name']) ?></td>
+  <td>
+    <?php switch ($resource['response']) {
+        case Kronolith::RESPONSE_ACCEPTED:
+            echo _("Accepted");
+            break;
+        case Kronolith::RESPONSE_DECLINED:
+            echo _("Declined");
+            break;
+    } ?>
+  </td>
+ </tr>
+ <?php $i++; ?>
+<?php endforeach; ?>
+<?php endif; ?>
 </table>
 
 <br />