Get an Admin / FEU user's Full Name

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Get an Admin / FEU user's Full Name

Post by hexdj »

I needed CGBlog to display a user's full name instead of their username, so I created this tag, called GetFullName
it does require the username as a parameter though.

Code: Select all

global $gCms;
$db =& $gCms->GetDb();
$user_name = $params['username'];

$query = "SELECT first_name, last_name FROM ".cms_db_prefix()."users WHERE username=?";
$row = $db->GetRow($query, array($user_name));
if($row)
{
   $result = $row['first_name'] . " " . $row['last_name'];
}
else
{
   $result = "Username: $user_name doesn't exist";
}

return $result;
Next, you can use it in your CGBlog templates like this:

Code: Select all

<div class="CGBlogPostAuthor">{GetFullName username=$entry->author}</div>
You can probably use it as well in modules like News

Hope somebody else finds this useful, thanks to Stikki for the help in making it work :-)
Last edited by hexdj on Wed Mar 03, 2010 11:32 pm, edited 1 time in total.
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Get an Admin user's Full Name

Post by hexdj »

OK this UDT has been revamped, because in my site I needed certain FEU users to post articles to CGBlog, using the FEsubmit option, therefore the above UDT wouldn't get their actual name, as they're stored in different places in the Database.
Once again many thanks to Stikki for all the Help.

So now two parameters are accepted in the call:
- username (this is the user name that you want to get the full name from)
- feufield (this is the field that you want to fetch from FEU properties)

In my case I created a Property in FEU which holds a user's full name and I called it 'name'
so my call in my CGBlog template looks like this:
{GetFullName username=$entry->author feufield='name'}

UDT:

Code: Select all

// This UDT returns the "Full Name" of an Admin User, requires the username as a param
global $gCms;
$db =& $gCms->GetDb();

$user_name = isset($params['username']) ? $params['username'] : "";

$feu_field = isset($params['feufield']) ? $params['feufield'] : "";

$query = "SELECT first_name, last_name FROM ".cms_db_prefix()."users WHERE username=?";
$row = $db->GetRow($query, array($user_name));
if($row)
{
   $result = $row['first_name'] . " " . $row['last_name'];
}
else
{

 if($gCms->modules['FrontEndUsers']['object'] && !empty($feu_field)) {

   $query = "SELECT id FROM ".cms_db_prefix()."module_feusers_users WHERE username=?";
   $feid = $db->GetOne($query, array($user_name));

   if($feid) 
   {
   $query = "SELECT data FROM ".cms_db_prefix()."module_feusers_properties WHERE userid=? AND title=?";
   $result = $db->GetOne($query, array($feid,$feu_field));
   
   }
   
 }
}

if(!$result) 
{
   $result = "Username: $user_name doesn't exist or feufield is not set";
}

return $result;
Last edited by hexdj on Sun Mar 07, 2010 12:05 am, edited 1 time in total.
User avatar
zounars
Forum Members
Forum Members
Posts: 41
Joined: Tue Jun 20, 2006 11:38 am
Location: Italy

Re: Get an Admin / FEU user's Full Name

Post by zounars »

Hi all,

Can someone please tell how I can get this UDT work in CMSMS 1.10.3 and CGBlog 1.9.8; Blog entries have to be submitted using Feusubmit

Using hexdj UDT:
When an admin post a blog entry, his name is correctly show but when the blog entry is posted using FEUsubmit, I get "Username: name@website.com doesn't exist or feufield is not set"

Any help please...
uniqu3

Re: Get an Admin / FEU user's Full Name

Post by uniqu3 »

Most possibly you have to change

Code: Select all

global $gCms
to

Code: Select all

$gCms = cmsms();
and

Code: Select all

$gCms->modules['FrontEndUsers']['object']
to

Code: Select all

cms_utils::get_module('FrontEndUsers')
Post Reply

Return to “Tips and Tricks”