<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<p>Hi. My module requires additional sql to return the correct content
on taxonomy queries. I've used hook_db_rewrite_sql() to construct the
sql I need, and it returns what I need. The problem is that my hook is
AND'd
with the taxonomy_access_db_rewrite_sql hook, and therefore voided.</p>
<p>Example:<br>
</p>
<p>In function taxonomy_term_page(): <br>
$result = db_query(db_rewrite_sql('<b>SELECT t.tid, t.name FROM
{term_data} t WHERE t.tid IN (%s)</b>', 't', 'tid'), implode(',',
$terms['tids']));<br>
</p>
<p>Once ran through the TAC hook and my hook, this query becomes:<br>
</p>
<div class="codeblock"><code>SELECT t.tid, t.name FROM term_data t
WHERE (t.tid IN ('1')) AND (t.tid IN ('1','3')) AND ( t.tid IN (3))</code></div>
<br>
TAC hook_db_rewrite_sql returns: (t.tid IN ('1'))<br>
My hook_db_rewrite_sql is returning: (t.tid IN ('1','3')) (correct)<br>
<br>
What I need is for my clause to be returned as <b>OR</b> rather than <b>AND</b>:<br>
<div class="codeblock"><code><br>
SELECT t.tid, t.name FROM term_data t WHERE (t.tid IN ('1')) <b>OR</b>
(t.tid IN ('1','3')) AND ( t.tid IN (3))</code></div>
<br>
That would do the trick. Question is, how to do it? I've included my
rewrite of the TAC db_rewrite_sql so you can see what I'm working with,
but I'm hoping you might have some way for me to accomplish this short
of hacking TAC. Thanks!<br>
<br>
-ron<br>
<br>
<?php<br>
/**<br>
* Implementation of hook_db_rewrite_sql()<br>
*<br>
* Used to include OGR roles in taxonomy/term<br>
*<br>
*/<br>
function og_user_roles_db_rewrite_sql($query, $table, $field) {<br>
if (!user_access('administer taxonomy') && ($field =='vid' ||
$field =='tid')) {<br>
global $user;<br>
$op = (arg(0) == 'node' && (arg(1) == 'add' || arg(2) ==
'edit')) ? 'create' : 'list';<br>
<br>
// let's cache<br>
static $taxonomy_access_sql_clause;<br>
$clause = array();<br>
<br>
if (!isset($taxonomy_access_sql_clause)) {<br>
$taxonomy_access_sql_clause = array();<br>
}<br>
if (!isset($taxonomy_access_sql_clause[$op][$field])) {<br>
if (isset($user) && is_array($user->roles)) {<br>
$rids = array_keys($user->roles);<br>
} <br>
else {<br>
$rids[] = 1;<br>
}<br>
<br>
if (isset($user)) {<br>
$query = db_query('SELECT ogr_id FROM {og_users_roles} where
uid = %d', $user->uid);<br>
while($row = db_fetch_array($query)){<br>
$ogr[] = $row['ogr_id'];<br>
}<br>
}<br>
else {<br>
$ogr[] = 0;<br>
} <br>
<br>
$sql = db_query("SELECT t.tid, d.vid, BIT_OR(t.grant_$op) AS
grant_$op FROM {term_access} t INNER JOIN {term_data} d ON t.tid =
d.tid LEFT OUTER JOIN {og_users_roles} ogr ON ogr.rid = t.rid WHERE
(t.rid IN ('".implode("','",$rids)."') OR ogr.uid = ".$user->uid.")
AND grant_$op = 1 GROUP BY t.tid, d.vid");<br>
while ($result = db_fetch_object($sql)) {<br>
$tids[]= $result->tid;<br>
$vids[$result->vid]= $result->vid;<br>
}<br>
$clause[$op]['tid'] = isset($tids) ? implode("','",$tids) : '';<br>
$clause[$op]['vid']= isset($vids) ? implode("','",$vids) : '';<br>
$taxonomy_access_sql_clause = $clause;<br>
}<br>
else {<br>
$clause[$op][$field] = $taxonomy_access_sql_clause[$op][$field];<br>
}<br>
$return['where'] = ($clause[$op][$field]) ? "$table.$field IN
('".$clause[$op][$field]."')" : "$table.$field IS NULL";<br>
return $return;<br>
}<br>
else {<br>
return array();<br>
}<br>
}<br>
?><br>
<pre class="moz-signature" cols="72">--
Ron Parker
Software Creations <a class="moz-txt-link-freetext" href="http://www.scbbs.com">http://www.scbbs.com</a>
Self-Administration Web Site <a class="moz-txt-link-freetext" href="http://saw.scbbs.com">http://saw.scbbs.com</a>
SDSS Subscription Mgmt Service <a class="moz-txt-link-freetext" href="http://sdss.scbbs.com">http://sdss.scbbs.com</a>
Central Ave Dance Ensemble <a class="moz-txt-link-freetext" href="http://www.centralavedance.com">http://www.centralavedance.com</a>
R & B Salsa <a class="moz-txt-link-freetext" href="http://www.randbsalsa.com">http://www.randbsalsa.com</a>
</pre>
</body>
</html>