} 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';
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'])) {
* 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.
*