? .DS_Store
? cache_indexes_01.patch
? ctools_contexts_03.patch
? entity_translations_00.patch
? entity_translations_01.patch
? entity_translations_02.patch
? grid_display_00.patch
? layer_filter_api_00.patch
? layer_filter_api_01.patch
? layer_filters_04.patch
Index: includes/index.classes.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/includes/Attic/index.classes.inc,v
retrieving revision 1.1.2.41
diff -u -p -r1.1.2.41 index.classes.inc
--- includes/index.classes.inc	27 Feb 2010 19:41:10 -0000	1.1.2.41
+++ includes/index.classes.inc	7 Mar 2010 18:07:38 -0000
@@ -20,6 +20,9 @@ class index {
   public $description = '';
   public $layers = array();
   public $contexts = array();
+  // Global conditions that apply to all layers in addition to layer-specific
+  // filters.
+  public $conditions = array();
 
   /**
    * Construct the object with basic properties or properties that have been
@@ -55,6 +58,7 @@ class index {
     $this->layers = array();
     foreach ($layers as $layer) {
       $layer->index = $this;
+      $layer->conditions['global'] = $this->conditions;
       $parent_lineage = substr($layer->lineage, 0, strrpos($layer->lineage, '_'));
       if (strlen($parent_lineage) == 0) {
         $this->layers[] = $layer;
@@ -139,6 +143,15 @@ class indexLayer {
   public $hide_childless_entities = FALSE;
   public $layers = array();
   public $entities = array();
+  public $conditions = array(
+    // Global conditions as defined in $this->index->conditions.
+    'global' => array(),
+    // Filters for this specific entity type.
+    'filters' => array(),
+    // Conditions to find children of parent entities based on entity
+    // properties. This array should only have ONE item.
+    'hierarchy' => array('name' => array('name')),
+  );
 
   /**
    * Fill all properties.
@@ -162,25 +175,26 @@ class indexLayer {
    * @param $depth_current integer
    *   The current layer depth.
    */
-  function getEntities(indexContext $context, $depth_max, $depth_current = 1, $key = NULL, array $values = array()) {
+  function getEntities(indexContext $context, $depth_max, $depth_current = 1) {
     $entity_types_info = index_entity_type_info();
+    $key = NULL;
 
     // If there are entities for a parent layer, compute the conditions for
     // which to get this layer's entities. A parent layer only has entities if
     // $key passed on to this function is NULL.
     if ($this->parent && count($this->parent->entities[$context->name])) {
       $key = $entity_types_info[$this->entity_type]['#relations'][$this->parent->entity_type];
-      $values = array();
+      $this->conditions['properties'][$key] = array();
       foreach ($this->parent->entities[$context->name] as $entity) {
         if ($entity->data->$key) {
-          $values[] = $entity->data->$key;
+          $this->conditions['properties'][$key][] = $entity->data->$key;
         }
       }
     }
 
     // We need to get the entity count only.
     if ($key && $this->entity_count_only) {
-      $counts = $entity_types_info[$this->entity_type]['#entity_count_callback']->call($key, $values, $depth_max);
+      $counts = $entity_types_info[$this->entity_type]['#entity_count_callback']->call($this, $depth_max);
       foreach ($this->parent->entities[$context->name] as $parent_entity) {
         if (is_null($parent_entity->child_count)) {
           $parent_entity->child_count = 0;
@@ -192,7 +206,7 @@ class indexLayer {
     }
     // We need to get entities.
     else {
-      $this->entities[$context->name] = $entity_types_info[$this->entity_type]['#entity_get_callback']->call($key, $values, $depth_max);
+      $this->entities[$context->name] = $entity_types_info[$this->entity_type]['#entity_get_callback']->call($this, $depth_max);
       // Assign parents and children.
       if ($this->parent) {
         foreach ($this->parent->entities[$context->name] as $parent_entity) {
Index: includes/index.entity.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/includes/Attic/index.entity.inc,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 index.entity.inc
--- includes/index.entity.inc	16 Jan 2010 21:43:49 -0000	1.1.2.9
+++ includes/index.entity.inc	7 Mar 2010 18:07:39 -0000
@@ -7,18 +7,50 @@
  */
 
 /**
- * Construct an SQL WHERE clause based on selection criteria.
+ * Construct a single SQL WHERE clause condition.
+ *
+ * @param $column string
+ *   An SQL table column.
+ * @param $values array
+ *   An array containing values the column should match.
+ *
+ * @return string
+ *   An SQL WHERE clause condition that can be directly injected into a query.
  */
-function index_entity_query_filter($key, $values, $table = NULL) {
-  if ($key) {
-    $column = $table ? "$table.$key" : $key;
-    $types = array(
-      'integer' => 'int',
-      'string' => 'text',
-    );
-    return " WHERE $column IN (" . db_placeholders($values, $types[gettype($values[0])]) . ')';
+function index_entity_query_condition($column, array $values, $table = NULL) {
+  $types = array(
+    'integer' => 'int',
+    'string' => 'text',
+  );
+
+  $column = $table ? "$table.$column" : $column;
+  $condition = "$column IN (" . db_placeholders($values, $types[gettype($values[0])]) . ')';
+  // Substitute placeholders here, so the calling function doesn't have to pass
+  // on condition values to the query.
+  _db_query_callback($values, TRUE);
+
+  return preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $condition);
+}
+
+/**
+ * Construct an SQL WHERE clause based on layer conditions.
+ *
+ * @param $conditions array
+ *   Keys are SQL table columns and values are arrays containing values the
+ *   columns should match.
+ * @param $table string
+ *   An optional table name to prefix column names with.
+ *
+ * @return string
+ *   An SQL WHERE clause that can be directly injected into a query.
+ */
+function index_entity_query_conditions(array $conditions, $table = NULL) {
+  $query_parts = array();
+  foreach ($conditions as $column => $values) {
+    $query_parts[] = index_entity_query_condition($column, $values, $table);
   }
-  return NULL;
+
+  return ' WHERE ' . implode(' ', $query_parts);
 }
 
 /**
@@ -26,8 +58,9 @@ function index_entity_query_filter($key,
  *
  * @return array
  */
-function index_entity_get($entity_type, $table, $key, array $values) {
-  $result = db_query("SELECT * FROM {$table}" . index_entity_query_filter($key, $values), $values);
+function index_entity_get(indexLayer $layer, $table = NULL) {
+  $table = $table ? $table : $layer->entity_type;
+  $result = db_query("SELECT * FROM {$table}" . index_entity_query_conditions($layer->conditions['hierarchy']));
   $entities = array();
   while ($data = db_fetch_object($result)) {
     $entities[] = new indexEntity($entity_type, $data);
@@ -41,9 +74,11 @@ function index_entity_get($entity_type, 
  *
  * @return integer
  */
-function index_entity_count($table, $key, array $values) {
-  $where = $key ? index_entity_query_filter($key, $values) . " GROUP BY $key" : NULL;
-  $result = db_query("SELECT COUNT(*) as count, $key as value FROM {$table} $where", $values);
+function index_entity_count(indexLayer $layer, $table = NULL) {
+  $table = $table ? $table : $layer->entity_type;
+  $column = array_shift(array_keys($layer->conditions['hierarchy']));
+  $where = $column ? index_entity_query_conditions($layer->conditions['hierarchy']) . " GROUP BY $column" : NULL;
+  $result = db_query("SELECT COUNT(*) as count, $column as value FROM {$table} $where");
   $counts = array();
   while ($count_data = db_fetch_array($result)) {
     $counts[$count_data['value']] = $count_data['count'];
@@ -58,8 +93,8 @@ function index_entity_count($table, $key
  * @return array
  *   Node types from {node_type}.
  */
-function index_entity_get_node_type($key, array $values, $depth_max) {
-  return index_entity_get('node_type', 'node_type', $key, $values);
+function index_entity_get_node_type(indexLayer $layer, $depth_max) {
+  return index_entity_get($layer);
 }
 
 /**
@@ -67,8 +102,8 @@ function index_entity_get_node_type($key
  *
  * @return integer
  */
-function index_entity_count_node_type($key, array $values) {
-  return index_entity_count('node_type', $key, $values);
+function index_entity_count_node_type(indexLayer $layer) {
+  return index_entity_count($layer);
 }
 
 /**
@@ -77,7 +112,8 @@ function index_entity_count_node_type($k
  * @return array
  *   Nodes from {node} and {node_revision}.
  */
-function index_entity_get_node($key, array $values, $depth_max) {
+function index_entity_get_node(indexLayer $layer, $depth_max) {
+  // TODO: implement new parameters.
   $entities = array();
 
   // Get nodes by TID.
@@ -103,7 +139,8 @@ function index_entity_get_node($key, arr
  *
  * @return integer
  */
-function index_entity_count_node($key, array $values) {
+function index_entity_count_node(indexLayer $layer) {
+  // TODO: implement new parameters.
   // Count nodes by TID.
   if ($key == 'tid') {
     $counts = array();
@@ -125,9 +162,9 @@ function index_entity_count_node($key, a
  * @return array
  *   Comments from {comments}.
  */
-function index_entity_get_comment($key, array $values, $depth_max) {
+function index_entity_get_comment(indexLayer $layer, $depth_max) {
   // TODO: Comments are hierarchical as well.
-  return index_entity_get('comment', 'comments', $key, $values);
+  return index_entity_get($layer, 'comments');
 }
 
 /**
@@ -135,8 +172,8 @@ function index_entity_get_comment($key, 
  *
  * @return integer
  */
-function index_entity_count_comments($key, array $values) {
-  return index_entity_count('comments', $key, $values);
+function index_entity_count_comments(indexLayer $layer) {
+  return index_entity_count($layer, 'comments');
 }
 
 /**
@@ -145,9 +182,9 @@ function index_entity_count_comments($ke
  * @return array
  *   Users from {users}.
  */
-function index_entity_get_user($key, array $values, $depth_max) {
-  $where = ($filter = index_entity_query_filter($key, $values)) ? "$filter AND uid <> 0" : ' WHERE uid <> 0';
-  $result = db_query("SELECT * FROM {users}" . $where, $values);
+function index_entity_get_user(indexLayer $layer, $depth_max) {
+  $where = ($where = index_entity_query_conditions($layer->conditions['hierarchy'])) ? "$where AND uid <> 0" : ' WHERE uid <> 0';
+  $result = db_query("SELECT * FROM {users}" . $where);
   $entities = array();
   while ($data = db_fetch_object($result)) {
     $entities[] = new indexEntity('user', $data);
@@ -161,8 +198,8 @@ function index_entity_get_user($key, arr
  *
  * @return integer
  */
-function index_entity_count_user($key, array $values) {
-  return index_entity_count('users', $key, $values);
+function index_entity_count_user(indexLayer $layer) {
+  return index_entity_count($layer, 'users');
 }
 
 /**
@@ -171,8 +208,8 @@ function index_entity_count_user($key, a
  * @return array
  *   User roles from {users_roles}. 
  */
-function index_entity_get_user_role($key, array $values, $depth_max) {
-  $result = db_query("SELECT * FROM {role} r LEFT JOIN {users_roles} ur ON ur.rid = r.rid" . index_entity_query_filter($key, $values));
+function index_entity_get_user_role(indexLayer $layer, $depth_max) {
+  $result = db_query("SELECT * FROM {role} r LEFT JOIN {users_roles} ur ON ur.rid = r.rid" . index_entity_query_conditions($layer->conditions['hierarchy']));
   $entities = array();
   while ($user_role = db_fetch_object($result)) {
     $entities[] = new indexEntity('user_role', $user_role);
@@ -186,7 +223,8 @@ function index_entity_get_user_role($key
  *
  * @return integer
  */
-function index_entity_count_user_role($key, array $values) {
+function index_entity_count_user_role(indexLayer $layer) {
+  // TODO: implement new parameters.
   $result = db_query("SELECT COUNT(*) FROM {role} r LEFT JOIN {users_roles} ur ON ur.rid = r.rid" . index_entity_query_filter($key, $values));
 
   return db_result($result);
@@ -198,8 +236,8 @@ function index_entity_count_user_role($k
  * @return array
  *   Vocabularies from {vocabulary}.
  */
-function index_entity_get_taxonomy_vocabulary($key, array $values, $depth_max) {
-  return index_entity_get('taxonomy_vocabulary', 'vocabulary', $key, $values);
+function index_entity_get_taxonomy_vocabulary(indexLayer $layer, $depth_max) {
+  return index_entity_get($layer, 'vocabulary');
 }
 
 /**
@@ -207,8 +245,8 @@ function index_entity_get_taxonomy_vocab
  *
  * @return integer
  */
-function index_entity_count_taxonomy_vocabulary($key, array $values, $depth_max) {
-  return index_entity_count('vocabulary', $key, $values);
+function index_entity_count_taxonomy_vocabulary(indexLayer $layer, $depth_max) {
+  return index_entity_count($layer, 'vocabulary');
 }
 
 /**
@@ -217,7 +255,8 @@ function index_entity_count_taxonomy_voc
  * @return array
  *   Terms from {term_data}.
  */
-function index_entity_get_taxonomy_term($key, array $values, $depth_max) {
+function index_entity_get_taxonomy_term(indexLayer $layer, $depth_max) {
+  // TODO: implement new parameters.
   $entities = array();
   $where = index_entity_query_filter($key, $values);
 
@@ -302,6 +341,6 @@ function index_entity_get_taxonomy_term_
  *
  * @return integer
  */
-function index_entity_count_taxonomy_term($key, array $values, $depth_max) {
-  return index_entity_count('term_data', $key, $values);
+function index_entity_count_taxonomy_term(indexLayer $layer, $depth_max) {
+  return index_entity_count($layer, 'term_data');
 }
\ No newline at end of file
