Closed (fixed)
Project:
Advanced Forum
Version:
6.x-1.0-alpha2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Jan 2008 at 07:18 UTC
Updated:
17 Sep 2008 at 15:22 UTC
I have a few profile fields that I manually added by making database calls within forum-thread.tpl.php. For example, I get the member's location by adding this:
$sql = "SELECT value FROM profile_values WHERE (uid = %d) AND (fid = 5)";
$result = db_query($sql,$node->uid);
$location = db_fetch_object($result);
I then display it in the node/comments by adding this:
<?php if ($location->value) { print check_plain($location->value); } ?>
Does this seem fine, or is there perhaps an easier/safer way to add any custom fields added to the profile, via the /admin/user/profile page?
Brad
Comments
Comment #1
michelleI can't speak to the query since I haven't dealt with the core profile module, but I suggest not putting it in the .tpl file. It's better to put that sort of thing in _phptemplate_variables and create a variable to use in your .tpl file.
Michelle
Comment #2
michelleNothing further since my answer... Marking fixed.
Michelle
Comment #3
jaydub commentedI believe that user_stats module holds promise for helping to provide user stats/profile/etc information. The module is clean and simple and should be able to be dropped right into advanced_forum.
http://drupal.org/project/user_stats
Comment #4
michelleI've already looked at that module and it duplicates a lot of what I already do.
Michelle
Comment #5
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #6
gareth_w commentedIs it possible to post an example of this, placed into the _phptemplate_variables function? Is this the same one that you add to the theme to get it to call advanced forum in the first place?
Many thanks,
Gareth
Comment #7
michelleWhen replying to closed issues, please set them active again. If I didn't get these by email, I never would have seen this.
Yes, that's the same function where the advforum call is. That's the function that prepares variables for the templates. In that example, you'd set $vars['location'] = $location.
Michelle
Comment #8
gareth_w commentedAgain, thanks for the quick response (you must be sick of me by now) and sorry I didn't set this to active - I kind of figured the system did it automatically without giving it a thought.
However, I can't quite get this to work, and am sure something is adrift.
in template.php
Is set. I'm not sure that I'm setting the %d or $node-> uid corretly though - are these sent through by default, or globally available to the system? I have checked, and 6 is the correct fid, and is populated for at least 1 user.
In forum-thread.tpl.php I have:
Which was cannibalised from another variable. Something is working somehow as "Location:" is printed for all users (even those who have not entered a location), but nothing follows it; which leads me to believe the SQL is not returning what I think it is.
Do you have any further suggestions as to what could be coming adrift here?
Many thanks,
Gareth
Comment #9
gareth_w commentedOK, I have a fix ~ish, but I can't explain it. Derived from knowing far too much perl and having a lucky guess.
When doing the above SQL query directly from the template, "Object" is produced. Mapping that Object to value gives the location. Note that this only works when doing the mapping in the forum-thread.tpl.php file; in the function _phptemplate_variables section of the template I cannot get it to return anything, suggesting that the uid is not being set properly.
My fix is
I'd still like to know the proper syntax to do this in the proper function, but for now it's working, and I'll take working over elegant and proper any day.
Gareth
Comment #10
michelleSorry, I hadn't looked that close at his SQL. You need to change $node->uid to $vars['node']->uid. You get $node in the .tpl when $vars['node'] is processed.
Michelle
Comment #11
gareth_w commentedThe code in my template.php file now reads
Have I got this right?
The template uses $variables instead of $vars (is this confusing things?), but this still returns nothing :(
Thanks again,
Gareth
Comment #12
michelleWell, I don't know that much about using SQL in Drupal so I'm just assuming his SQL works. Unless the OP comes back, I'm not sure there's anythign else I can do. This isn't an advforum issue...
Michelle
Comment #13
michelleI guess the OP never came back. At any rate, you can access the user's profile fields from the .tpl file through the variable I added a while back.
Michelle
Comment #14
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #15
BradM commentedHi,
I've been out of the loop for a bit, but I just installed the latest alpha today. Michelle, you mentioned that "you can access the user's profile fields from the .tpl file through the variable I added a while back." I'm guessing you mean you can do this by adding $profile->fieldname within the advf-forum-user.tpl.php file?
Well I tried that but so far no success. Using the core profile module, I added a few fields, named "profile_location" and "profile_title" -- and I call them using this code in advf-forum-user.tpl.php:
However, nothing is returned. Any ideas?
Also, on a related note, in advanced_forum.module, around line 187, it states:
However, I was getting buddy, email, etc. display in anonymous posts. So I had to change this to $accountid == 0.
Brad
Comment #16
BradM commentedforgot to switch version info
Comment #17
fe@drupal.org commented$profile - Profile object from core profile. Usage: $profile->fieldname
this doesn't work for me neither
Comment #18
valdemar commentedThat doesn't work for me either, but I figured it out by doing an array dump of the $profile array. You can access it like this:
print $profile["Personal Information"]["profile_name"]["value"];(Personal Information is the "profile group" of the field)
The documentation should be updated to say this.
Comment #19
fe commentedonce again, doesn't work for me
Comment #20
ozon commentedFirst, sorry for my bad english ;).
The Code of Advanced Forum is very buggy.
I have the same Problem with profile fields.
But i have a Workaround.
Place the Code in "themes/advforum/advf-forum-user.tpl.php
Then you can access the user Profile Fields with
It works for me.
I hope it helps.
Comment #21
BradM commentedHi ozon, that fix worked for me! Thanks for the help. :)
Comment #22
michelleComment #23
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #24
pilot7 commentedI have had this same problem, even through trying all of the following:
1) Enabled the Core profile package, added a new field called profile_name, and completed this value
2) Edited advf-forum-user.tpl.php and added Name:
print $profile->profile_name;At this point, all that displayed was Name:, the actual name did not display
3) I verified that the profile_name field had 'Public field, content shown on profile page but not used on member list pages.' and also tried it with, 'Public field, content shown on profile page and on member list pages.' In both cases I got the same result
4) Added the following code per a prior post to advf-forum-user.tpl.php file. Still did not display the actual name
Name:
print $acc->profile_name;I am sure I am missing something, but I cannot figure out what. Can anyone provide a pointer?
- Steve
Comment #25
michelleYou don't need to load the user object as it's already loaded. Just use the existing $profile variable. It works but it wasn't documented correctly in the .tpl. I've updated it with the proper information.
Michelle
Comment #26
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #27
dazhdbog commentedstill not working for me on alpha2.. dumps of both $profile and $account are giving NULL.
ozon's solution is returning profile fields of the _currently logged in user_ : (
Comment #28
michelleI've confirmed that this works in the current 6.x.
Michelle
Comment #29
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.