[SOLVED] LDAP thumbnail Photo Plugin

5 years 6 months ago - 5 years 5 months ago #253608 by cheemak
Hi Guys

I have developed a user field plugin to pull the thumbnailPhoto Attribute from the _user_profile table to be displayed on a users profile.

I took some ideas from the CBcore plugin and the CBmysqlfield plugin by Joe Palmer & softforge.

This is designed to work with the SHMANIC Profile plugin. it looks for the ldap.thumbnailPhoto field and then streams back the image if found, if not should return the no-photo image.

Now this works when used on a user profile, but when using the user list it crashes with
Call to a member function get() on a non-object ...\components\com_comprofiler\plugin\user\plug_cbcore\cb.core.php:260

now I think this is because the line below returns a null value
$value =	$user->get( $field->get( 'name' ) );

But I am stuck as to how to best fix it?

can anyone give me some pointers please?
5 years 6 months ago #253609 by cheemak
here is the plugin code ..
global $_PLUGINS;
$_PLUGINS->loadPluginGroup( 'user', array( (int) 1 ) );
$_PLUGINS->registerUserFieldTypes( array( 'ldapthumbnail' => 'CBfield_ldapthumbnail' ) );

class CBfield_ldapthumbnail extends cbFieldHandler {
		function getField( &$field, &$user, $output, $reason, $list_compare_types ) {
		global $_CB_framework, $ueConfig, $_CB_database;
		$oReturn = null;
		//grab user profile id 
		$user = $user->id;
	// grab ldap.thumbnailPhoto from user_profile table 
	$db = JFactory::getDBO();
	$query = $db->getQuery(true);
		->where($query->quoteName('profile_key') . ' = ' . $query->quote('ldap.thumbnailPhoto'))
		->where($query->quoteName('user_id') . ' = ' . $query->quote((int) $user));
	//check the result of the Query from the DB
		//if there is something in the result stream back the image
			$image=	'<img src="data:image/jpeg;base64,'.$result.'"/>';
		//if no image from Ldap then check CB avatar field
			if ( $cbUser !== null ) {
				$cbUser =& CBuser::getInstance( $user );
				//$thumbnailAvatarHtmlWithLink 	= $cbUser->getField( 'avatar', null, 'html', 'none', 'list' );
				$bigAvatarHtmlWithLink = $cbUser->getField( 'avatar' );
				$image = $bigAvatarHtmlWithLink;			
		return $oReturn;
}//end of ldap Thumbnail field
5 years 6 months ago #253650 by cheemak
for some reason if I add the field as the 3rd column the list renders without problem, if i try it in col1 or 2 it fails spectacularly!
5 years 6 months ago #253672 by krileon
Probably easier to just extend the core image field and override _avatarLivePath to generate the URL path then let the normal image field behavior take place. I've attached and example of how to do this based off your current field code. The problem with your current usage is you're not handling the various output states properly.

Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
Please note I am available Monday - Friday from 8:00 AM EST to 4:00 PM EST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: cheemak
5 years 6 months ago #253687 by cheemak
thanks Kyle

I also realised that with the above code I had used
$user = $user->id;
was causing the issue with the display in list view
5 years 5 months ago #255234 by cheemak
Thanks Kyle

It seems to work fine, I was wondering if there was a way to use this to over-ride the default avatar field? as it stands it looks a bit strange not having the image available in the login module!
Moderators: beatnantkrileon
Time to create page: 0.437 seconds

Facebook Twitter LinkedIn