Membership plugin - author specific photo

Wow...pretty neat! So I tested out the helper function for both the Accounts Table and the New Blog Image Table I created. I was a bit confused at the fact that when I ran the test for each one, there was a createdBy.avatar for both. I originally set up the Account Table to have the upload name of "avatar" and the Blog Image Table to have the upload name of "upload_image". But the "createdBy.upload_image" never came up. So I changed that to "avatar" as well. Here are the results...

For this code:
<?php foreach ($accountsRecords as $record) :?>
<?php showme($record); ?>
<?php die(); ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>

i got this:
[createdBy.avatar] => Array ( )

for this code:
<?php foreach ($blog_avatarsRecords as $record) :?>
<?php showme($record); ?>
<?php die(); ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php endforeach ?>


i got a huge string of information. But most notably it linked to my image (yay). So I changed the code to read as follows:
<?php foreach ($blog_avatarsRecord['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php if (!$blog_avatarsRecord['createdBy.avatar']): ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>


but it shows up for EVERY posting. Not solely the one that I created. I wanted the "fpo" image to populate if the user has not uploaded their own image yet...

I can't tell you all how much I appreciate you everyone hanging in there with me for this and trying to help out. I feel like we are getting close(ish) and just wanted to cheer you on a bit longer :)
Thank you so much!

Re: [Gabums85] Membership plugin - author specific photo

By (Deleted User) - January 30, 2012

Hi Gabums85,

You're very close withg your code. Try this instead:

<?php foreach ($blog_avatarsRecord['createdBy.avatar'] as $upload): ?>
<?php if ( @$upload ) : ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif; ?>
<?php endforeach ?>


Basically, you want to check for the existence of the avatr while in the for loop, as the output of the img url happens in the loop.

Hope that helps,

Tom

Re: [Gabums85] Membership plugin - author specific photo

By gkornbluth - January 30, 2012 - edited: January 30, 2012

Hi Gab,

In the code that you're using, shouldn't the logic be something like:
<?php foreach ($blog_avatarsRecords as $record) :?>
<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>
<?php endforeach ?>


Also, instead of urlPath, why not use thumbUrlPath and set the thumbnail sizes to 75 x 75 in the editor?

Using:
<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo
$upload['thumbHeight'] ?>
you'll get to display a small thumbnail image to begin with and not get distorted images if the aspect ratio of the original is not exactly square.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Gabums85] Membership plugin - author specific photo

By Jason - January 31, 2012

Hi,

You're really close. If the avatar is supposed to be an image associated with the person who created the record, you won't need this extra avatar table. In your code you are limiting the query to only retrieve a single record from the blog_avatars table, which is why it is repeating. You need the code to output the createdBy.avatar field, as this will be the image uploaded to the avatar field of the accounts table for the user that created the record.

try this:

<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($record['createdBy.avatar'] as $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" />
<?php endforeach ?>
<?php else : ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Membership plugin - author specific photo

By Gabums85 - January 31, 2012 - edited: January 31, 2012

It worked! But alas, I was informed that I have to have the code to pull from the Blog Avatar table and not the account manager... ::sigh::

::EDIT::

So as much as I would love to take credit for this being solved... my boss is the one who figured out the code :)

Here it is if anyone wants to know:

<?php $post_author = $record['createdBy.username'] ?>

<!-- SET VARIABLE TO DETERMINE IF USER UPLOADED AN IMAGE -->
<?php $avatar_match = 0; ?>

<!-- LOAD AVATAR -->
<?php foreach ($blog_avatarsRecords as $record): ?>
<?php if ($record['name'] == $post_author): ?>
<?php foreach ($record['avatar'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="75" height="75" />
<?php endforeach ?>
<?php $avatar_match +=1; ?>
<?php endif ?>
<?php endforeach ?>

<!-- IF NO RECORDS MATCH, LOAD GENERIC IMAGE -->
<?php if ($avatar_match == 0): ?>
<img src="images/fpo_avatar.jpg" width="75" height="75" />
<?php endif ?>


Thank you very much to everyone who has been helping me through this the last few days. Hopefully the above code helps others too.
Gab