Check for an existing WHERE clause
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 6 May 2009 15:43:18 +0000 (11:43 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 6 May 2009 15:43:18 +0000 (11:43 -0400)
content/lib/Tagger.php

index 973b9b2..5d2887e 100644 (file)
@@ -240,6 +240,7 @@ class Content_Tagger
         } elseif (isset($args['userId'])) {
             $args['userId'] = current($this->_userManager->ensureUsers($args['userId']));
             $sql = 'SELECT DISTINCT t.tag_id AS tag_id, tag_name FROM ' . $this->_t('tagged') . ' AS tagged INNER JOIN ' . $this->_t('tags') . ' AS t ON tagged.tag_id = t.tag_id WHERE tagged.user_id = ' . (int)$args['userId'];
+            $haveWhere = true;
         } elseif (isset($args['typeId'])) {
             $args['typeId'] = current($this->_typeManager->ensureTypes($args['typeId']));
             $sql = 'SELECT DISTINCT t.tag_id AS tag_id, tag_name FROM ' . $this->_t('tagged') . ' AS tagged INNER JOIN ' . $this->_t('objects') . ' AS objects ON tagged.object_id = objects.object_id AND objects.type_id = ' . (int)$args['typeId'] . ' INNER JOIN ' . $this->_t('tags') . ' AS t ON tagged.tag_id = t.tag_id';
@@ -255,7 +256,7 @@ class Content_Tagger
 
         if (isset($args['q']) && strlen($args['q'])) {
             // @TODO tossing a where clause in won't work with all query modes
-            $sql .= ' WHERE tag_name LIKE ' . $this->_db->quoteString($args['q'] . '%');
+            $sql .= (!empty($haveWhere) ? ' AND' : ' WHERE') .  ' tag_name LIKE ' . $this->_db->quoteString($args['q'] . '%');
         }
 
         if (isset($args['limit'])) {
@@ -345,6 +346,7 @@ class Content_Tagger
      *   limit      Maximum number of objects to return.
      *   offset     Offset the results. Only useful for paginating, and not recommended.
      *   tagId      Return objects related through one or more tags.
+     *   notTagId   Don't return objects tagged with one or more tags.
      *   typeId     Only return objects with a specific type.
      *   objectId   Return objects with the same tags as $objectId.
      *