I have a content type with a CCK user reference that take 2 users. I wan to get the user profile data for each of those two and create "firstname1 lastname1 & firstname2 lastname2" in the computed field.

I'm a php/mysql n00b so even the basics need to be explained once we get under the hood. It would seem that if I could get the uid from the cck user field that I could use http://11heavens.com/Drupal-coder-lost-in-space/who-is-she user_load to get my custom profile firstname and lastname for each of the two users and then concatenate them into my computed field.

2 problems:

I can't seem to get at the UID's
I couldn't write the query once I got them.

Anyone want to lend a hand? Extensive searches have led me to think that an example like this does not exist, so it would be a great addition to the community.

Comments

clarkburbidge’s picture

clarkburbidge’s picture

Thanks to "seutje" on #drupal-support on 20080114 for finally answering one of my pleas and getting me on the right track. I also had some example help from http://11heavens.com/Drupal-coder-lost-in-space/who-is-she.

I have a content type that is just a data storage for a view that I create. One of the items in the view is a cck user reference field that I allow for 2 users to be selected. I need to generate a collection of these views that are linked to a separate display view that takes 2 arguments. In order to get a link in the view to to the separate view that needs arguments, I could only think of one out one way to do it. Obviously there are many ways but for me it needed to be virtually code free. The way that I devised was to create a separate cck compute field to generate a title from the names and a url from the two arguments.

Getting custom profile data from the UID of a CCK user reference field:

$cck_user_ref_uid_1 = $node->the_name_of_my_cck_user_ref_field[0]['uid'];
$cck_user_ref_uid_2 = $node->the_name_of_my_cck_user_ref_field[1]['uid'];

With the uid I used this to get an array from that users profile:

$array_of_user_data = user_load(array('uid' => $cck_user_ref_uid_1));

The specific fields I wanted were first and last names:

$user_first_name = $array_of_user_data->profile_first;   
$user_last_name = $array_of_user_data->profile_last;

Where profile_first & profile_last are the custom profile fields that I set up previously to hold those values.

Finally I was able to concatenate the name and make it into a href link:

$node_field[0]['value'] = "<a href=\"/some/prefix/".$node->another_cck_field_on_this_node_argument_1[0]['value']."/some/intrafix/".$node->another_cck_field_on_this_node_argument_2[0]['value']."\" >".$user_first_name." ".$user_last_name." & ".$user_first_name2." ".$user_last_name2." </a>";