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: [gkornbluth] Membership plugin - author specific photo

Hey everyone,

Ok I got it working kinda but there is some funky stuff going on. I'm going to attach a stripped down file to see if maybe that will help. So when I did the error testing again that Tom recommended, I noticed that the uploaded images from the Blog_Avatars table won't work unless there is an avatar upload form in the Accounts table as well... So now I have them both up and both with images downloaded to the tables. Anyways, using this code:

<?php if ($record['createdBy.avatar']): ?>
<?php foreach ($blog_avatarsRecord['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 ?>


Causes the last image that has been added to the manager to be the one that shows up when there is an image created by the user. So my boss uploaded her image after I had, and now for my posts, her image comes up as well as on her own posts. The else statement works. This is the closest I have gotten with every variation of the code I can think of...

Thanks again everyone! You're lifesavers :)
Attachments:

index_test.php 5K

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/