2

I have a view where I am trying to show all users who have a last access value of never, meaning they have never logged in.

The filter however expects a Date value which is no help to me because I just need to filter by users who have never accessed.

enter image description here

Does anyone know a way around this?

5

You can achieve this using following simple steps:

  1. Add filter criteria User: Last access or User: Last login is equal to 1970-01-01

enter image description here

  1. You could see the users.access = 0 in query

enter image description here

Note: Drupal uses Unix time. The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch.

  • +1 Good answer. Slight wrinkle though: As my site time zone is set at GMT+2 I had to set my access to 1970-01-01 02:00:00. Don't know what will happen if users are allowed to set their own time zone. Probably nothing. – J. Reynolds May 6 '16 at 6:42
  • Okay so this works better: Last access Is less than or equal to, Value 1970-01-02 – J. Reynolds May 6 '16 at 6:52
0

Use hook_views_query_alter

Alter the query before executing the query.

Add a filter to your view on User: Last access and set Is equal to with Value: today

Next create a module and add following:

function MODULE_views_query_alter(&$view, &$query) {
  if ($view->name == 'useraccess') { // add your view name instead
    foreach ($query->where as &$condition_group) {
      foreach ($condition_group['conditions'] as &$condition) {
        if (strpos($condition['field'], 'users.access') === 0) {
          $condition = array(
              'field' => 'users.access',
              'value' => array(null),
              'operator' => '=',
          );
        }
      }
    }
  }
}
0

If you use GMT+x you can use "Regular expression" instead of "is equal to" and use ^0$ as expression.

The SQL result will be:

...
WHERE (( (users.uid NOT IN  ('0')) AND (users.access RLIKE '^0$') ))
...

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.