Membership plugin - author specific photo

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/

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