this here is a first go at an implementation of views_profile. the ultimate goal is to make all fields defined with the help of profile.module display and searchable by the views module. this here should be regarded as a first attempt inspired by DaveNotik and the user_search discussion on

some notes: 
- only display fields and filters have been defined so far, no default views and arguments. if someone can enlighten me about the benefits of arguments i'd be grateful as i am new to views...
- filters for checkbox profile fields (yes/no) must not be forced single (display as selection) but presented as list. i have not investigated the reason for this but it seems a strange behaviour to me. anybody noticed this with other checkbox fields and views module as well?
- date input has been hacked a little. i much prefer to enter the dates in a selector. also it minimized the possibility of entering dates in the wrong format etc. feedback on this method is of course welcome. (at the moment the year selector starts in 2006 but this can of course e changed).

to install simply put the attached file in the modules directors inside the views directory (you will be asked to replace the current placeholder views_profile.inc file)

feedback and comments are of course welcome

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DaveNotik’s picture

Nice! I will test ASAP.

It'd be great if merlinofchaos, the Views author, and others with knowledge could help out from that side. I think a lot of people would be interested in this.

The next question is how this relates to the profile as CCK type activity (http://drupal.org/node/68360). Thoughts?

--D
http://www.wovenlabs.com

mshaver’s picture

This is really great! I was looking for exactly this type of user display capability. Here are a few issues I noticed and a few questions:

issues
- I can't get all users with profiles to show up. It only lists 3 users, even though I have 10 on a test site? I'm not even sure why the 3 users are showing up vs the others? There isn't anything unique about these 3 users. I've filtered by "Profile: Distinct", but even when this isn't filtered, I only get 3 users.

questions
- is there a way to link to a user profile from one of the profile fields, like how "node:Title" works?
- is it possible to bring in user e-mail addresses?
- will it be possible to sort by profile fields?
- how do you deal with checkbox display?

Thanks and great work so far.

mathmeye’s picture

FileSize
15.86 KB

thanks for the feedback. i shall notice that this is only a first go at this and that my learning curve concerning the views module is quite steep since i am relatively new to drupal...

> I can't get all users with profiles to show up.

views is based on the assumption that nodes are selected. its base table from the database is hence the node table. most likely, the users not showing up have not created any content so far. is that possible? currently views_profile only finds users that have created some content (ie an entry with their uid in the node table)

> [...] link to a user profile from one of the profile fields

yes. 'Node: Author Name' does it, so does 'User: Author Picture'. Both are provided by views_user.inc, so no need to define those fields again.

> is it possible to bring in user e-mail addresses?

yes. the version attached here has this feature. i added this in views_profile.inc for now. in the long run thisfield should be provided by views_user.inc in my opinion. note that as i said before, views is node and not user centric. myself, i would rename 'Node: Author Name' to 'User: Username' but i am curious to hear the original author's opinion.

> will it be possible to sort by profile fields?

yes. the version attached adds sorting for all fields except dates. date sorting needs some work, will do that tomorrow...

> how do you deal with checkbox display?

tick mark if checked, cross mark (or however that is called) otherwise

some issues:
- anynomous user: shows up if no search criteria given (all filters exposed and optional), gets value assigned for checkboxes (due to a if..else caluse) even though value is undefined. hence anonymous breaks checkbox sorting...

appreciating any comments

merlinofchaos’s picture

I'm following this but I have not had time to analyze this.

1) It is likely to be accepted in the end, so without a doubt, *continue working on this*, please! I am ecstatic to see this functionality made available.

2) Patching views_user.inc is perfectly acceptable for fields that are there, and that can be included in this patch or posted as a separate patch depending on which is easier.

3) There is a profile node module I think, and a bio module as well. Either of those might adequately serve as an 'anchor' node for doing user lists. It'd be worth looking at them, because I'd be more than happy to recommend one. All that really matters is that there is an anchor.

4) When I skimmed through the code, I didn't see anything that invalidates the views cache when profile fields are changed. This is likely to be necessary. TO see what I mean, get everything set up the way you want. Then go add a profile field. Then immediately go to views admin; if I'm right, the new field won't show up in the views data until something invalidates the views cache. I think profile has a hook for this but I don't remember for sure.

DaveNotik’s picture

Thanks for following, merlinofchaos.

I too can only gets users who have actually posted a piece of content to show. Is this an inherent limitation w/ the views.module?

I should be able to decide whether to include blocked users or just show active users, and this should be possible via a User: Is Active filter or something like that. Would this be added to views_user.inc?

I'll keep playing.

fago’s picture

perhaps you can use the "usernode" module for this, which I'm currently developing
it automatically creates a node for each user in the system.

it's basically working, however there are still some ways to delete the nodes, which i want to prevent. I'm going to add views support too, so that it's possible to list the users's data (mail, registration time, ..)

mathmeye’s picture

FileSize
16.57 KB

yes, thanks for following, merlinofchaos

> 1) It is likely to be accepted in the end, so without a doubt, *continue working on this*

i will. some difficulties i encountered are mentioned below. grateful for any opinion on that 

> 2) Patching views_user.inc is perfectly acceptable for fields that are there

for now i chose not to touch views_user.inc but only work with views_profile.inc. once views_profile.inc is more feature complete and may be included in the official views module, i'd transfor some fields (user email, user status) into views_user.inc. does that sound reasonable?

> 3) All that really matters is that there is an anchor.

i have not looked at that very much but from i quick glimpse the query object always has the node table as promary table, no? so when linking to node, either uid must be present (so i can do node.uid = user.uid) or i use a third table and link with something else (node.xxx = mirror.xxx and then mirror.uid = user.uid). please correct me if i am wrong here.

> 4) When I skimmed through the code, I didn't see anything that invalidates the views cache when profile fields are changed. This is likely to be necessary.

yes, i (or somebody else ;-) will have to tackle that.

[new] a user status field/sort/filter has been added as requested by davenotik
[fix] checkbox and date display/sorting fixed for empty profile fields

using the 'user active' filter (set to equal 1), blocked users as well as anonymous is filtered from the search results. i guess this is a reasonable method for filtering anonymous.

unfortunately, profile fields have some limitations:

selection:
if a list selection profile field is marked optional a '--' option will show up. the array key of this option is 0. this has several consequences: optional profile selection lists may not have the value 0 as an option (it is overwritten with '--'). the '--' option will show up as 0 in the views display (correct would be an empty field), yet if i filter out all 0s, the the 0 option of required fields would not display... needs some investigation....
 
dates:
date are still the biggest headache and i would like to hear the opinion of some experts. corrently the database entry is a serializes array of month/day/year. this makes it impossible to do date arithmetics in the database (or is there a php equivalent on-the-fly unserialize?). the MySQL STR_TO_DATE is not really an option either (only present in new versions plus format of serialized value differs for one/two digit months/days). what can be done? hacking profile.module to save in a different format or creating an additional table that mirrors the dates. question is: which format should the dates be in? timestamps habe been suggested. but while they work great for node creation dates, dates in profile fields may as well date back before 1970 (date of birth etc). my suggestion would be to use a format in the profile.module that mysql understands. what would be the drawbacks of that?
currently the profile date filter executes a query first to get the date from the database and then does the date arithmetic in php and rewrites the WHERE clause to only inlude uids that match the criteria. this works well for filtering but how would sorting look like?

@fago: i have tested usernode and it works as expected. views now finds users even if they have no content published. some questions and remarks:
- naming: there's a usernodes module already. perhaps usernode vs. usernodes is a little confusing
- access: i only had a quick look. how is access managed? while i am interested in the node tabe entry, the node created must not necessarily be accessible as content.
- views intergration. currently i have user email and user status included in views_profile.inc but as i said, i would transfer those fields to views_user.inc. would this be the integration of user data you pictured? of course, all the other user fields (time created/accessed etc.) could be included as well.

thanks, m

fago’s picture

i know that there is already a module called usernodes, however the name fits very well to my module, so I decided to use 'usernode' nevertheless.

@access: you can set the default optionf of "published" to false for the usernode content type, the usernode module will respect this setting. further I've just comitted an update, which adds a permission "edit own usernode".

@views integration:
yes that's what I'm thinking off. however, currently I'm not using the node author field for the uid entry, (but it's also filled with the same uid), but i store the uid in an extra table.
So I'll add views integration which uses the extra user id - so the fields will show up proper as user fields and not as author information..

merlinofchaos’s picture

Because Views links the user object to the node, having an integration that does NOT use $user->uid == $node->uid will be a weaker integration (from Views' perspective) than another path.

If you're filling the author with that data anyway, I would highly recommend just telling Views that's the linkage. For one, it'll save a join, and for 2, anything which Views links to the user object via node author will work; otherwise, it'll be *very* confusing for people.

fago’s picture

i just replyed here, as I don't want to overtake this issue with my stuff.. ;)
you can comment using your drupal id

DaveNotik’s picture

I'm back at this, trying the latest .inc Mathias provided.

I don't see a filter for user status (active/blocked).

Do we have a proposed solution for the issue where only users who have contributed nodes are shown? This would be nearly there for me if I could just get all users to show. I think this has to do with Earl's "anchor" talk -- he recommended other modules to look at.

Eager to try an updated version.

mathmeye’s picture

dave, the views_profile.inc attached in #7 does have a 'User: Active' filter. after replacing the old version, you might have to go the the modules page ('admin/modules') and simply save the configuration again for views to load the new version.

The proposed solution to show all users is to use fago's usernode module.

Some issues mentioned above (date sorting/force single checkbox/select display) still persist, let me know what else bugs you.

fago’s picture

I've just added some views integration to my usernode module.
(I reused code of the views_user implementation and your patch - thanks)

now you can use the module to provide user listings itself.

Hayakawa’s picture

Version: 6.x-2.x-dev » 4.7.x-1.x-dev
Status: Closed (fixed) » Active

any real world examples?
thanks

DaveNotik’s picture

fago, I can't find your usernode module that's mentioned. Do you mean the usernodes.module (http://drupal.org/node/50850) or your node profile project (http://drupal.org/project/nodeprofile)? Ready to try this right now.

DaveNotik’s picture

Sorry, usernode.module was in your Node Profile package. I installed it, none of the other modules.

First off, it conflicted w/ views_profile.inc in trying to redeclare views_handler_field_email(), so I had to disable views_profile.inc. That means that I now can't use any of the custom profile fields in my view (unless another module of yours handles this?).

Second, while I now can see all users in the list, many of them show over and over, some five times, even though the Node: Distinct filter is set.

Also, I'd like to use a placeholder image if the user doesn't have a user photo for layout consistency, but that's getting way ahead of where I'm at.

I'm, trying to show a nicely-formatted list of users, with select information from their profile. Is this a really complex thing? :( Anyone interested in helping me if I put a modest bounty on it?

--D

fago’s picture

yeah, as I wrote, I reused code from this patch - every information which belongs to the user not to his profile is already offered by the usernode module - and yeah this patch needs to be updated to work with the usernode module again - just remove the information which usernode already provides.

the placeholder image should be possible to achieve by theming a view I think.

this thread is about the views_profile.inc - please use the nodeprofile issue queue for further questions, ideas on my project (or usernode) - you 're welcome.. :)

@multiple nodes: can you provide more details? a view export would be fine.. please open an issue for this..

I'm, trying to show a nicely-formatted list of users, with select information from their profile. Is this a really complex thing? :(
that's what I'm working on and it's already possible, however not by using the core profile.module....

mathmeye’s picture

> [...] I reused code from this patch [...] this patch needs to be updated to work with the usernode module again

@fago: i'm sorry to sound rude but this behaviour is just stupid. you use code from a patch (that might be included in a new version of views.module), break compatibility with the updated views module (and future versions if patch is integrated) and tell the solution is to remove the code from views - which is where you copied it from! please elaborate the reason why you need this functionality in your module and can not use the filters provided by the views_user.inc and views_profile.inc.

moshe weitzman’s picture

please excuse me as i haven't read every post here ... i think profile.module is a bit discredited at this point among drupal shows making real sites. we all use hook_user, just like profile.module. so a views_profile module that only pulls from profile.module tables is of some use, but not that much. i actually prefer the user => node mapping approach. i haven't tried fago's module, but conceptually it works for me.

fago’s picture

hm sry, I don't wanted to tell you how to do your patch. however I've jused the email handler function from your patch, and if one uses usernode module and your patch, you 've to remove the function from one... ;)

So if your patch gets committed I remove the handler from usernode and there is no problem. for now, the handler isn't in views and I need to provide it myself so that the usernode views integration works.

first I thought the incompatiblity (I never tried your patch!) came through duplicate field definitions (email, status), but I think that's not the case. it should be just the handler..

fago’s picture

I've changed the function names of the usernode handlers, so there shouldn't be any conflicts any more.

DaveNotik’s picture

Hi. I had actually removed the duplicate declaration and it worked fine. The latest Node Profile stuff from fago fixes the issue, anyways.

I actually successfully have a view that pulls some stuff from *both* usernode.module (Picture, Created time) and views_profile.inc (Custom fields like Country, Interests).

I'd love to provide a link, but I'm having an issue where the view isn't spitting out any content for anonymous users. merlinofchaos, is this a Views-wide bug? I know you're out of town.

Next, I want to be able to really change the look of this view, and it's currently not as flexible as I'd love for it to be.

Also, the usernode that usernames now link to doesn't include the custom profile fields and other information I would get on the default profile pages. fago?

Getting close. Can anyone help w/ the last mile? I think this would benefit alot of people.

fago’s picture

@usernode: you may use the Usernode: Name field, which links to the normal drupal user page as default.

DaveNotik’s picture

Thanks fago. Using Usernode: Name does indeed list the usernames, but they're not linked.

fago’s picture

if you want a link you have to set the handler for this field to "themed userlink" in the views edit page.

DaveNotik’s picture

That'd be cool, fago, but no handler options are available for the Usernode: Name field as far as I can tell.

I'm using v 1.19 of the usernode.module.

Thanks for the help.

--D

fago’s picture

clear your cache and try again. (views caches a lot)

John McV’s picture

Hello,
Above states:
> I can't get all users with profiles to show up.

> views is based on the assumption that nodes are selected. its base table from the database is hence the node table. most likely, the users not showing up have not created any content so far. is that possible? currently views_profile only finds users that have created some content (ie an entry with their uid in the node table)

I'm new at this and I need to create tables from a load of user profiles. Unfortunately most of the members won't be creating content immediatly. Is there a way around this? Is there a patch or module that creates a page for each profile as if it were content from the user? Thanks,
John

John McV’s picture

Hello again,
Yahoo! I just found the answer to my request (#28) above: http://drupal.org/node/68360
John

merlinofchaos’s picture

I was hoping there'd have been some more work on this.

I've gone ahead and committed it so that future fixes can be simple patches, and more people will likely be involved because this could theoretically be a very big deal.

One very important fix that needs to be done: When profile fields are changed or updated via the profile admin page, views' cache needs to be invalidated. It should be relatively trivial. Anyone want to roll a patch?

merlinofchaos’s picture

Status: Active » Fixed

Please roll said patch as a separate issue (but reference this one!)

moshe weitzman’s picture

I don't think there is a hook when profile fields are added/removed so the best way to notice this event and clear views cache is to add submit handlers to the profile add and delete forms.

drewish’s picture

Status: Fixed » Active

it doesn't look like this was commited to HEAD not the 4.7 branch... which would be fine if this bug hadn't been marked as 4.7...
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/views/modules...
maybe the tags are just screwy

merlinofchaos’s picture

Version: 4.7.x-1.x-dev » 6.x-2.x-dev

I haven't moved the tag up; I didn't actually notice the version on the queue.

I plan to move the tag up fairly soon, I just wanted to make sure all the changes I put in were stable before catching 4.7 up.

merlinofchaos’s picture

Status: Active » Fixed

This has been live for a little bit now

Anonymous’s picture

Status: Fixed » Closed (fixed)
drupalxykon’s picture

how does this work? I dont see any extra fields (I was expecting to see profile fields) under arguments or filters when I add a view

Rosamunda’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

erm... I´m asking the same thing here that our vrao fellow.
I don´t see profile fields... maybe I´m doing something wrong? Or didn´t do some step?
(I´ve got installed the last version of views for 4.7)

Thanks!!

Rosamunda

jenlampton’s picture

Title: views_profile implementation » views_profile implementation - not working at all

I don't see any change at all to my drupal site either... also, the instructions are very unclear. I uploaded the file to modules/views/views_profile.inc but I don't understand how adding a file would do anything if there is no call to include it? Was this file really meant for v 4.7.x? It's also not mentioned anywhere in the original post. Any help apprecited!

Jen

merlinofchaos’s picture

Title: views_profile implementation - not working at all » views_profile implementation
Status: Postponed (maintainer needs more info) » Closed (fixed)

Oh good grief, people.

views_profile.inc has been with Views since October. It's in every officially released version. Why you'd take a closed issue and re-open it with some cryptic message is beyond me, but it's a bad way to get help.

If you want help, open a support issue. Clearly state what it is you're asking.

DO NOT take over closed issues.

DO NOT change the title of an issue to something inane.

These things piss me off a lot.

jenlampton’s picture

ok, I'm sorry. I'm not trying to open a closed issue, but when I did a search on the drupal site for views_profile I only got 2 results, this page, and one referring to this page. It looked to me like the issue wasn't resolved, so - I asked again. How do I know where to look for actual resolutions?

(FYI) What it is I'm asking: How do I get profile Fields to appear as an option in the views "fields" drop-down?

Jen
---
Oh good grief, people. views_profile.inc has been with Views since October. It's in every officially released version. Why you'd take a closed issue and re-open it with some cryptic message is beyond me, but it's a bad way to get help. If you want help, open a support issue. Clearly state what it is you're asking. DO NOT take over closed issues. DO NOT change the title of an issue to something inane. These things piss me off a lot.

drewish’s picture

jenlampton, you must have skipped over the part where merlin said you should open up a support request.

jenlampton’s picture

He said to do that if there was a problem... and he also said that this had already been resolved, hence, no real problem. So - I was just elaborating for his benefit (or maybe just my own, since I don't think he really cares anyway)

merlinofchaos’s picture

I have opened a support request to address this: http://drupal.org/node/121164

merlinofchaos’s picture

And it's a good thing I create that support issue before I saw your crack about not really caring, because after that I certainly would not have bothered.

I spend hours of my life every month supporting this free product. It makes me happy when people use it and like it, but it also makes me unhappy when people fail to follow the requested procedure. It particularly makes me unhappy when people come here and insult me.

I'm sorry that you're having trouble with it. I don't pretend that it is perfect or bug free or everything it needs to be. That said, if you want help, there are proper avenues for that. Use them. I do help people when I have the time.

But do not come here and insult me.

I have absolutely positively no obligation to help you. I do it because I am proud of the software I create. No one pays me for this task, I do it in my spare time. So if I get impatient when procedure isn't followed, it's because my spare time is limited, and it upsets me that I have to spend my spare time getting people to simply do the right thing.

I am now finished with this issue.

jenlampton’s picture

no insult intended :-( sorry.

mathmeye’s picture

i was the one opening this thread, so a few comments from my side as well even though this issue is officially closed - i'm terribly sorry to learn that seemingly in the long run this has caused more confusion that being of help to anyone.

merlinofchaos has been so kind to help with issues along the way and has even accepted it for inclusion in the views module. if there are any flaws, it is me to blame. not including a proper way of detecting updated and added profile fields is a failure from my side. it would be terrific if anyone, especially the people who commented on this, would be willing to work on this.

merlinofchaos, your work is much appreciated and i'm especially sorry to learn that my unskilled programming efforts have caused you anger. your views module is an absolute beauty and i can only imagine how much time and effort you put into it. i know that positive feedback and praise is seldom, i should have said thank you a long time ago and not only now but i hope you still accept.

finally for views profile:
- please follow the instructions of merlinofchaos and post any future issues as support issues
- read the answer at http://drupal.org/node/121164 if views fails to show your newly created profile fields
- i will try to answer the questions concerning the views profile implementation myself as good and fast as i can

thanks, m.

Status: Active » Closed (fixed)