thumbnails in 5.3

Permalink 1 user found helpful
In 5.2, I used code like this:
<code>
$cobj->getAttribute('thumbnail')->getThumbnail(100,100)->src
</code>

After the 5.3 update, I see that I must add a getVersion and getURL instead of src but I still can't seem to get getThumbnail to work.

<code>
$cobj->getAttribute('thumbnail')->getVersion()->getURL()
</code>

I've searched the forums but all the examples seem to be pre 5.3.

PerryJohnson
View Replies:
Remo replied on at Permalink Reply
Remo
this is what I'm using:

$lfb = LibraryFileBlockController::getFile($cobj->getAttribute('thumbnail')->fID);
echo $lfb->getThumbnail(75,75)->src
PerryJohnson replied on at Permalink Reply
PerryJohnson
The code you posted works! Thank you!
brennaH replied on at Permalink Reply
brennaH
I get a mysql "mysql error: [1146: Table 'techfocu_c5.btFile' doesn't exist" when I try and run this code. Sure enough, btFile does not, in fact, exist.

Looks like it's the LibraryFileBlockController::getFile method that's springing the error.

Am I missing something obvious? All the other variables/methods resolve as expected...
ScottC replied on at Permalink Reply
ScottC
if you check out the block itself, it has much of the methods referencing the models of type: File and File_Version and the concrete/helpers/file.php which has more to do with system paths and less (well nothing) to do with actually referencing files.

The library_file block imo and from what I have read has been "deprecated" but kept around to facilitate legacy blocks working.

File::getVersion or something like that is more current.
brennaH replied on at Permalink Reply
brennaH
but, for example, if I am trying to reference a page attribute of type file/image -- just output it on a page -- what method(s) would you use to access it? I don't see any documentation about an object of type File.
matogertel replied on at Permalink Reply
matogertel
$imgHelper = Loader::helper('image');
$thumb = $cobj->getAttribute('thumbnail');
$imgHelper->getThumbnail($thumb, 100, 100);


Or you can give this block a try:
http://www.codium.co.nz/page_block_for_concrete5/...
Remo replied on at Permalink Reply
Remo
I already thought that such an ugly code doesn't make much sense ;-) But it worked...

But yours is much nicer!
Remo replied on at Permalink Reply
Remo
that block is nice, did you send a link to Andrew? Would be nice to have it in the marketplace!
matogertel replied on at Permalink Reply
matogertel
already did :-)
Glad you liked it!
PerryJohnson replied on at Permalink Reply
PerryJohnson
Glad to see that this works as well.
synlag replied on at Permalink Reply
synlag
the block is great.

i've put the following to controller.php
public function getBlocks() {
                        return $this->page->getBlocks();
                }


and created a template templates/temp.php

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
?>
<h3><a href="<?= $controller->getLink(); ?>"><?= $controller->getName(); ?></a></h3>
<p><?= $controller->getDescription(); ?></p>
<?php
    $blocks = $controller->getBlocks();
    foreach($blocks as $b) {
    if ($b->getBlockTypeHandle() ==
            'guestbook') {
        $bi = $b->getInstance();
        $entries = $bi->getEntries();
        print "Comments: " . count($entries);
    }
}


to display the number of guestbook entries, but the result is always 0, whatever the number of guestbook entries is.

Any idea, what i'm doing wrong?
marius replied on at Permalink Reply
marius
Hi synlag

Have also 0. When i look in the array:
$bi = $b->getInstance(); 
foreach ($bi as $c) {
echo $c ."<br>";
}

The result is:
63
0
Comments:
1
1
0

It's not the right way to read out the entrys - i have 3 comments in the guestbook at the above example :-/

Can someone help us?

thanks
matogertel replied on at Permalink Reply
matogertel
Ok, I just had a look at the guestbook controller, and the function getEntries uses the global variable $c which is set to the current page. What you need to call (provided you're inside my page block) is:
<?php 
    defined('C5_EXECUTE') or die(_("Access Denied."));
?>
<h3><a href="<?= $controller->getLink(); ?>"><?= $controller->getName(); ?></a></h3>
<p><?= $controller->getDescription(); ?></p>
<?php
    $blocks = $page->getBlocks();
    foreach($blocks as $b) {
    if ($b->getBlockTypeHandle() ==
            'guestbook') {
        $bi = $b->getInstance();
        $entries = GuestBookBlockEntry::getAll($bi->bID, $page->cID, 'ASC');
        print "Comments: " . count($entries);
    }
}
marius replied on at Permalink Reply
marius
Thank you for your answer!

I receive following error:

Catchable fatal error: Object of class Page could not be converted to string in /home/aroundch/public_html/around/concrete/libraries/3rdparty/adodb/adodb.inc.php on line 983

The $page var is wrong, i need the cID ($c->getCollectionID()) right? But how can i read out the cID?

Thank you
matogertel replied on at Permalink Reply
matogertel
Still assuming you're inside my "page block" like synlag is. If you're anywhere else, just replace the $page variable with whatever variable is pointing to the collection you want to get the comments from. EG: inside the page list block use the $cobj variable that's inside the for loop. Makes sense?
marius replied on at Permalink Reply
marius
Thank you very much - it works!
synlag replied on at Permalink Reply
synlag
thx a lot!
nwaterhouse replied on at Permalink Reply
Hi,

I'm still having troubles with this. Perhaps I'm misunderstanding. What I'm trying to do is generate thumbnails of images contained within pages and display them in the page list. Is this possible?

thanks

Nathan
Remo replied on at Permalink Reply
Remo
sure, this is no problem but it needs some php stuff..

This tutorials shows you how to display pictures specified in the page properties:
http://www.codeblog.ch/2009/03/concrete5-templates/...

but you can also extract blocks using a code like this (I assume you know php, oop):

$contentBlocks = array();
$c = new Page::getByPath('/about');
$blocks = $c->getBlocks("sidebar");
foreach($blocks as $b) {
    if ($b->getBlockTypeHandle() == 'content') {
        $contentBlocks[] = $b;
    }
}
mindroth33 replied on at Permalink Reply
as I can get thumbnails of all images are seen and not only one.

Example this web:http://www.varelalamar.com/index.php/media/...

And load more fast

Thank.
maxcal replied on at Permalink Reply
This might sound like a pretty stupid question - how do you select the post thumbnail for a post in the c5 menues / backend?

I´m using the code by matogertel in a custom block.
Mnkras replied on at Permalink Reply
Mnkras
This Thread is 11 months old...
and your question isn't really clear

Mike
Tallfrog replied on at Permalink Reply
Tallfrog
Been looking for this PHP snippet for ages.
Thank you for sharing.
warrenparadigm replied on at Permalink Reply
where do we insert these 'codes' im a newb and I have no idea whats going on.. seriously though, Im looking for some simple help and everything I read on here is about inserting codes? do I put this in my terminal?
Tallfrog replied on at Permalink Reply
Tallfrog
@warrenp:
All depends on which code you want to insert?
For instance, the comment code would be within a page-list. So it shows the number of comments for each "post".

I'll be monitoring this post, If you reply, It shouldn't be long before I reply back...if your issue wasn't resolved before :P
kranthi20 replied on at Permalink Reply
kranthi20
You may get thumbnail image src like this also.

$imgFile = File::getByID($objFile->fID); //for image
$imgSrc = $imgFile->getRelativePathFromID($objFile->fID);

echo "<img src='$imgSrc' />";