1

I have a view with 2 exposed filter.. I only want to change the result of my view when filters are used, ie if they have any value and press the button to run the filters.

I try to used the hook_views_pre_render, but doesn't work...

function node_db_views_pre_render(&$view) {
   if($view->name=="demo" && $view->current_display == 'page_1' &&  $view->exposed_input['date_filter'] != NULL) {
       $get_date = $view->exposed_input['date_filter'];
       $min = $get_date['min']['value'];
       $max = $get_date['max']['value'];

         $query_power = "SELECT h.id, h.name, count(c.room_id) as busy 
                         FROM table_1 c JOIN table_2 h ON c.id = h.id
                         WHERE '%s' < c.in_date OR '%s' > c.in_date
                         AND '%s' < c.out_date OR '%s' > c.out_date";

         $result = db_query($query_power, $min, $min, $max, $max);

       $items = get_rows($result); // this is a function gets the data from the sentence and makes a array.

       $view->result = $items;
   }
}

Exist other hook that can help me?..Thanks :D

1

you should use hook_views_query_alter, because hook_views_pre_render is called after the query is done, so you cannot influence your database request anymore.

The views documentation has been added to the Drupal api docs recently, so for more info look at: http://api.drupal.org/api/views/docs%21views.api.php/group/views_hooks/7

or

http://views.doc.logrus.com/

  • So, first i use hook_views_query_alter where i get the value of my filters, then execute the query ... then use hook_views_pre_render for show the result.. ¿this is the way? Or i only use the first hook and autommatically my view show the result that i require? – Dvex Mar 14 '12 at 22:52
  • You should only use one hook (hook_views_query_alter), where you can check for filters values (eg. $view->exposed_input['YOUR_FILTER_IDENTIFIER']), and then you can add conditions to your query object – 30equals Mar 15 '12 at 11:49
  • @30equals.. do you have any example of this hook?. because, when i override the query... i have a fatal-error .-. – Dvex Mar 15 '12 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.