Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Display User Properties from GT Community

Quote Reply
Display User Properties from GT Community

I was wondering if someone can help me out with the problem that I am facing.

I am wanting to display user properties on link.html & detailed.html page along with the link proprties.

I have tried below sub but was not successful. (big thanks to Andy, who tried to help me out) :


sub {
my $user = $_[0];
$DB2 = new GT::SQL '/path/to/community/defs/';
$DB2->set_connect ({
driver => "mysql",
host => "localhost",
database => $dbname,
login => $user,
password => $pass
}) || die $GT::SQL::error;
$DB2->prefix("comm_");
my $get_hash = $DB2->table('Users')->select( { Username => $user } )->fetchrow_hashref || return $GT::SQL::error;
return { username => $get_hash->{comm_Username} };
}




What I am trying to do is, many users have more than one link, so even though the link information is different for every listing, company/link owner information like company name, address, email.. etc remains the same and it would be wonderful to have the ability to display all the user fields on the link.html and detailed page.

Thanks for the help.

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Did you not get my other PM?

This post may help;

http://www.gossamer-threads.com/...i?post=245765#245765

You should be able to pass in the user ID...i.e;

<%Plugins::Auth_Community::get_profile($LinkOwner)%>

Hope that works :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display User Properties from GT Community In reply to
Hi Andy,

I did tried using <%Plugins::Auth_Community::get_profile($LinkOwner)%> , but it does not seem to work, also I assume what it does is, it will show the logged user their info/name, but won't be able to display user properties on the link & detailed page.

:(

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Try this (your original global seemed quite mixed up between Links Users table, comm_users table, Username, comm_username, etc - so this is my best guess as to what you want - even this is just reading in a username and outputting the same username Wink):

sub {
my $user = $_[0];
use lib('/path/to/private/lib');
my $db = GT::SQL->new('/path/to/community/defs')->table('comm_users');
my $get_hash = $db->select( { comm_username => $user } )->fetchrow_hashref || return $GT::SQL::error;
return { username => $get_hash->{comm_username} };
}
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
Hey Laura, thanks for helping :)

This is what I added in detailed.html

sub {
my $user = $_[0];
use lib('/path/to/gtcommunity/private-folder/lib');
my $db = GT::SQL->new('/path/to/gtcommunity/private-folder/defs')->table('prof_city');
my $get_hash = $db->select( { prof_city => $prof_city } )->fetchrow_hashref || return $GT::SQL::error;
return { prof_city => $get_hash->{prof_city} };
}

With above sub what I am trying to do is, display the City from the user properties. Also, I am not logged into the web site, as I plan to hard code the field in static view of the web site, so these fields will be visible to everyone.


Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
OK - I assume that the field you are passing into the global is LinkOwner, you want to look this up in your community users table and return the city value for that user?

my $db = GT::SQL->new('/path/to/gtcommunity/private-folder/defs')->table('prof_city');

This says that the table you are looking in is called 'prof_city' in your Community database - I think this should probably be 'comm_users' - unless you really do have a table called prof_city?

my $get_hash = $db->select( { prof_city => $prof_city } )->fetchrow_hashref || return $GT::SQL::error;

This is definitely wrong. I'm pretty certain that you want to look up the row in the comm_users table that has comm_username=LinkOwner so you need to change this to comm_username=>$user
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
Thanks for the quick reply :)

Okay, first let me admit that I don't know perl or mysql and hence when I receive any global or see anything, I normally try out different things to see which one works, and generally I make many mistakes, and one of them is made just above.

Here is the case senario:
  1. I haven't updated any tables or anything in either Links SQL or GT Community
  2. I registered a user at GT Community, and username is user3
  3. user3 has Oklahoma City under its city property.
  4. Now I modifed the link from Links SQL admin interface and make user3 the link owner for it.
  5. In link.html and detailed.html I have instered below code :

    sub {
    my $user = $_[0];
    use lib('/path/to/gtcommunity/private-folder/lib');
    my $db = GT::SQL->new('/path/to/gtcommunity/private-folder/defs')->table('comm_users');
    my $get_hash = $db->select( { comm_username=>$user } )->fetchrow_hashref || return $GT::SQL::error;
    return { prof_city => $get_hash->{prof_city} };
    }

However this is still not working. :

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Well I can't see anything obvious wrong with the global so some quick checks - you have replaced '/path/to' with the actual path? And you have <%globalname($LinkOwner)%> in the template?
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Also - just checking - you do realise that this global will not return anything? You actually need to use the tag <%prof_city%> somewhere after calling the global to see the city.
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
Hum... not sure what I could be doing wrong...

Here is the global
sub {
my $user = $_[0];
use lib('/path/to/gtcommunity/private-folder/lib');
my $db = GT::SQL->new('/path/to/gtcommunity/private-folder/defs')->table('comm_users');
my $get_hash = $db->select( { comm_username=>$user } )->fetchrow_hashref || return $GT::SQL::error;
return { prof_city => $get_hash->{prof_city} };
}

I have setup the name for it like z_city, so I am calling it via <%z_city($LinkOwner)%> in link.html and detailed.html page

I am using prof_city in the global, because that is how the city propertiy appears in the GT Community.

About the /path/to/ , yes I have updated it to the actual path on the web site.

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Do you get an error message?
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
In Reply To:
Also - just checking - you do realise that this global will not return anything? You actually need to use the tag <%prof_city%> somewhere after calling the global to see the city.


Okay, I will have to admit that I found one of the most unusal thing...
  1. When I put <%prof_city%> in link.html and detailed.html it worked like a charm :)
  2. Now being so silly that I am, I actually deleted the global, but left the tags that way on both link.html and detailed.html just to see what happens.
  3. on link.html pages, I am still able to see the City Name (<%prof_city%>) & Country(<%prof_country%>) while even though I am using the same tags on detailed.html page, it didn't worked for me.
  4. Now I created the global one more time, to see what happens, on link.html things didn't changed, while on detailed.html I was able to see the City name, But not the country name. (while before deleting the global, I was able to see the country name too)

The code in link.html
--------------------------------
<%z_city%>
<%prof_city%>
<%prof_country%>
--------------------------------

and it displayes City Name and Country Name.



Code in detailed.html

------------------------------
<%z_city%>
<%prof_city%>
<%z_city($prof_country)%>
<%prof_country%>

Above code generates Unknown Tag: 'prof_city' Unknown Tag: 'prof_country'

--------------------------------
<%z_city($LinkOwner)%>
<%prof_city%>

Above code displayes :: Dallas (City Name)
--------------
<%z_city%>
<%prof_city%>
<%prof_country%>

Above Code Displays :: Dallas Unknown Tag: 'prof_country'
--------------------------------

Now from the codes in detailed.html page, if I were to only delete <%z_city($LinkOwner)%>, then I am getting only unknown tag errors.

==============================

So how is that, it is able to generate country code on the link.html without any global, but not working properly on detailed.html ?



I am able to see that things are working, but I am totally lost with the magic trick Links SQL is playing with me... what do you think?

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Now I created another global with below info and named it z_test1

sub {
my $user = $_[0];
use lib('/home/rdqtckjz/public_html/gtcommunity/private/lib');
my $db = GT::SQL->new('/home/rdqtckjz/public_html/gtcommunity/private/defs')->table('comm_users');
my $get_hash = $db->select( { comm_username=>$user } )->fetchrow_hashref || return $GT::SQL::error;
return { prof_country => $get_hash->{prof_country} };
}

and I am using below code on the detailed page, and it does display country name :)
<%z_test1($LinkOwner)%>
<%prof_country%>

So I assume, I will have to create a new global for evey user property (darn, there will be atleast 20 or more), but doing this way works.

Also, I was wondering, would it be possible to create just one global and make it work for all the user property?

P.S.. thanks a lot, in last 30 minutes I got more work done in fixing this problem, then in last 8 days :) thank you again.

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
In Reply To:
  1. When I put <%prof_city%> in link.html and detailed.html it worked like a charm :)
[/quote]

Great Cool.

As to the other results - I'm pretty certain that you shouldn't get any results for <%prof_something%> in the link template without any globals - I wonder whether you have another global somewhere on the page which is pulling in the profile fields (such as <%Plugins::Auth_Community::get_profile($LinkOwner)%>)? You could have a look at <%GT::Template::dump%> to see what fields are available.

The global that you are using should only be used with LinkOwner - or other username tag - you can't pass in the field that you want returned.

Last edited by:

afinlr: Mar 26, 2004, 10:58 AM
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Just add the fields that you want returned to the list:

sub {
my $user = $_[0];
use lib('/home/rdqtckjz/public_html/gtcommunity/private/lib');
my $db = GT::SQL->new('/home/rdqtckjz/public_html/gtcommunity/private/defs')->table('comm_users');
my $get_hash = $db->select( { comm_username=>$user } )->fetchrow_hashref || return $GT::SQL::error;
return { prof_country => $get_hash->{prof_country}, prof_city=> $get_hash->{prof_city} };
}
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
Quote:
Just add the fields that you want returned to the list:

cool.. I am going to add all the user properties, so I can display them anywhere on link.html and detailed.html page for all the users (both logged in and not logged in) :)

===========

About global working for link.html, well it seems like it just working like a magic .. cuz I don't see anywhere the global being called.. below is the code for link.html

----------...... I think I found something.. I will post back in a moment.

Vishal
-------------------------------------------------------
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
Tongue .... ha ha.... Tongue

Hey Laura, I have a news for you :)

We don't need this or any global to make this thing work. Also, without this or any global, we can display any user property on link.html detailed.html page I am not sure if Alex and GT team is aware of this feature either, as in his post Alex said that a global might be required to pull user properties on links sql pages...

It is very simple, just put below code in the page

<%Plugins::Auth_Community::get_profile($LinkOwner)%>
and then whatever property you want, type in
<%prof_city%>
<%prof_country%>
......
......
etc...

and it seems to be working with all the user properties, and that was the reason why it was working on link.html without any global. Also, I just tested it on my site by deleting the globals, and still I am able to display user properties on link.html and detailed.html page

Well, I would like to thank you for taking time and helping me out, as if it was not for you, then I would have never learned about this way. Also, it is very good to know that the global you created, also works :)

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
If you want to return all the fields, I think you can just use (saves a bit of time typing all the fields in!)

return $db->select( { comm_username=>$user } )->fetchrow_hashref || return $GT::SQL::error;
Quote Reply
Re: [NeedScripts.Com] Display User Properties from GT Community In reply to
Crazy So Andy's post at the top of this thread was correct! I assumed that it must only return the logged in user's fields as you said you'd tried it - should have had a closer look myself. At least we'll know for the future.
Quote Reply
Re: [afinlr] Display User Properties from GT Community In reply to
In Reply To:
Crazy So Andy's post at the top of this thread was correct! I assumed that it must only return the logged in user's fields as you said you'd tried it - should have had a closer look myself. At least we'll know for the future.


Yup.. Andy was right all the way.. but I assume along with him, the main reason why you or I were looking for a different alternative was because, in his post Alex wrote "If I understand you, you want to display information stored in Links SQL on a page displayed by Community. You would need a global to fetch this information." however I believe that maybe even Alex (even though he is all big and bad Tongue - I think he is actually a good guy) was not aware of this hidden feature/tag.

Vishal

Vishal
-------------------------------------------------------

Last edited by:

NeedScripts.Com: Mar 26, 2004, 11:29 AM