[SOLVED] LDAP thumbnail Photo Plugin

9 years 4 months ago - 9 years 3 months ago #253608 by cheemak
[SOLVED] LDAP thumbnail Photo Plugin was created 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?

Please Log in to join the conversation.

9 years 4 months ago #253609 by cheemak
Replied by cheemak on topic LDAP thumbnail Photo Plugin
here is the plugin code ..
global $_PLUGINS;
$_PLUGINS->loadPluginGroup( 'user', array( (int) 1 ) );
$_PLUGINS->registerUserFieldTypes( array( 'ldapthumbnail' => 'CBfield_ldapthumbnail' ) );
$_PLUGINS->registerUserFieldParams();

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);
	$query->select($db->quoteName('profile_value'))	
		->from($db->quoteName('#__user_profiles'))
		->where($query->quoteName('profile_key') . ' = ' . $query->quote('ldap.thumbnailPhoto'))
		->where($query->quoteName('user_id') . ' = ' . $query->quote((int) $user));
	$db->setQuery($query);
	$result=$db->loadResult();
	
	//check the result of the Query from the DB
	if($result!==null){
		//if there is something in the result stream back the image
			$image=	'<img src="data:image/jpeg;base64,'.$result.'"/>';
		}else{
		//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;			
			}
}
		$oReturn=$image;	
		return $oReturn;
	}
}//end of ldap Thumbnail field

Please Log in to join the conversation.

9 years 4 months ago #253650 by cheemak
Replied by cheemak on topic LDAP thumbnail Photo Plugin
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!

Please Log in to join the conversation.

9 years 4 months ago #253672 by krileon
Replied by krileon on topic LDAP thumbnail Photo Plugin
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 - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
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 CST to 4:00 PM CST. 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.
Attachments:
The following user(s) said Thank You: cheemak

Please Log in to join the conversation.

9 years 4 months ago #253687 by cheemak
Replied by cheemak on topic LDAP thumbnail Photo Plugin
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

Please Log in to join the conversation.

9 years 3 months ago #255234 by cheemak
Replied by cheemak on topic [SOLVED] LDAP thumbnail Photo Plugin
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!

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.219 seconds

Facebook Twitter LinkedIn