Tuesday 13 October 2009 8:23:11 am
Hi, guys. Wondered if someone could take small time amount to check and tell me what am i doing wrong. I am very new to ezpublish, and try to create a datatype for rating any possible content (range is 1 to 5). I tried following the excellent article from Thomas Koch(http://ez.no/developer/articles/creating_datatypes_in_ez_publish_4), as well as existing standard ezpublish datatypes like eZInteger. Whenever I install my extension, when i want to edit/create/modify a class, I get this page: http://stephane.persyn.free.fr/fre-FR.html As you can see, debug output isn't giving any hints. For your comfort, I created a tar.gz file cnoatining the whole mlcndatatype extension structure availabale here: http://stephane.persyn.free.fr/mlcndatatype.tar.gz You can see here my settings/override/site.ini.append file where i tell ezpublish about my new extension <b>"mlcndatatype" :</b>
[ExtensionSettings]
ActiveExtensions[]=ezgmaplocation
ActiveExtensions[]=ezjscore
ActiveExtensions[]=ezmultiupload
ActiveExtensions[]=ezodf
ActiveExtensions[]=ezoe
ActiveExtensions[]=ezstarrating
ActiveExtensions[]=ezwebin
ActiveExtensions[]=ezwt
ActiveExtensions[]=mlcndatatype
also, you can see below my <b>extension/mlcndatatype/settings/content.ini.append</b> file:
[DataTypeSettings]
ExtensionDirectories[]=mlcndatatype
AvailableDataTypes[]=mlcnrating
..as well as my <b>extension/mlcndatatype/settings/design.ini.append</b> file :
[ExtensionSettings]
DesignExtensions[]=mlcndatatype
Now about the <b>mlcnratingtype.php</b> file, located in <b>extension/mlcndatatype/datatypes/mlcnrating/ </b>:
<?php
/*!
\class mlcnRatingType mlcnratingtype.php
\ingroup mlcnDatatype
\brief Prend en charge le type de donnée mlcnRating. En utilisant mlcnRating vous pouvez...
\version 1.0
\date Lundi 12 Octobre 2009 20:44:43
\author Stéphane Persyn
permet aux utilisateurs de donner un score à n'importe lequel de vos objets.
un operateur de template prévoit de pouvoir agréger les données de score au niveau du parent node
pour afficher le score moyen obtenu, ainsi que le nombre de votes total.
*/
class mlcnRatingType extends eZDataType
{
const DATA_TYPE_STRING = "mlcnrating";
/*!
Constructeur
*/
function mlcnRatingType()
{
$this->eZDataType( self::DATA_TYPE_STRING, "mlcnRating" );
$this->IntegerValidator = new eZIntegerValidator();
}
/*!
Validates all variables given on content class level
\return eZInputValidator::STATE_ACCEPTED or eZInputValidator::STATE_INVALID if
the values are accepted or not
*/
function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
{
return eZInputValidator::STATE_ACCEPTED;
}
/*!
Fetches all variables inputed on content class level
\return true if fetching of class attributes are successfull, false if not
*/
function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
{
return true;
}
/*!
Validates input on content object level
\return eZInputValidator::STATE_ACCEPTED or eZInputValidator::STATE_INVALID if
the values are accepted or not
*/
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
$classAttribute = $contentObjectAttribute->contentClassAttribute();
if ( $http->hasPostVariable( $base . "_mlcnrating_data_int_" . $contentObjectAttribute->attribute( "id" ) ) )
{
$data = $http->postVariable( $base . "_mlcnrating_data_int_" . $contentObjectAttribute->attribute( "id" ) );
$data = str_replace(" ", "", $data );
if ( $data == "" )
{
if ( !$classAttribute->attribute( 'is_information_collector' ) and
$contentObjectAttribute->validateIsRequired() )
{
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
'Input required.' ) );
return eZInputValidator::STATE_INVALID;
}
else
return eZInputValidator::STATE_ACCEPTED;
}
else
{
$this->IntegerValidator->setRange( "1", "5" );
$state = $this->IntegerValidator->validate( $data );
if( $state===1 )
return eZInputValidator::STATE_ACCEPTED;
else
{
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
'The number is not within the required range 1 - 5' ) );
return eZInputValidator::STATE_INVALID;
}
}
}
else if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() )
{
$contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'Input required.' ) );
return eZInputValidator::STATE_INVALID;
}
else
return eZInputValidator::STATE_ACCEPTED;
}
/*!
Sets the default value.
*/
function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
{
if ( $currentVersion != false )
{
$dataInt = $originalContentObjectAttribute->attribute( "data_int" );
$contentObjectAttribute->setAttribute( "data_int", $dataInt );
}
else
$contentObjectAttribute->setAttribute( "data_int", null );
}
/*!
Fetches all variables from the object
\return true if fetching of class attributes are successfull, false if not
*/
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
if ( $http->hasPostVariable( $base . "_mlcnrating_data_int_" . $contentObjectAttribute->attribute( "id" ) ) )
{
$data = $http->postVariable( $base . "_mlcnrating_data_int_" . $contentObjectAttribute->attribute( "id" ) );
$data = trim( $data ) != '' ? $data : null;
$data = str_replace(" ", "", $data);
$contentObjectAttribute->setAttribute( "data_int", $data );
return true;
}
return false;
}
/*!
Returns the content.
*/
function objectAttributeContent( $contentObjectAttribute )
{
return contentObjectAttribute->attribute( "data_int" );
}
/*!
Returns the meta data used for storing search indeces.
*/
function metaData( $contentObjectAttribute )
{
return contentObjectAttribute->attribute( "data_int" );
}
/*!
Returns the value as it will be shown if this attribute is used in the object name pattern.
*/
function title( $contentObjectAttribute, $name = null )
{
return $contentObjectAttribute->attribute( "data_int" );
}
/*!
\return true if the datatype can be indexed
*/
function isIndexable()
{
return false;
}
}
eZDataType::register( mlcnRatingType::DATA_TYPE_STRING, "mlcnRatingType" );
?>
Now about the view and edit templates: <b>1/ view object template located in extension/mlcndatatype/design/standard/templates/content/datatype/view/</b>:
{$attribute.data_int}
<b<2/ edit object template located in extension/mlcndatatype/design/standard/templates/content/datatype/edit/:</b>
{default attribute_base=ContentObjectAttribute}
<input id="ezcoa-{if ne( $attribute_base, 'ContentObjectAttribute' )}{$attribute_base}-{/if}{$attribute.contentclassattribute_id}_{$attribute.contentclass_attribute_identifier}"
class="box ezcc-{$attribute.object.content_class.identifier} ezcca-{$attribute.object.content_class.identifier}_{$attribute.contentclass_attribute_identifier}"
type="text"
name="{$attribute_base}_mlcnrating_data_int_{$attribute.id}"
size="1"
value="{$attribute.data_int}" />
{/default}
<b>3/ view class template located in extension/mlcndatatype/design/standard/templates/class/datatype/view/:</b>
/* nothing to do here */
<b<4/ edit class template located in extension/mlcndatatype/design/standard/templates/class/datatype/edit/:</b>
/* nothing to do here */
I didn't create a specific mlcnRating class, as I don't see any need for that, at the end it's just an even more basic datatype than ezInteger, with specific & known in advance min/max values (1 & 5)....
Again, you can find a zip file containing the whole mlcndatatype extension structure at the link : http://stephane.persyn.free.fr/mlcndatatype.tar.gz
All help wil be gratly apreciated :) Cheers, Stéphane
|