3

First of all:

I know that there's a static filter with Global: Fields comparison that would do it. But I need an exposed filter in views to fullfill my needs.

Let's say I have a table with 3 cols: "nid" | "changed" | "another datetime".

Now I want to have an exposed filter as a select list with options "none", "old" and "new". If "old" is selected, show rows where "another datetime" > "changed". If "new" is selected, show rows where "another datetime" < "changed".

I've been looking for a solution for multiple hours.

  • This would need some custom coding, would that be an option for you? Or are you strictly looking for site-building options? – Stefanos Petrakis Sep 10 '16 at 6:31
  • Absolutely yes! – maen Sep 10 '16 at 15:03
  • You could also use a taxonomy field (none, old, new) and when the node is saved or updated, use Rules to compare time fields and set the taxonomy field accordingly. Then expose the field. Easy option if you're already using rules. – Niall Murphy Sep 10 '16 at 23:19
0

Solution 1

Make use of views php to do the compare with the help of https://www.drupal.org/project/views_php

In that case you have to write some code which is executed on each row, in the end it will work but it is very bad in maintaining. You do not have any integrated editor for error code checking etc etc. It is a solution but I do not recommend it.

Solution 2

Make use of the hook views_post_execute with parameter of the view name.

function YOURMODULENAME_views_post_execute(&$view){

For easy maintenance start with a switch

switch ($view->name){

    case "YOURVIEWNAMEA";
    case "YOURVIEWNAMEB";
    case "YOURCASEVIEW";

    foreach ($view->result as $row => $rowinfo) {


      // put here your code to do something with each result.

       // E.G Delete a value in the result of the view making use of unset statement 
        unset ($view->result[$row]);


      }

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.