2

I created a view that displays the number of nodes modified by each user on a specific month. I check the "modification date". The problem is that I also obtain nodes that have never been modified but have been created on that date.

In the node table, "created" and "changed" fields have the same value when the node is created. How can I only retrieve the nodes that have been modified but not created on a specific month ?

Maybe a way of doing this is to check if node.changed <> node.created, but how can I do that in views ?

2

Unfortunately impossible to do it in the current UI.

There are 3 options AFAIK :

A repaired :) attempt to do the alter hook (with help from another answer on this great site) and the add_where_expression function :

function main_mm_views_query_alter(&$view, &$query) {
  if($view->name == 'admin_views_user') {
    $query->add_where_expression(0,'users.access < users.login');
  }
}

This is the view that comes with the module admin views. there are 2 columns - access and login, both are dates and this seems to work :) you will want to do a dpm($query) first, to see your actual query.

7
  • I tried to alter the query to do something like node.created <> node.changed but it did nothing... About handlers, I saw the tutorial you mentionned when I was looking for a solution, but I was expecting not to deal with so much stuff only for my little problem. Well, time to get my hands dirty ! If you have an idea for a query alter, I'd like to hear about it before I try the handler.
    – Grendel
    Apr 11 '14 at 10:30
  • @Grendel I added some code :) try it.
    – mojzis
    Apr 11 '14 at 15:12
  • I tried with : $cond = array( 'field' => 'node.created', 'value' => array('node.changed'), 'operator' => '<' ); but the query generated is wrong, it contains AND (node.created < 'node.changed'). The quotes where added by views.
    – Grendel
    Apr 15 '14 at 13:22
  • thanks for checking and sorry, apparentlyi was wrong :) this could be of help : api.drupal.org/api/views/… i will try to improve my code above :)
    – mojzis
    Apr 15 '14 at 15:21
  • 1
    I successfully used the query alter. Thorough and very helpful answers, thanks a lot ! I'll look into the module too.
    – Grendel
    Apr 15 '14 at 16:34
0

In view's Filter criteria:

  • first filter: Content: Post date Is greater than (or equal to) -1 month
  • second filter: Content: Updated date Is less than -1 month
1
  • Maybe I should have been more precise. I have an exposed filter on the modification date. If I select "June 2014", I only want contents edited at least one time on June 2014. If the content hasn't beed edited since it's creation, it shouldn't be displayed. Your answer doesn't seem to adress that specific problem.
    – Grendel
    Apr 10 '14 at 15:18

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.