Get the image storage path from a ContentObjectID (php-side)

Author Message

Alexandre Nion

Monday 30 January 2006 6:48:47 am

Hi all,

I'm in a php function and I have the ID of a contentObject which represents an ezImage object. And my problem is that I'd like to know his real storage url but I don't see any simple way to do it, although it shouldn't be so difficult... I mean that when I do:

$myImageObject = eZContentObject :: fetch( 76 );  // where 76 is my contentObjectID
print_r( $myImageObject  );
// displays properties but doesn't display any contained attributes.. don't know why..

// Then I can do:
print_r( $myImageObject->contentObjectAttributes() );
// to display all the object attributes..

Array {
....
    [2] => ezcontentobjectattribute Object
        (
 ...
            [ID] => 266
            [ContentObjectID] => 76
            [Version] => 2
            [LanguageCode] => fre-FR
            [AttributeOriginalID] => 0
            [SortKeyInt] => 0
            [SortKeyString] => 
            [DataTypeString] => ezimage
            [DataText] => <?xml version="1.0" encoding="UTF-8"?>
<ezimage serial_number="1"
         is_valid="1"
         filename="geek.png"
         suffix="png"
         basename="geek"
         dirpath="var/plain/storage/images/media/images/geek/266-2-fre-FR"
         url="var/plain/storage/images/media/images/geek/266-2-fre-FR/geek.png"
         original_filename="alignement_resultats.png"
         mime_type="image/png"
         width="1155"
         height="217"
         alternative_text=""
         alias_key="1293033771"
         timestamp="1138213887">
  <original attribute_id=""
            attribute_version=""
            attribute_language="" />
</ezimage>

            [DataInt] => 
            [DataFloat] => 0
        )
...
}

// Well, now I can see the storage path in the DataText field but I don't know how to access it easily (without having to parse individually, I'd like a generic method..):

So is there a way to get the image storage url easily? (maybe via ezImage or imageHanler, I didn't manage with the objects tried)

Thanx for your lights,
Alexandre

Łukasz Serwatka

Monday 30 January 2006 6:57:59 am

Hi Alexandre,

Use this code to get image URL

objectWithIMG = eZContentObject::fetch( 171 ); 
 
$dataMap =& $objectWithIMG->attribute( 'data_map' ); 
 
$image =& $dataMap['image']->content(); 
 
$list =& $image->aliasList(); 
 
var_dump( $list['original']['url'] );

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Alexandre Nion

Monday 30 January 2006 8:26:21 am

wow thank you Lukasz, this code rocks!
Exactly what I needed, I knew it wasn't so hard in the end ;)

Piotrek Karaś

Wednesday 11 February 2009 10:04:47 pm

Hi guys,

And how do we generate an alias that has not been generated up to the moment of fetching?

For example: I have 20 aliases defined in the website, but the aliasList() method only returns 4 (the underlying XML-base for that method also contains 4 alias entries). How do I force particular alias generation in PHP?

Thanks!

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Piotrek Karaś

Thursday 12 February 2009 12:08:31 am

OK, for those interested and also for verification, this seems to work:

<?php
$targetAliasName = 'my_huge_image';
$contentObjectAttributeID = 1234567...;
$contentObjectAttribute = eZContentObjectAttribute::fetch( $contentObjectAttributeID );
$aliasHandler = new eZImageAliasHandler( $contentObjectAttribute );
$myHugeImageAliasData = $aliasHandler->imageAlias( $targetAliasName );
?>

If the alias entry had not existed, seems to be created automatically (provided it had existed in the image.ini declarations). I hope this includes the internal caching layer ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 21:23:20
Script start
Timing: Jan 30 2025 21:23:20
Module start 'layout'
Timing: Jan 30 2025 21:23:20
Module start 'content'
Timing: Jan 30 2025 21:23:20
Module end 'content'
Timing: Jan 30 2025 21:23:20
Script end

Main resources:

Total runtime0.0319 sec
Peak memory usage8,192.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0083 588.3906151.2422
Module start 'layout' 0.00830.0058 739.6328220.7500
Module start 'content' 0.01410.0162 960.38281,005.9922
Module end 'content' 0.03030.0015 1,966.375037.9922
Script end 0.0318  2,004.3672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003310.2963140.0002
Check MTime0.00134.0443140.0001
Mysql Total
Database connection0.00092.914310.0009
Mysqli_queries0.005417.051630.0018
Looping result0.00000.059810.0000
Template Total0.00113.310.0011
Template load0.00082.562910.0008
Template processing0.00020.733610.0002
Override
Cache load0.00061.816510.0006
General
dbfile0.00206.179480.0002
String conversion0.00000.037440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs