Stqrt hashing out the isFree() method. Remove deprecated Resource.php file, phpdoc
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 8 Sep 2009 16:44:47 +0000 (12:44 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:51 +0000 (16:53 -0400)
kronolith/lib/Event/Sql.php
kronolith/lib/Resource.php [deleted file]
kronolith/lib/Resource/Single.php
kronolith/resources.php

index 93cd981..6d751e0 100644 (file)
@@ -210,7 +210,7 @@ class Kronolith_Event_Sql extends Kronolith_Event
     /**
      * Function to check availability and auto accept/decline for each resource
      * attached to this event. Needed here instead of in Kronolith_Driver::saveEvent
-     * since the _properties array is already built at that point.
+     * since self::_properties is already built at that point.
      *
      * @return unknown_type
      */
diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php
deleted file mode 100644 (file)
index db84dda..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
- * Base class for dealing with Kronolith_Resource objects. Handles basic
- * creation/deletion/listing by delegating to the underlying Kronolith_Driver
- * object.
- *
- * For now, assume SQL driver only. Could probably easily extend this to use
- * different backend drivers if/when support is added to those drivers for
- * resources.
- *
- * Copyright 2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Kronolith
- */
-class Kronolith_Resource
-{
-    static protected $_driver;
-
-    /**
-     * Removes a resource from storage
-     *
-     * @param Kronolith_Resource $resource
-     * @return boolean
-     * @throws Horde_Exception
-     */
-    static public function removeResource($resource)
-    {
-
-    }
-
-    static public function isResourceCalendar($calendar)
-    {
-        if (strncmp($calendar, 'resource_', 9) === 0) {
-            return true;
-        }
-    }
-
-}
\ No newline at end of file
index f22da70..8f942ec 100644 (file)
@@ -22,6 +22,30 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
      */
     public function isFree($event)
     {
+        // Need to make sure to remove the $event's fb info from this calendar
+        // before checking...otherwise, if it's an update the time will block.
+        $old_status = $event->status;
+        $event->setStatus(Kronolith::STATUS_FREE);
+
+        /* Fetch events. */
+        $busy = Kronolith::listEvents($event->start, $event->end, $this->calendar);
+        if (is_a($busy, 'PEAR_Error')) {
+            return $busy;
+        }
+
+        if (!count($busy)) {
+            return true;
+        }
+
+        foreach ($busy as $e) {
+            if (!($e->hasStatus(Kronolith::STATUS_CANCELLED) ||
+                  $e->hasStatus(Kronolith::STATUS_FREE))) {
+
+                return false;
+            }
+        }
+
+        $event->setStatus($old_status);
         return true;
     }
 
@@ -41,7 +65,9 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
         $uid = $event->getUID();
         $existing = $driver->getByUID($uid, array($this->calendar));
         if (!($existing instanceof PEAR_Error)) {
+            /* Already attached, just update */
             $existing->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
+            $existing->status = $event->status;
             $existing->save();
         } else {
             /* Create a new event */
index 7dd71a9..cffeebe 100644 (file)
@@ -72,10 +72,10 @@ var_dump($resources);
 $resource = Kronolith::getDriver('Resource')->getResource(9);
 
 /* Any driver/event */
-$driver = Kronolith::getDriver('Sql');
-$event = $driver->getByUID('20090903183552.146242hgs864c92c@localhost');
-$event->addResource($resource, Kronolith::RESPONSE_NONE);
-$event->save();
+//$driver = Kronolith::getDriver('Sql');
+//$event = $driver->getByUID('20090904121938.17551lvwtt52y728@localhost');
+//$event->addResource($resource, Kronolith::RESPONSE_NONE);
+//$event->save();
 
 
 //