For my view's php field, I configured it to use my own custom PHP sorting. Here is what's in the "Click sort code" box:

if ( function_exists ( "mymodule_log_view_time_sort" ) )
        mymodule_log_view_time_sort ( $view, $handler, $row1, $row2 );

From the description, it says my custom sorting function should return an integer either < 0, > 0 or = 0 which will determine whether row1 comes before, stay or after row2. But it seems no matter what my code returns, the order remains the same! I verified this with a very simple function that just return either -1, 0 or 1:

function mymodule_log_view_time_sort ( $view, $handler, $row1, $row2 )
{
    return ( -1 );
}

I dug into the Views PHP module code a bit and it appears in the php_click_sort() function, the following line always have $result = 0:

$result = (int)$function($this->view, $this, $this->php_static_variable, $normalized_row1, $normalized_row2);

Either I'm doing something wrong or something is broken...any help is appreciated!

Comments

monaw’s picture

Ok, I've made the following changes and custom sorting appears to be working:

  1. updated Views PHP to 7.x-1.0-alpha1
  2. the function that I call to sort returns 1, 0, or -1 instead of a value > 1 or < -1 (eg 293 or -882)
  3. the sort field actually has to do a return also:
    return ( mymodule_views_log_time_sort ( $handler, $row1, $row2 ) ); instead of just mymodule_views_log_time_sort ( $handler, $row1, $row2 );

Hope this helps someone else.