From: Michael J. Rubinsky Date: Fri, 4 Sep 2009 00:08:49 +0000 (-0400) Subject: resource event delettion, start building a useful resource page... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=da2812a55a55da147580f9ca3002c42a307fb1f9;p=horde.git resource event delettion, start building a useful resource page... Make sure we delete the resource from the 'original' event when directly deleting the resource's copy of the event. Fix some variable/method names Start building a resorce management page. --- diff --git a/kronolith/calendars/index.php b/kronolith/calendars/index.php index 88c08638c..65425f2be 100644 --- a/kronolith/calendars/index.php +++ b/kronolith/calendars/index.php @@ -61,12 +61,6 @@ $edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('hord $perms_img = Horde::img('perms.png', _("Change Permissions"), null, $registry->getImageDir('horde')); $delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde')); -/* @TODO: Show resources? */ -$resources = array(); -//$resources = Kronolith::listResources(); -//var_dump($resources); - - Horde::addScriptFile('tables.js', 'horde', true); $title = _("Manage Calendars"); require KRONOLITH_TEMPLATES . '/common-header.inc'; diff --git a/kronolith/lib/Driver/Resource.php b/kronolith/lib/Driver/Resource.php index 051a72589..d732dffa4 100644 --- a/kronolith/lib/Driver/Resource.php +++ b/kronolith/lib/Driver/Resource.php @@ -383,14 +383,36 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql return $resource; } + /** + * Delete an event. + * + * Since this is the Kronolith_Resource's version of the event, if we + * delete it, we must also make sure to remove it from the event that + * it is attached to. Not sure if there is a better way to do this... + * + * @see lib/Driver/Kronolith_Driver_Sql#deleteEvent($eventId, $silent) + */ public function deleteEvent($event, $silent = false) { - parent::deleteEvent($event, $silent); - - /* @TODO: Since this is being removed from a resource calendar, need to - * make sure we remove any acceptance status from the event it's - * attached to. + /* Since this is the Kronolith_Resource's version of the event, if we + * delete it, we must also make sure to remove it from the event that + * it is attached to. Not sure if there is a better way to do this... */ + $delete_event = $this->getEvent($event); + $uid = $delete_event->getUID(); + $driver = Kronolith::getDriver(); + $events = $driver->getByUID($uid, null, true); + foreach ($events as $e) { + $resources = $e->getResources(); + if (count($resources)) { + // found the right entry + $r = $this->getResource($this->getResourceIdByCalendar($delete_event->getCalendar())); + $e->removeResource($r); + $e->save(); + } + } + + parent::deleteEvent($event, $silent); } /** diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 2955f7c25..37741c606 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -736,7 +736,8 @@ class Kronolith_Driver_Sql extends Kronolith_Driver } /* Remove the event from any resources that are attached to it */ - if (count($resources = $event->getResources())) { + $resources = $event->getResources(); + if (count($resources)) { $rd = Kronolith::getDriver('Resource'); foreach (array_keys($resources) as $uid) { $r = $rd->getResource($uid); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index e17bdebd9..0af8f73b9 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -1568,8 +1568,8 @@ abstract class Kronolith_Event */ function removeResource($resource) { - if (isset($this->_resources[$resource->uid])) { - unset ($this->_resources[$resource->uid]); + if (isset($this->_resources[$resource->id])) { + unset ($this->_resources[$resource->id]); } } diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index bee52b313..93cd9818c 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -217,7 +217,7 @@ class Kronolith_Event_Sql extends Kronolith_Event public function checkResources() { foreach ($this->_resources as $id => $resource) { - $r = $this->getDriver()->getResource($id); + $r = Kronolith::getDriver('Resource')->getResource($id); if ($r->isFree($this)) { $r->addEvent($this); $this->addResource($r, Kronolith::RESPONSE_ACCEPTED); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 982423791..eb35057f9 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -318,6 +318,9 @@ class Kronolith /* Resource calendars (this would only be populated if explicitly * requested in the request, so include them if this is set regardless * of $calendars value). + * + * @TODO: Should we disallow even *viewing* these if the user is not an + * admin? */ if (!empty($GLOBALS['display_resource_calendars'])) { $driver = self::getDriver('Resource'); diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index f03e5b9d0..f22da70eb 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -36,7 +36,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base public function addEvent($event) { /* Get a driver for this resource's calendar */ - $driver = Kronolith::getDriver(null, $this->calendar); + $driver = Kronolith::getDriver('Resource', $this->calendar); /* Make sure it's not already attached. */ $uid = $event->getUID(); $existing = $driver->getByUID($uid, array($this->calendar)); @@ -60,7 +60,9 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base */ public function removeEvent($event) { - + $driver = Kronolith::getDriver('Resource', $this->calendar); + $re = $driver->getByUID($event->getUID(), array($this->calendar)); + $driver->deleteEvent($re->getId()); } /** diff --git a/kronolith/lib/View/Week.php b/kronolith/lib/View/Week.php index 23a57100d..bd259dab8 100644 --- a/kronolith/lib/View/Week.php +++ b/kronolith/lib/View/Week.php @@ -69,7 +69,7 @@ class Kronolith_View_Week { $day->mday++; } $endDate = new Horde_Date($day); - $allevents = Kronolith::listEvents($this->startDate, $endDate, $GLOBALS['display_calendars']); + $allevents = Kronolith::listEvents($this->startDate, $endDate); if (is_a($allevents, 'PEAR_Error')) { $GLOBALS['notification']->push($allevents, 'horde.error'); $allevents = array(); diff --git a/kronolith/resources.php b/kronolith/resources.php index 6a6e8283a..7dd71a9c0 100644 --- a/kronolith/resources.php +++ b/kronolith/resources.php @@ -6,8 +6,60 @@ require_once dirname(__FILE__) . '/lib/base.php'; $title = _("Edit resources"); + +$resources = array(); +$resources = Kronolith::listResources(); +$display_url_base = Horde::applicationUrl('month.php', true, -1); + + require KRONOLITH_TEMPLATES . '/common-header.inc'; require KRONOLITH_TEMPLATES . '/menu.inc'; + +?> + +
+ +

+ +

+ +
+ + " /> +
+ +" cellspacing="0" id="calendar-list" class="striped sortable"> + + + + + + + + + + + + + + +
name) ?>calendar, false); echo Horde::link($url, _("Click or copy this URL to display this calendar"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '' ?>
+ $max_length) { + return substr_replace($url, $separator, $first_chunk_length, -$last_chunk_length); + } + + return $url; +} +var_dump($resources); /* Test creating a new resource */ //$new = array('name' => _("Another Big Meeting Room"), // 'category' => 'conference rooms'); @@ -17,11 +69,11 @@ require KRONOLITH_TEMPLATES . '/menu.inc'; //var_dump($results); /* Test adding resource to event */ -$resource = Kronolith::getResource(9); +$resource = Kronolith::getDriver('Resource')->getResource(9); /* Any driver/event */ $driver = Kronolith::getDriver('Sql'); -$event = $driver->getByUID('20090831145736.98833ff01g9m338k@localhost'); +$event = $driver->getByUID('20090903183552.146242hgs864c92c@localhost'); $event->addResource($resource, Kronolith::RESPONSE_NONE); $event->save(); @@ -30,4 +82,6 @@ $event->save(); ////var_dump($resource->getFreeBusy(null, null, true)); // /* Test listing resources */ -//var_dump(Kronolith::listResources()); \ No newline at end of file +//var_dump(Kronolith::listResources()); +?> +
\ No newline at end of file