Hi,

I managed to get a view with some custom sql through the use of hook_views_query_alter(&$view, &$query).

I added some where clauses.

What I want to do now is get the value of a date field (exposed) and bring this into my custom sql.
(DATE_FORMAT(STR_TO_DATE(node_data_field_club.field_club_value2, '%Y-%m-%dT%T'), '%Y-%m-%d') >= '2010-10-06')
I want to change the '2010-10-06' to the exposed input (from a suer) for the date field.

Can you guys help me out?

Thanx!

Comments

dawehner’s picture

You should better use hook_views_pre_execute. There you have exposed_input availible in the $view object and $filter->value.

So you have to go through $view->filter and set the value of the handler to what you want.

timlie’s picture

Thanx, i'll try that and report my findings!

timlie’s picture

I'm struggling with this hook.

In the hook_views_query_alter(&$view, &$query) i could add a where clause (and remove the others) like this:

<?php
unset($query->where);
$view->query->add_where('custom_group', "node_data_field_club.field_bij_club_value2 = node_data_field_club.field_bij_club_value OR (node_data_field_club.field_club_value2 >= '2010-10-10')");
?>

Is this also possible with this hook? Leave the SQL intact and just change the where clauses?

Thanx

Letharion’s picture

Assigned: Unassigned » dawehner

Needs an expert opinion :)

Letharion’s picture

Assigned: dawehner » Unassigned
Status: Active » Fixed

Dereine is a busy person :)
This question is getting rather old, and the OP hasn't responded for quite a while. I'm going to close it due to activity. Please re-open as necessary.

Timlie, is this still relevant to you? If so, please re-open.
Can you achieve what you want if you use both hooks?

timlie’s picture

Is fixed :-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jmolinas’s picture

how do you fix it?

thanks