0

This is a follow-up to How to show nodes where the user is (not) in the reference field with Views?

I have a node with multiple user references and need a node VIEW that hides all nodes where the current user is NOT referenced. So, if the current user is not referenced, the node should not show up. The problem I just can't solve is that the node still shows up when other user are referenced (using exclude, it only excludes the current user from display, but it still displays the nodes for each other user that is referenced). I have unsuccessfully tried views_distinct module and VIEWs own "distinct" query settings.

If the user is referenced, the node should show up (this works from the above mentioned question)

CLARIFICATION:

Basically, it’s for a simple pay-per-view site. I need 1 (or 2, whatever works) VIEWS that shows the videos where the user has purchased access to (where he is referenced) and where the user has not purchased access to (where he is not referenced). After 48 hours the references are removed using rules scheduler.

Ideally in one VIEW, when the user is referenced, the link should be „watch“, where the user is not referenced, it should read „buy“ using VIEWS conditional and rules link. But two separate VIEWS are also ok.

Right now I have a content view (also tried it with a user view unsuccessfully, but this might be a saner approach?!). All of that works well with the notable exception of showing the nodes with multiple user references.

UPDATE:enter image description here

Added a screenshot using the views argument substitutions.

UPDATE 2:

I tried it with regExpressions and views substitutions. The UID of the currently logged in user is passed as !1, but what is the correct regEx syntax to show only the nodes, where this user is not referenced?

This does not work as value of the operator on the useraccess field filter:

^***!1*** 

SOLUTION

Oh boy, this was a ride. Finally figured out a solution. Posting it if someone needs it. Basically, I added the username in the url and do a contains text comparison using views conditional. ID from the logged in user did not work as contains also shows user ID "13" or "14" when the user "1" is logged in. Simply excluding did not work in those cases where other users are referenced as well.

enter image description here

  • You need to elaborate on your View setup and output a bit more. Are you showing a row for each user referenced for a node, hence you have the same node showing up multiple times with a different user? – J. Reynolds Feb 1 '16 at 8:55
0

You have to add a filter under Filter Criteria Section which is, if a 'yourfield-name'is 'is not empty (NOT NULL)' from the select list.

This filter only shows results which have the value for this particular field. Otherwise it will not show you any result for that node.

I hope it will work.

  • Not saying you're wrong but right now, I don't think you can get the current user nid to filter that way. If that doesn't work, I'd add a global:null contextual filter or regular user contextual filter with provide default "logged in user". Then use the module "views arguments substitutes" to feed the users nid into the view filter. Can't test away from laptop so not posting this as an answer. – Niall Murphy Feb 1 '16 at 10:15
  • @ Niall: Thanks for the hint with views arguments substitutions. This indeed looks very much what I need. But as filter I only can use "is not equal" to the global null (logged in user). I guess I would need something like "does not contain" - the reference field is a multiple value (and not a text) field. I tried adding a custom text field to get the "contains" but this also doesn't seem to do the job – user24957 Feb 3 '16 at 8:32
  • hey, when you add a filter criteria that I mentioned above, there will we be a option, is not empty (NOT NULL) option. – Pankaj Sachdeva Feb 3 '16 at 8:45
  • @ Pankaj! Thx for your suggestion. I tried this, but I can't get it to work properly. You mean setting a relationship to the user reference field, then adding the currently logged in user as a contextual filter and then add the filter criteria filtering the "user reference field" with (NOT NULL)? – user24957 Feb 3 '16 at 9:28
0
  • Add your user reference field has a Contextual Filter
  • In your contextual filter settings go to When the filter value is NOT available and check Provide default value and select User ID from logged in user. Then under "More" tab, check "Exclude".

This might give you only those Articles where current logged in user is NOT referenced

  • Thx for the suggestion, xstean. This is how I have implemented the "positive" VIEW, i.e. showing nodes where the user has access to. The issue I am having is that I can't get the neagtive VIEW, i.e. show (only once) the nodes where the user is NOT referenced – user24957 Feb 3 '16 at 7:58
  • Got it, i edited my answer in step 2. In your contextual filter settings go to "More" tab and check "Exclude" – xstean Feb 3 '16 at 18:45
  • Yes, I tried it with this. It does not work when other users are referenced as well. It excludes the current user (and removes one row where the logged in user is referenced), but if there are more user referenced, the node still shows up because for each user referenced one row is displayed. – user24957 Feb 4 '16 at 8:49

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.