Remove already added resources from the select list.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 12 Sep 2009 16:04:25 +0000 (12:04 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:54 +0000 (16:53 -0400)
Also have listResources() return the results keyed by the resource_id

kronolith/attendees.php
kronolith/lib/Driver/Resource.php
kronolith/templates/attendees/attendees.inc

index 9665197..d12ff3e 100644 (file)
@@ -21,7 +21,6 @@ $resources = (isset($_SESSION['kronolith']['resources']) &&
               is_array($_SESSION['kronolith']['resources']))
     ? $_SESSION['kronolith']['resources']
     : array();
-$allResources = Kronolith_Resource::listResources();
 
 // Get the action ID and value. This specifies what action the user initiated.
 $actionID = Horde_Util::getFormData('actionID');
@@ -228,6 +227,12 @@ case 'clear':
     break;
 }
 
+/* Get list of resources for select list, and remove those we already added */
+$allResources = Kronolith_Resource::listResources();
+foreach (array_keys($resources) as $id) {
+    unset($allResources[$id]);
+}
+
 // Get the current Free/Busy view; default to the 'day' view if none specified.
 $view = Horde_Util::getFormData('view', 'Day');
 
index 5aa02a3..d44542d 100644 (file)
@@ -497,14 +497,14 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
     public function listResources($params = array())
     {
         $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category, resource_description, resource_response_type, resource_max_reservations FROM kronolith_resources';
-        $results = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC);
+        $results = $this->_db->getAssoc($query, true, array(), DB_FETCHMODE_ASSOC, false);
         if ($results instanceof PEAR_Error) {
             throw new Horde_Exception($results->getMessage());
         }
 
         $return = array();
-        foreach ($results as $result) {
-            $return[] = new Kronolith_Resource_Single($this->_fromDriver($result));
+        foreach ($results as $key => $result) {
+            $return[$key] = new Kronolith_Resource_Single($this->_fromDriver(array_merge(array('resource_id' => $key), $result)));
         }
 
         return $return;
index f6b9a82..e8754f3 100644 (file)
@@ -135,7 +135,7 @@ function switchDateView(view, date)
   <td width="100%">
     <select id="resourceselect" name="resourceselect">
      <option value="0"><?php echo _("Select resource")?></option>
-    <?php foreach ($allResources as $resource):?>
+    <?php foreach ($allResources as $id => $resource):?>
         <?php printf('<option value="%s">%s</option>', $resource->getId(), $resource->get('name')) ?>
     <?php endforeach;?>
     </select>