By leevh on
Hi all, I would really like to filter a node view based on one field in the user's content profile. For instance if the logged in user is specified as part of "program A", then all the related views can be filtered to show only those nodes related also to "program A". Is this possible?
It seems like the only thing I can do with the current user is filter by nodes CREATED by the current user and I can't seem to use relationships to do it either... Any ideas?
thanks a bunch for any ideas.
Comments
if u know how to filter out data before showing a view..
Could u possibly share this with me.. I have posted multiple posts wrt how to searh and display only the result set in the View
I think I might have figured
I think I might have figured out a way. (but any feedback on the idea would be awesome too)
My plan is to create a small custom module that will register a session variable that is the "Program" of the current user. Some good info was found here: http://drupal.org/node/199078 There is probably an easier way but this will keep my custom code out of the core, so a drupal update doesn't override it.
Then I will make "Program" an argument for the view and use the PHP code "default argument" setting. Pull the value from the session variable and it should work! I hope :)
drupalize: I'm not sure exactly what you need, but I'd be happy to explain anything I can if you clarify the question a bit. I'm assuming you know how to use the "Filters" part of views 2 ?
thanks,
Lee
views 2 - is that a module I need to install
sorry, but all i know about views is from a video i saw about it. Nothing specifically mentioned in pro drupal book about this stuff.
I used cck to create a table with all the fields I need to collect user information. I wrote a system to import my existing data to the tables created by cck ( though have not thoroughly tested the results of this). Now I am thinking ahead a bit. I see that Views is nice for formatting, say, a sign up form and I guess also for presenting/displaying a profile page's worth of data.
Then I will need to create a method for users to search out other profiles based upon such criteria, for example, such as age and location. Not sure how to develop this portion, though my first inclination is to write a small form to collect search criteria and then generate the corresponding Sql statement. Once the data is pulled, I would like to list the results in the Views Page style format with the buttons at the links on the page in this style, more or less: < 1 2 3 4 5 6 7 8 9 10 > more..
That's basically it. Can Views ( 2 ? ) do all this, and if so, then how?
Do I have to write a form at all with procedural code as described in pro drupal or is there a ready made solution for this too?
I'm by no means an expert,
I'm by no means an expert, but I'll tell you what I know.
First, I'd say your "sign up form" could just be the create form for the CCK datatype you made. Maybe I made that sound confusing, but after you've used CCK to create a new datatype, you can go to "create content" and choose your new datatype. There's your entry form. If you need to customize the look of it, I would say the module "contemplate" could be used for that.
To list the results you would definitely use views. You shouldn't even have to write any forms to search the data because with views you can set a filter for the data and then "expose" it to the users so that they can change its setting. So for example if you did a simple filter where you filtered by age=30, then you'd only see 30 yr olds in that view. But if you expose that filter, the view includes an input box and the user can type in an age and hit "apply" and it will filter on a new value dynamically.
From what it sounds like, you shouldn't have to do much if any custom coding. CCK and Views2 should be enough. There are a few really good tutorials and videos out there for learning views. If you haven't been here: http://drupal.org/node/248766 , have a look see.
I will check out the video(s), thanks..
Yep, that is what I did. The default create content page is, for now, my sign-up page. I want the search page to come up with basic fields to search on, when 'submitted', I want a new page showing the results
Answer
Viola, the view is now restricted to the current user, as long as that user is specified in a node's userreference.
Now you also have access to all the user's other properties in filters, arguments, and fields. Just be sure to specify the relationship specified above.
A similar problem
I have a situation where one set of users will be creating content and one of the fields in the CCK contains another individual's user name. I would like to create a view that compares the user name in the cck field to that of the current user therefore the user will only be able to view the records that contain their user name in the content.
I tried the relationship option that was suggested by the user above; however the particular field i would like to compare was not available. Any suggestions?
Not sure what you mean.
Not sure what you mean. User:Current shows up in the available filters. As long as the content author sets that user field to a user, then you ought to be able to filter to the current user using that?
User -> current
the user current will only display the records that were created by the user who is currently logged in. What if the record is created by another user and one of the fields has the user name of another user example john creates a content and one of the fields asks "which user will view content" and he enters "doe" therefore if doe logs in he should be able to view the content created by john since doe has been selected as the user to view the record.
something similar to the above example is what i want to do
That's exactly what I am
That's exactly what I am doing in Answer above. What part of that isn't working for you?
Generally what i want to do
Based on the code that es generated from the views module, i want to change
(node_data_field_enum.field_enum_value = 11247)
to
(node_data_field_enum.field_enum_value = ***CURRENT_USER***)
Awesome! Thanks! You just
Awesome! Thanks! You just opened my eyes to the utility of CCK and Views.
Awesome!
I have to admit that I didn't know this after so many years of Drupal! You've been very helpful and I'd like to show my appreciation for it :) Ty!
Trying to filter a view based on a CCK field in user's profile
I'm developing a dating site and I'm trying to filter a view based upon a CCK field in the user who is viewing the site's content profile.
Let's say in my profile I say that I'm looking for women. This is a field in the content profile.
I would like to show all the profile for all of the women. There is also a field in the content profile to state whether you are a man or woman.
How would this be possible?
I have the same challenge. I
I have the same challenge.
I want to list product prices for the country the current user belongs to, which is declared in a content profile field. My content type for product prices also has a country field.
Is there any way to do this?
1. How do i get the country field value of the current logged in user's content profile?
2. How do I filter the view to only show product prices for this country?
Did you figure this out?
I am trying to do the same thing with cck and ....
I am also trying to do the same thing with a field I added to the user profile by using the core profile module.
any help would be great!
thanks
I am trying to do the same.
I am trying to do the same. please share if you found a solution.
Use PHP code
User PHP code in contextual filter. Hope it will solve.
Can I filter a view based on a field of CURRENT user
I am trying to do the same. please share if you found a solution. I have a field in customer section COUNTRY. and i want the list all the content who's authors having same country which having by logged in user country