Jump to content

Show user information to everyone


godmok
 Share

Recommended Posts

Hi everyone,
 
this is my first post here, please be gentle to me ;)

I am using ProcessWire for a the second time, running it for a project site that has a little trouble on its way. It is my fist time to work so intense with the user profiles in PW.
 
I have extended the user template with additional information (avatar, postal address,etc.) that the user can fill in.
 
The user have the roles of one of these:

  • member
  • member-x
  • member-y

The information from the profile has to be shown on various pages, even on the home page. So, if I get the profiles like this:
 

$profiles = $users->find( "roles^=member-, limit=4, sort=random" ); // get only "...-x" and "...-y" member

 
The output should show some profile information, but it does not. Only logged in as superuser the profiles are shown.
 
Now my question: how can I output information from the user to a guest/visitor/everyone?
 
For now I have created for the test site a /profile/ page and duplicated the user profile into this, so the information can be found by a simple $pages->find(). This is working for now, but makes the maintenance troublesome.
 
On another part of the site there is a little confusion situation. Here the background: Every user can create a calendar (event) post.
The structure is like this for the calendar page:
 
/calendar/
| - /calendar-1/ (by user1)
| - /calendar-2/ (by user2)
| - ... (by userX)
 
I can get the posts in /calendar/ by:

$calendarPosts = $page->children("sort=date_start");
foreach ( $calendarPosts as $calendarPost ) {
    //...
    $member = $users->get( $calendarPost->created_users_id ); // get the user information
    //...
    //HTML output with user information
    echo $member->lastname;
    //...
}

Here the user information is reachable for the guest. For now this is quite "dirty" code (or maybe clean?) but it is working. Could this be a bug or is it because of "get()" and not "find()"?
 
So I can get a user profile information about another page but not directly from the profile itself.
 
 
Is there a solution to get the profile information from the user without creating a additional profile page or is the additional profile page a better solution?
 
 
PS: Originally my client wanted this to be on Joomla, but that would bring a lot of other trouble ;)
That is why I like PW a lot! So simple, clean, mighty. Love it!

Link to comment
Share on other sites

Hi godmok,

Welcome here :)

You don't find any users because the user template is access protected and the guest user does not have "view" permission. You can either change this or skip the access check in your selector by adding "check_access=0".

And your second question: Yes there's a difference between $pages->find and $pages->get. The latter assumes that you're very specific about getting a single page and therefore also returns pages that are unpublished/hidden/no-access. Hope I don't forget anything here :)

Cheers

  • Like 1
Link to comment
Share on other sites

Hi Wanze,

thanks for the welcome and your feedback!

I don't like the idea to change the permission in the system template. As you suggested I tried that and still no result.

But I found the problem within the selector. You put me on the "right" track with "check_access=0", and should read the cheatsheet more carefully...

I simplified the selector like this:

$profilesTemp = $users->find("roles=member-gold");
echo $profilesTemp->first()->name;

Without check_access it is still working (system template "user" -> guest has no view rights!) for visitor (strange?) and shows the name from the user. I can get output on every field from the user profile. This is good, but then it gets problematic again.

$profilesTemp = $users->find("roles^=member-");
echo $profilesTemp->first()->firstname;

The difference is "roles^=member-". I want to have all users that have the role starting with "member-". This one fails.

The problem seems to be in the selector: If the role is not selected with the "=" operator it fails (even for logged in members). I tried every operator for the string, but no luck.

Link to comment
Share on other sites

I put up your code and set some outputs to it with no result in the end.

$customUserRoles = $roles->find( "name^=member-" );
echo $customUserRoles->first()->name; // output: member-gold (OK)
echo count($customUserRoles); // output: 2 (OK)

$profileTemp = $users->find( "roles=$customUserRoles" );
echo count($profileTemp); // output: 2 (OK)
echo $profilesTemp->first()->name; // output: "" (nothing, not OK)

It seems as a guest I can get some information but not filtered with roles (even with "check_access=0" or "include=all").
Another test was also successful, as long as I do not use "roles":

$profilesTemp = $users->find( "name^=a" ); // find user beginning with "a" in the name
echo count($profilesTemp); // output: 1 (OK)
echo $profilesTemp->first()->name; // output: "adam-..." (OK)

$profilesTemp = $users->find( "user_firstname^=a" ); // find user beginning with "a" in the field user_firstname
echo count($profilesTemp); // output: 1 (OK)
echo $profilesTemp->first()->user_firstname; // output: "Adam" (OK)

 
Edit:
 
Thank you LostKobrakai, that's it! It worked out like it should and is displaying on the page.

Will do that with the other pages after some food input!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...