Questions concerning object generation

Author Message

Roger Schmidt

Sunday 03 September 2006 1:03:47 pm

Hi all

Does anybody know how to let users generate objects in a folder/section and show them in a different folder/section?

E.g. there should be a single upload page for images (including all the attributes), but these images should be shown on several different pages.

My second question is concerning attributes. Is it possible to store IP address of anonymous users as attribute? How to do that? The value should not be accessable to user, and therefore changeable, as hidden field within form.

Thanks and regards,
Roger

Xavier Dutoit

Monday 04 September 2006 1:00:18 am

Hi,

Not sure about your question on the images, could you give us more details about how to decide what is displayed where ?

Anyway, you can customise templates to display any images stored anywhere.

As for the ip address, don't do that as hidden field, that's too easy to change. Take the variable set by apache instead.

I'd suggest to write a new attribute type that does it. Shouldn't be complicated... and don't hesitate to share it with the community! ;)

X+

http://www.sydesy.com

Roger Schmidt

Monday 04 September 2006 7:51:33 am

Hi

Maybe it was not a good idea to mention images. I have created a custom class and one attribute has image as data type.

It is a general question, if it is possible to show any object in any folder, independent in which folder the object has been created. Because in the admin interface you can just add objects within a specific folder.

On my website the created objects should be shown on several different pages. I am not sure now, if each page has to be linked to a specific folder, but the menu structure - and therefore pages - are following the folder structure. And within a template I have only seen source code showing how to get children of current folder, but not from a different folder.

Or is it possible to have pages independent of folder structure?

Concerning the second question:
Actually, I mentioned that it should not be a hidden field, because it can be changed by any user. Sorry, maybe my word order was not very understandable.

Ok, I will have a look on how to implement a new attribute type. Can you give me good resources to have a quick start on this subject?

Would it also be possible to fill specific attributes using triggers or workflow? I just read about this issue in different posts, but did not have a closer look on this until now.

Thanks and regards,
Roger

Roger Schmidt

Tuesday 05 September 2006 3:19:04 pm

Hi

My first attempt to create an own datatype was not very successful.

I have followed more or less the instructions found here:
http://ez.no/products/ez_publish/documentation/development/extensions/datatypes/new_datatype

ezclientiptype.php found in extension/clientip/datatypes/ezclientip looks like this:

<?php

/*
 * Ins schmiroh 6.9.2006 
 * Followed instructions found in
 * http://ez.no/products/ez_publish/documentation/development/extensions/datatypes/new_datatype
 */

// Include the super class file
include_once( "kernel/classes/ezdatatype.php" );

// Include the file which will be used to validate clientip
include_once( "lib/ezutils/classes/ezclientip.php" );

// Define the name of datatype string
define( "EZ_DATATYPESTRING_CLIENTIP", "ezclientip" );

class eZClientIPType extends eZDataType
{
   /*!
    Construction of the class, note that the second parameter in eZDataType
    is the actual name showed in the datatype dropdown list.
   */
   function eZEmailType()
   {
       $this->eZDataType( EZ_DATATYPESTRING_CLIENTIP, "Client IP" );
   }

   /*!
    Validates the input and returns true if the input was valid for this
    datatype. Here there are no rules for validating client ip, because it is
    automatically set by the system and is read only.
   */
   function validateObjectAttributeHTTPInput( &$http, $base,
                                              &$contentObjectAttribute )
   {
       return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
   }

   /*!
    There is no http input to be fetched. Therefore we leave this function empty.
   */
   function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
   {
   	   return false; //not sure, if true or false
   }

   /*!
    Store the content.
   */
   function storeObjectAttribute( &$contentObjectattribute )
   {
       $data = $_SERVER['HTTP_CLIENT_IP'];
	   $contentObjectAttribute->setAttribute( "data_text", $data );
	   return false; //not sure, if true or false
   }

   /*!
    Returns the content.
   */
   function &objectAttributeContent( &$contentObjectAttribute )
   {
       return $contentObjectAttribute->attribute( "data_text" );
   }

   /*!
    Returns the meta data used for storing search indices.
   */
   function metaData( $contentObjectAttribute )
   {
       return $contentObjectAttribute->attribute( "data_text" );
   }

   /*!
    Returns the text.
   */
   function title( &$contentObjectAttribute )
   {
       return $contentObjectAttribute->attribute( "data_text" );
   }
}

eZDataType::register( EZ_DATATYPESTRING_CLIENTIP, "ezclientiptype" );

All the other steps were followed really carefully, including activation in admin interface, but the new datatype ("Client IP") is not showing up in datatype dropdown.

Maybe someone can have a look in the code above and finds a reason for this, or can give me any hint. Are there any logs available when activating a new datatype? Debugging information in admin interface does not give any info on that.

Thanks and regards,
Roger

Roger Schmidt

Tuesday 05 September 2006 3:36:20 pm

Ok, I found one problem! Just the constructor was wrongly named. Now it is showing up in the datatype list. Sorry, already too late in the evening! ;-)

But now I get an error when trying to save a new object within admin interface:

Fatal error: Call to a member function on a non-object in c:\program files\apache software foundation\apache\htdocs\fun-pics\extension\clientip\datatypes\ezclientip\ezclientiptype.php on line 54
Fatal error: eZ publish did not finish its request

The execution of eZ publish was abruptly ended, the debug output is present below.

Below there is no additional debug output, but never mind.

Line 54 is in function storeObjectAttribute:
$contentObjectAttribute->setAttribute( "data_text", $data );

Regards,
Roger

Clemens T

Tuesday 05 September 2006 4:15:36 pm

Heya Roger,

This seems to be the problem:

  /*!     Store the content.    */    
function storeObjectAttribute( &$contentObjectattribute )   

should be:

  /*!     Store the content.    */    
function storeObjectAttribute( &$contentObjectAttribute )   

A little typo (lowercase a) @ $contentObjectattribute.

Greets & happy coding,
Clemens

Roger Schmidt

Wednesday 06 September 2006 3:31:49 pm

Thanks Clemens. You are the man!

This typo has been copied/pasted from the chapter 'New datatype' of official eZ publish 3.4 documentation.

I will drop a comment there.

Cheers,
Roger

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