[development] hook_views_query_alter

Ashraf Amayreh mistknight at gmail.com
Fri Oct 29 23:18:13 UTC 2010


Hello all,

I've searched the net all over for the particular case I have but couldn't
find an answer. I have a view with an argument, based on this argument, I
would like to either pass it through, or join to two more tables and add a
where clause to my query that is pretty unrelated to the argument type. For
example, let's say the argument is a tid and I want to add a where clause to
the files table if this tid was equal to 5, otherwise, I want it to function
normally. For this I looked into the hook_views_query_alter hook

The problems I faced in order:

1. The cck file field that contains the fid was not in the fields list, so
the table wasn't even in the joins, I resolved this by adding the cck file
field to the fields list although I have no use for it. But this at least
added the table to the view object in this hook (I didn't really want to add
a field in vain just to get its table to show up in the view->query object).
2. After doing that, I needed to do a join from the table in #1 to the files
table, again, the files table was not inside the view->query and this is
where I got stuck.
3. Assuming #2 works, I will finally add a where clause to the files table.
4. Let's say I did all this successfully, I would need to remove the tid
that was passed in the argument so that it would not be rendered inside the
query (i.e. where tid = 5).

Is there any guidelines on how to fully handle the view, view->query
objects? All I could find were hacks to add sort by, add simple wheres to
tables that were already in the views object, and to create aliases for
tables that are, again, already in the view object. None of them with the
complexity I need.

I've hesitated on weather this should be in the views issue queue or here,
but I think many agree views is no longer an optional module. If I do get
this resolved I'll be more than happy to post it on our site or to create a
views issue with the details.


-- 
Ashraf Amayreh
CEO | O-Minds
Cell. 962 78 8099997
Tel. 962 6 5655150
Fax. 962 6 5675150
Skype: aamayreh

www.o-minds.com
web development | web design
user experience | branding design

Connect with us on Twitter
http://twitter.com/ominds

Connect with us on LinkedIn
http://www.linkedin.com/in/aamayreh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101030/95009099/attachment-0001.html 


More information about the development mailing list