Show file author/uploader in gallery images

Permalink
Hi all!

I wanted to add a block of code in a gallery that will call out the name of the file and show the name of the uploader/author as well, but I think I must be doing something wrong because the name changes depending on who logs in.

So for example, USER1 logs in, and he'll see file1.jpg by user1.
But if USER2 logs in, he'll see file1.jpg by user2 instead.

Can someone tell me what I did wrong?

In /concrete/packages/asmiller_gallery/blocks/asmiller_gallery/view.php, I did this:

<?php     
   foreach($images as $imgInfo) {
   $f = File::getByID($imgInfo['fID']);
      echo $imgInfo['width'];
      echo '<li><img src="';
      echo $f->getRelativePath();
      echo '" ';
      echo 'title="';
      echo $imgInfo['description'];
      $title = $f->getApprovedVersion()->getTitle();
echo $title;
      echo " by ";
        echo $u->getUserName();
      echo '"/></li>';
         ;}; ?>

gnyma
 
aghouseh replied on at Permalink Reply
aghouseh
You are getting the name of the User object, which would be relative to who is logged in. You need to get the approved version of the file object and then run getAuthorName() on that.

echo $f->getApprovedVersion()->getAuthorName();


Without testing, that should do the trick.
gnyma replied on at Permalink Reply
gnyma
Thanks so much! It did work! :)

But here's the thing – it seems to work on the asmiller gallery, but not in the Sortable Fancybox gallery (which I am also implementing):

<div class="sortable_fancybox_gallery_container">
<?php  foreach ($images as $img): ?>
   <div class="sortable_fancybox_gallery_image" style="height: <?php  echo $max_row_height; ?>px; width: <?php  echo $column_width; ?>;">
      <?php  if ($enableLightbox): ?>
         <a href="<?php  echo $img['full_src']; ?>" rel="<?php  echo $rel; ?>" title="<?php  echo $img['title']; ?><?php echo " by "; ?><?php echo $f->getApprovedVersion()->getAuthorName(); ?>">
            <?php  echo $html->image($img['thumb_src'], $img['thumb_width'], $img['thumb_height'], array('alt' => $img['title'])); ?>
         </a>
      <?php  else: ?>
         <?php  echo $html->image($img['full_src'], $img['full_width'], $img['full_height'], array('alt' => $img['title'])); ?>
      <?php  endif; ?>
   </div>


This is very weird!
aghouseh replied on at Permalink Best Answer Reply
aghouseh
It looks like the controller of the sortable fancybox returns an array of image properties (url, title, etc), so you really don't have access to the file object as you did in the other block. You would have to modify the controller to also add the author to the returned array. Something like this under line 42:

$image['author'] = htmlspecialchars($fv->getAuthorName(), ENT_QUOTES, 'UTF-8');


Then within your view file you could call the following to echo the author name:

echo $img['author'];


That should do the trick.
gnyma replied on at Permalink Reply
gnyma
Andrew, thanks so much for this -- it works perfectly! :)