1

I have a content type with a number of fields, one of which is state (pending/active/complete). Users can also be assigned to a piece of content. Eg Frank is linked to content titled "Blah" with state "active".

I want to create a view that shows users who ARE NOT linked to any content with the state field "active".

So far, I figured I can show a list of users and then using relationships, I pull up and reference the content.

It is easy enough to show users linked to content that has the state field "active", but for the life of me, I cannot figure out how to show users who ARE NOT linked to content with state "active".

Any ideas?

2
  • This can be accomplished using views. Try the video series dev.nodeone.se/en/taming-the-beast-learn-views-with-nodeone to get a handle on how to use it :)
    – Ashlar
    Apr 15, 2012 at 2:54
  • Checked out the Beast video series and I still can't see how to do it. The issue is that I am trying to dynamically exclude or include data, based on other data included or excluded. Eg If X has Y, then don't show any other X's, even if they show Z'ds.
    – Craig
    Apr 16, 2012 at 10:43

5 Answers 5

1

Thank you all.

In the end I added a new field to the user as Jimajamma suggested, which counts the number of state (active) nodes that user has. I used Rules to add and subtract from the number to keep it current. Views then filters, only reporting on users with 0 state (active) nodes.

0

From what I'm able to understand, you want to be able to see users that are not linked to that piece of content type. Thus, could you possibly just create a view that uses a contextual filter for users NOT of that content type?

1
  • Unfortunately this won't work. It is the same content type, with a field marked state, so all users will be using that content type, but not all will have that state as active.
    – Craig
    Apr 15, 2012 at 3:18
0

I'd say go the other way round:

Create a view of Users and add a relation to the nodes.

Then, in your filter, set your state field to Pending or Inactive. You can select multiple values IIRC.

4
  • Nice try - getting closer :) Unfortunately I can't go "NULL", as the field often has other values in there. I need the filter to exclude any user who has "active" on ANY node. ie I want it to look at more than 1 node and if any of them have "Active" as a state, then it should exclude ALL of the nodes from the result (or exclude the user of all of those nodes from the result)
    – Craig
    Apr 16, 2012 at 10:31
  • I hate to say this but I think this might be a case of a poor architectural decision on your behalf. This is straightforwards and shouldn't be so hard! The only other way I can think of is using a hook_views_query_alter().
    – Alex Weber
    Apr 16, 2012 at 13:10
  • I'll take that on the chin, but I'm pretty sure the design is OK :) I simply have a single field named state that can contain the values Pending, Active and Complete. So it will never return null in a view as, right from node creation it is given the value "Pending". It looks like I will need to add another field specificially to track "Active" (Y/N), but to me, this seems less architectually sound. I'll also look at the various workflow modules to see if they can be used.
    – Craig
    Apr 16, 2012 at 20:16
  • Hum I guess I misunderstood your field's purpose, I was under the impression it allowed other kinds of values (hence the remark about the architecture). Updated my answer!
    – Alex Weber
    Apr 16, 2012 at 23:03
0

One way I can see this being done easily is to have another field linked somehow to your user that is incremented when the user is assigned or otherwise has active content. In D6, this could be as simple as having an integer field in a content profile. Using permissions you could set it up so the user can't change or edit it and then whenever a user is assigned a piece of active content, this gets incremented. When that content is no longer active, or assigned to another user, it gets decremented. This logic could easily be put inside nodeapi(). Then you could use a view to look for users with this field being zero. You could also look for overworked users, too :)

4
  • I came to the same conclusion - Another field would do the trick - It does seem the clumsy option though :)
    – Craig
    Apr 17, 2012 at 10:53
  • The issue here is that I don't see that there is a direct way with the joins that views uses to do what you want. You could put a multiple value field in the user side of the house that links to the content and then all would be good in the world but given you are doing it in the opposite way, I don't see how to do it directly. You could create a view that returns all the users with content assigned to them, shove those uids in an array and then create another array of all your users uids and then use array_diff() to find out who isn't in there...all pretty clumsy.
    – Jimajamma
    Apr 17, 2012 at 16:24
  • another way would be to create an array of all your uids, and then use views to grab the uids of content owners and then cycle through them, unsetting the corresponding user in the first array, and then at the end, you'd have an array of users without content.
    – Jimajamma
    Apr 17, 2012 at 17:12
  • Thank you all. In the end I added a new field to the user as Jimajamma suggested, which counts the number of state (active) nodes that user has. I used Rules to add and subtract from the number to keep it current. Views then filters, only reporting on users with 0 state (active) nodes.
    – Craig
    Apr 17, 2012 at 19:55
0

If I can understand correctly, you just want a view of users not connected to "active" content right?

Here's what I would do:

  1. Create a User view
  2. Add an entity reference relationship for your user reference field (I'm assuming this is how you are linking users)
  3. Add two filters (normal, not contextual) for field_state; first one is "is not one of: active" which will display users linked to pending/complete content and second one is "is empty" which will display users who are not connected to anything
  4. Create a new filter group (click the arrow next to "add" and select "rearrange") and change the operator to OR
  5. Put those two filters you created in this OR group, and you should be good to go.

This worked for me on a new test bed I made just now, so it SHOULD work for you too. But I am not sure how complicated your site currently is so your mileage may vary. Let me know if it works.

2
  • It does work as you indicate, but what still doesn't produce the result I want:
    – Craig
    Apr 17, 2012 at 11:58
  • Sorry Craig, I guess I haven't fully grasped what you need. And come to think of it, I think I basically duplicated Alex's suggestion, whoops! May I ask where this list of users (is that right?) will be displayed? Is it a page? Block on a piece of content?
    – filmoreha
    Apr 17, 2012 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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