eZ Publish  [4.0]
ezdatatype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZDataType class
00004 //
00005 // Created on: <16-Apr-2002 11:08:14 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \defgroup eZDataType Content datatypes */
00032 
00033 /*!
00034   \class eZDataType ezdatatype.php
00035   \ingroup eZKernel
00036   \brief Base class for content datatypes
00037 
00038   Defines both the interface for datatypes as well as functions
00039   for registering, quering and fetching datatypes.
00040 
00041   Each new datatype will inherit this class and define some functions
00042   as well as three templates. A datatype has three roles, it handles
00043   definition of content class attributes, editing of a content object
00044   attribute and viewing of a content object attribute. The content class
00045   attribute definition part is optional while object attribute edit and
00046   view must be implemented for the datatype to be usable.
00047 
00048   If the datatype handles class attribute definition it must define one
00049   or more of these functions: storeClassAttribute, validateClassAttributeHTTPInput,
00050   fixupClassAttributeHTTPInput, fetchClassAttributeHTTPInput. See each function
00051   for more details. The class attribute definition usually defines the
00052   default data and/or the validation rules for an object attribute.
00053 
00054   Object attribute editing must define these functions: storeObjectAttribute,
00055   validateObjectAttributeHTTPInput, fixupObjectAttributeHTTPInput,
00056   fetchObjectAttributeHTTPInput, initializeObjectAttribute. If the attribute
00057   wants to have a custom action it must implement the customObjectAttributeHTTPAction
00058   function. See each function for more details.
00059 
00060   Each datatype initializes itself with a datatype string id (ezstring, ezinteger)
00061   and a descriptive name. The datatype string id must be unique for the whole
00062   system and should have a prefix, for instance we in eZ Systems use ez as our prefix.
00063 */
00064 
00065 //include_once( "kernel/classes/ezpersistentobject.php" );
00066 //include_once( "lib/ezutils/classes/ezinputvalidator.php" );
00067 
00068 class eZDataType
00069 {
00070     /*!
00071      Initializes the datatype with the string id \a $dataTypeString and
00072      the name \a $name.
00073     */
00074     function eZDataType( $dataTypeString, $name, $properties = array() )
00075     {
00076         $this->DataTypeString = $dataTypeString;
00077         $this->Name = $name;
00078 
00079         $translationAllowed = true;
00080         $serializeSupported = false;
00081         $objectSerializeMap = false;
00082         if ( isset( $properties['translation_allowed'] ) )
00083             $translationAllowed = $properties['translation_allowed'];
00084         if ( isset( $properties['serialize_supported'] ) )
00085             $serializeSupported = $properties['serialize_supported'];
00086         if ( isset( $properties['object_serialize_map'] ) )
00087             $objectSerializeMap = $properties['object_serialize_map'];
00088 
00089         $this->Attributes = array();
00090         $this->Attributes["is_indexable"] = $this->isIndexable();
00091         $this->Attributes["is_information_collector"] = $this->isInformationCollector();
00092 
00093         $this->Attributes["information"] = array( "string" => $this->DataTypeString,
00094                                                   "name" => $this->Name );
00095         $this->Attributes["properties"] = array( "translation_allowed" => $translationAllowed,
00096                                                  'serialize_supported' => $serializeSupported,
00097                                                  'object_serialize_map' => $objectSerializeMap );
00098     }
00099 
00100     /*!
00101      \return the template name to use for viewing the attribute.
00102      \note Default is to return the datatype string which is OK
00103            for most datatypes, if you want dynamic templates
00104            reimplement this function and return a template name.
00105      \note The returned template name does not include the .tpl extension.
00106      \sa editTemplate, informationTemplate
00107     */
00108     function viewTemplate( $contentobjectAttribute )
00109     {
00110         return $this->DataTypeString;
00111     }
00112 
00113     /*!
00114      \return the template name to use for editing the attribute.
00115      \note Default is to return the datatype string which is OK
00116            for most datatypes, if you want dynamic templates
00117            reimplement this function and return a template name.
00118      \note The returned template name does not include the .tpl extension.
00119      \sa viewTemplate, informationTemplate
00120     */
00121     function editTemplate( $contentobjectAttribute )
00122     {
00123         return $this->DataTypeString;
00124     }
00125 
00126     /*!
00127      \return the template name to use for information collection for the attribute.
00128      \note Default is to return the datatype string which is OK
00129            for most datatypes, if you want dynamic templates
00130            reimplement this function and return a template name.
00131      \note The returned template name does not include the .tpl extension.
00132      \sa viewTemplate, editTemplate
00133     */
00134     function informationTemplate( $contentobjectAttribute )
00135     {
00136         return $this->DataTypeString;
00137     }
00138 
00139     /*!
00140      \return the template name to use for result view of an information collection attribute.
00141      \note Default is to return the datatype string which is OK
00142            for most datatypes, if you want dynamic templates
00143            reimplement this function and return a template name.
00144      \note The returned template name does not include the .tpl extension.
00145      \note \a $collectionAttribute can in some cases be a eZContentObjectAttribute, so any
00146            datatype that overrides this must be able to handle both types.
00147     */
00148     function resultTemplate( &$collectionAttribute )
00149     {
00150         return $this->DataTypeString;
00151     }
00152 
00153     /*!
00154      \static
00155      Crates a datatype instance of the datatype string id \a $dataTypeString.
00156      \note It only creates one instance for each datatype.
00157     */
00158     static function create( $dataTypeString )
00159     {
00160         $def = null;
00161         if ( !isset( $GLOBALS["eZDataTypes"][$dataTypeString] ) )
00162         {
00163             eZDataType::loadAndRegisterType( $dataTypeString );
00164         }
00165 
00166         if ( isset( $GLOBALS['eZDataTypes'][$dataTypeString] ) )
00167         {
00168             $className = $GLOBALS['eZDataTypes'][$dataTypeString];
00169 
00170             if ( !isset( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) ||
00171                  get_class( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) != $className )
00172             {
00173                 $GLOBALS["eZDataTypeObjects"][$dataTypeString] = new $className();
00174             }
00175             return $GLOBALS["eZDataTypeObjects"][$dataTypeString];
00176         }
00177 
00178         return null;
00179     }
00180 
00181     /*!
00182      \static
00183      \return a list of datatypes which has been registered.
00184      \note This will instantiate all datatypes.
00185     */
00186     static function registeredDataTypes()
00187     {
00188         $types = isset( $GLOBALS["eZDataTypes"] ) ? $GLOBALS["eZDataTypes"] : null;
00189         if ( isset( $types ) )
00190         {
00191             foreach ( $types as $dataTypeString => $className )
00192             {
00193                 if ( !isset( $GLOBALS["eZDataTypeObjects"][$dataTypeString] ) )
00194                 {
00195                     $GLOBALS["eZDataTypeObjects"][$dataTypeString] = new $className();
00196                 }
00197             }
00198             uasort( $GLOBALS["eZDataTypeObjects"],
00199                     create_function( '$a, $b',
00200                                      'return strcmp( $a->Name, $b->Name);' ) );
00201         return $GLOBALS["eZDataTypeObjects"];
00202         }
00203         return null;
00204     }
00205 
00206     /*!
00207      \static
00208      Registers the datatype with string id \a $dataTypeString and
00209      class name \a $className. The class name is used for instantiating
00210      the class and should be in lowercase letters.
00211     */
00212     static function register( $dataTypeString, $className )
00213     {
00214         $types =& $GLOBALS["eZDataTypes"];
00215         if ( !is_array( $types ) )
00216             $types = array();
00217         $types[$dataTypeString] = $className;
00218     }
00219 
00220     /*!
00221      \return the data type identification string.
00222     */
00223     function isA()
00224     {
00225         return $this->Attributes["information"]["string"];
00226     }
00227 
00228     /*!
00229      \return the attributes for this datatype.
00230     */
00231     function attributes()
00232     {
00233         return array_keys( $this->Attributes );
00234     }
00235 
00236     /*!
00237      \return true if the attribute \a $attr exists in this object.
00238     */
00239     function hasAttribute( $attr )
00240     {
00241         return isset( $this->Attributes[$attr] );
00242     }
00243 
00244     /*!
00245      \return the data for the attribute \a $attr or null if it does not exist.
00246     */
00247     function attribute( $attr )
00248     {
00249         if ( isset( $this->Attributes[$attr] ) )
00250         {
00251             return $this->Attributes[$attr];
00252         }
00253 
00254         eZDebug::writeError( "Attribute '$attr' does not exist", 'eZDataType::attribute' );
00255         $attributeData = null;
00256         return $attributeData;
00257     }
00258 
00259     /*!
00260      \return \c true if the datatype support insertion of HTTP files or \c false (default) otherwise.
00261 
00262      \sa insertHTTPFile()
00263     */
00264     function isHTTPFileInsertionSupported()
00265     {
00266         return false;
00267     }
00268 
00269     /*!
00270      \return \c true if the datatype support insertion of files or \c false (default) otherwise.
00271 
00272      \sa insertRegularFile()
00273     */
00274     function isRegularFileInsertionSupported()
00275     {
00276         return false;
00277     }
00278 
00279     /*!
00280      \return \c true if the datatype support insertion of simple strings or \c false (default) otherwise.
00281 
00282      \sa insertSimpleString()
00283     */
00284     function isSimpleStringInsertionSupported()
00285     {
00286         return false;
00287     }
00288 
00289     /*!
00290      \virtual
00291      Inserts the HTTP file \a $httpFile to the content object attribute \a $objectAttribute.
00292 
00293      \param $object The contentobject in which the attribute is contained
00294      \param $objectVersion The current version of the object it is being worked on
00295      \param $objectLanguage The current language being worked on
00296      \param $objectAttribute The attribute which will get the file
00297      \param $httpFile Object of type eZHTTPFile which contains information on the uploaded file
00298      \param $mimeData MIME-Type information on the file, can be used to figure out a storage name
00299      \param[out] $result Array which will be filled with information on the process, it will contain:
00300                  - errors - Array with error elements, each element is an array with \c 'description' containing the text
00301                  - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
00302 
00303      \return \c true if the file was stored correctly in the attribute or \c false if something failed.
00304      \note The datatype will return \c null (the default) if does not support HTTP files.
00305      \note \a $result will not be defined if the return value is \c null
00306      \note The \a $httpFile must not be stored prior to calling this, the datatype will handle this internally
00307 
00308      \sa isHTTPFileInsertionSupported()
00309     */
00310     function insertHTTPFile( $object, $objectVersion, $objectLanguage,
00311                              $objectAttribute, $httpFile, $mimeData,
00312                              &$result )
00313     {
00314         eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of HTTP files",
00315                                'eZDataType::insertHTTPFile' );
00316         return null;
00317     }
00318 
00319     /*!
00320      \virtual
00321      Inserts the file named \a $filePath to the content object attribute \a $objectAttribute.
00322 
00323      \param $object The contentobject in which the attribute is contained
00324      \param $objectVersion The current version of the object it is being worked on
00325      \param $objectLanguage The current language being worked on
00326      \param $objectAttribute The attribute which will get the file
00327      \param $filePath Full path including the filename
00328      \param[out] $result Array which will be filled with information on the process, it will contain:
00329                  - errors - Array with error elements, each element is an array with \c 'description' containing the text
00330                  - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
00331 
00332      \return \c true if the file was stored correctly in the attribute or \c false if something failed.
00333      \note The datatype will return \c null (the default) if does not support HTTP files.
00334      \note \a $result will not be defined if the return value is \c null
00335 
00336      \sa isRegularFileInsertionSupported()
00337     */
00338     function insertRegularFile( $object, $objectVersion, $objectLanguage,
00339                                 $objectAttribute, $filePath,
00340                                 &$result )
00341     {
00342         eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of regular files",
00343                                'eZDataType::insertRegularFile' );
00344         return null;
00345     }
00346 
00347     /*!
00348      \virtual
00349      Inserts the string \a $string to the content object attribute \a $objectAttribute.
00350 
00351      \param $object The contentobject in which the attribute is contained
00352      \param $objectVersion The current version of the object it is being worked on
00353      \param $objectLanguage The current language being worked on
00354      \param $objectAttribute The attribute which will get the file
00355      \param $filePath Full path including the filename
00356      \param[out] $result Array which will be filled with information on the process, it will contain:
00357                  - errors - Array with error elements, each element is an array with \c 'description' containing the text
00358                  - require_storage - \c true if the attribute must be stored after this call, or \c false if not required at all
00359 
00360      \return \c true if the file was stored correctly in the attribute or \c false if something failed.
00361      \note The datatype will return \c null (the default) if does not support HTTP files.
00362      \note \a $result will not be defined if the return value is \c null
00363 
00364      \sa isSimpleStringInsertionSupported()
00365     */
00366     function insertSimpleString( $object, $objectVersion, $objectLanguage,
00367                                  $objectAttribute, $string,
00368                                  &$result )
00369     {
00370         eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support insertion of simple strings",
00371                                'eZDataType::insertSimplestring' );
00372         return null;
00373     }
00374 
00375     /*!
00376      \virtual
00377      Checks if the datatype supports returning file information.
00378 
00379      \param $object The contentobject in which the attribute is contained
00380      \param $objectVersion The current version of the object it is being worked on
00381      \param $objectLanguage The current language being worked on
00382      \param $objectAttribute The attribute which stored the file
00383 
00384      \return \c true if file information is supported or \c false if it doesn't.
00385     */
00386     function hasStoredFileInformation( $object, $objectVersion, $objectLanguage,
00387                                        $objectAttribute )
00388     {
00389         return false;
00390     }
00391 
00392     /*!
00393      \virtual
00394      This function is called when someone tries to download the file.
00395 
00396      \param $object The contentobject in which the attribute is contained
00397      \param $objectVersion The current version of the object it is being worked on
00398      \param $objectLanguage The current language being worked on
00399      \param $objectAttribute The attribute which stored the file
00400 
00401      \return \c true if any action has been don or \c false if hasn't.
00402     */
00403     function handleDownload( $object, $objectVersion, $objectLanguage,
00404                              $objectAttribute )
00405     {
00406         return false;
00407     }
00408 
00409     /*!
00410      \virtual
00411      Returns file information for the filed stored by the attribute.
00412 
00413      \param $object The contentobject in which the attribute is contained
00414      \param $objectVersion The current version of the object it is being worked on
00415      \param $objectLanguage The current language being worked on
00416      \param $objectAttribute The attribute which stored the file
00417 
00418      \return An array structure with information or \c false (default) if no
00419              information could be found.
00420              The structure must contain:
00421              - filepath - The full path to the file
00422 
00423              The structure can contain:
00424              - filename - The name of the file, if not supplied it will
00425                            be figured out from the filepath
00426              - filesize - The size of the file, if not supplied it will
00427                            be figured out from the filepath
00428              - mime_type - The MIME type for the file, if not supplied it will
00429                            be figured out from the filepath
00430     */
00431     function storedFileInformation( $object, $objectVersion, $objectLanguage,
00432                                     $objectAttribute )
00433     {
00434         return false;
00435     }
00436 
00437     /*!
00438      Fetches the product option information for option with ID \a $optionID and returns this information.
00439      This will be called from the basket when a new product with an option is added, it is then up to the
00440      specific datatype to return proper data. It will also be used to recalcuate prices.
00441 
00442      \param $objectAttribute The attribute that the datatype controls.
00443      \param $optionID The ID of the option which information should be returned from.
00444      \param $productItem The product item object which contains the option, is available for reading only.
00445      \return An array structure which contains:
00446              - id - The unique ID of the selected option, this must be unique in the attribute and will later on
00447                     be used to recalculate prices.
00448              - name - The name of the option list
00449              - value - The display string of the selected option
00450              - additional_price - A value which is added to the total product price, set to 0 or \c false if no price is used.
00451              If the option could not be found it should return \c false, if not supported it should return \c null.
00452      \sa handleProductOption
00453     */
00454     function productOptionInformation( $objectAttribute, $optionID, $productItem )
00455     {
00456         eZDebug::writeWarning( "The datatype " . get_class( $this ) . " for attribute ID " . $objectAttribute->attribute( 'id' ) . " does not support product options",
00457                                'eZDataType::productOptionInformation' );
00458         return null;
00459     }
00460 
00461     /*!
00462       \virtual
00463       Will return information on how the datatype should be represented in
00464       the various display modes when used by an object.
00465 
00466       If this method is reimplemented the implementor must call this method
00467       with the new info array as second parameter.
00468 
00469       \param $objectAttribute The content object attribute to return info for.
00470       \param $mergeInfo A structure that must match the returned array, or \c false to ignore.
00471                         Any entries here will override the default.
00472       \return An array structure which contains:
00473               - \c edit
00474                 - \c grouped_input - If \c true then the datatype has lots of input elements
00475                                      that should be grouped. (e.g. in a fieldset)
00476                                      EditSettings/GroupedInput in datatype.ini is used to
00477                                      automatically determine this field
00478                 .
00479               - \c view
00480               - \c collection
00481                 - \c grouped_input - If \c true then the datatype has lots of input elements
00482                                      that should be grouped. (e.g. in a fieldset)
00483                                      CollectionSettings/GroupedInput in datatype.ini is used to
00484                                      automatically determine this field and will override
00485                                      the default and datatype setting if used.
00486                 .
00487               - \c result
00488     */
00489     function objectDisplayInformation( $objectAttribute, $mergeInfo = false )
00490     {
00491         $datatype = $objectAttribute->attribute( 'data_type_string' );
00492         $ini = eZINI::instance( 'datatype.ini' );
00493         $editGrouped = in_array( $datatype, $ini->variable( 'EditSettings', 'GroupedInput' ) );
00494         $viewGrouped = in_array( $datatype, $ini->variable( 'ViewSettings', 'GroupedInput' ) );
00495         $resultGrouped = in_array( $datatype, $ini->variable( 'ResultSettings', 'GroupedInput' ) );
00496         $collectionGrouped = in_array( $datatype, $ini->variable( 'CollectionSettings', 'GroupedInput' ) );
00497 
00498         $info = array( 'edit' => array( 'grouped_input' => false ),
00499                        'view' => array( 'grouped_input' => false),
00500                        'collection' => array( 'grouped_input' => false ),
00501                        'result' => array( 'grouped_input' => false ) );
00502         $override = array();
00503         if ( $editGrouped )
00504             $override['edit']['grouped_input'] = true;
00505         if ( $collectionGrouped )
00506             $override['collection']['grouped_input'] = true;
00507         if ( $viewGrouped )
00508             $override['view']['grouped_input'] = true;
00509         if ( $resultGrouped )
00510             $override['result']['grouped_input'] = true;
00511 
00512         if ( $mergeInfo )
00513         {
00514             // All entries in $mergeInfo will override the defaults
00515             foreach ( array( 'edit', 'view', 'collection', 'result' ) as $view )
00516             {
00517                 if ( isset( $mergeInfo[$view] ) )
00518                     $info[$view] = array_merge( $info[$view], $mergeInfo[$view] );
00519                 if ( isset( $override[$view] ) )
00520                     $info[$view] = array_merge( $info[$view], $override[$view] );
00521             }
00522         }
00523         else
00524         {
00525             // All entries in $override will override the defaults
00526             foreach ( array( 'edit', 'view', 'collection', 'result' ) as $view )
00527             {
00528                 if ( isset( $override[$view] ) )
00529                     $info[$view] = array_merge( $info[$view], $override[$view] );
00530             }
00531         }
00532         return $info;
00533     }
00534 
00535     /*!
00536       \virtual
00537       Will return information on how the datatype should be represented in
00538       the various display modes when used by a class.
00539 
00540       If this method is reimplemented the implementor must call this method
00541       with the new info array as second parameter.
00542 
00543       \param $classAttribute The content class attribute to return info for.
00544       \param $mergeInfo A structure that must match the returned array, or \c false to ignore.
00545                         Any entries here will override the default.
00546       \return An array structure which contains:
00547               - \c edit
00548                 - \c grouped_input - If \c true then the datatype has lots of input elements
00549                                      that should be grouped. (e.g. in a fieldset)
00550                                      ClassEditSettings/GroupedInput in datatype.ini is used to
00551                                      automatically determine this field and will override
00552                                      the default and datatype setting if used.
00553                 .
00554               - \c view
00555     */
00556     function classDisplayInformation( $classAttribute, $mergeInfo = false )
00557     {
00558         $datatype = $classAttribute->attribute( 'data_type_string' );
00559         $ini = eZINI::instance( 'datatype.ini' );
00560         $editGrouped = in_array( $datatype, $ini->variable( 'ClassEditSettings', 'GroupedInput' ) );
00561 
00562         $info = array( 'edit' => array( 'grouped_input' => false ),
00563                        'view' => array() );
00564         $override = array();
00565         if ( $editGrouped )
00566             $override['edit']['grouped_input'] = true;
00567 
00568         if ( $mergeInfo )
00569         {
00570             // All entries in $mergeInfo will override the defaults
00571             foreach ( array( 'edit', 'view' ) as $view )
00572             {
00573                 if ( isset( $mergeInfo[$view] ) )
00574                     $info[$view] = array_merge( $info[$view], $mergeInfo[$view] );
00575                 if ( isset( $override[$view] ) )
00576                     $info[$view] = array_merge( $info[$view], $override[$view] );
00577             }
00578         }
00579         else
00580         {
00581             // All entries in $override will override the defaults
00582             foreach ( array( 'edit', 'view' ) as $view )
00583             {
00584                 if ( isset( $override[$view] ) )
00585                     $info[$view] = array_merge( $info[$view], $override[$view] );
00586             }
00587         }
00588         return $info;
00589     }
00590 
00591     /*!
00592      Returns the content data for the given content object attribute.
00593     */
00594     function objectAttributeContent( $objectAttribute )
00595     {
00596         $retValue = '';
00597         return $retValue;
00598     }
00599 
00600     /*!
00601      \return \c true if the datatype finds any content in the attribute \a $contentObjectAttribute.
00602     */
00603     function hasObjectAttributeContent( $contentObjectAttribute )
00604     {
00605         return false;
00606     }
00607 
00608     /*!
00609      Returns the content data for the given content class attribute.
00610     */
00611     function classAttributeContent( $classAttribute )
00612     {
00613         return '';
00614     }
00615 
00616     /*!
00617      Stores the datatype data to the database which is related to the
00618      object attribute.
00619      \return True if the value was stored correctly.
00620      \note The method is entirely up to the datatype, for instance
00621            it could reuse the available types in the the attribute or
00622            store in a separate object.
00623      \sa fetchObjectAttributeHTTPInput
00624     */
00625     function storeObjectAttribute( $objectAttribute )
00626     {
00627     }
00628 
00629     /*!
00630      Performs necessary actions with attribute data after object is published,
00631      it means that you have access to published nodes.
00632      \return True if the value was stored correctly.
00633      \note The method is entirely up to the datatype, for instance
00634            it could reuse the available types in the the attribute or
00635            store in a separate object.
00636 
00637      \note Might be transaction unsafe.
00638     */
00639     function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
00640     {
00641     }
00642 
00643     /*!
00644      Similar to the storeClassAttribute but is called before the
00645      attribute itself is stored and can be used to set values in the
00646      class attribute.
00647      \return True if the value was stored correctly.
00648      \sa fetchClassAttributeHTTPInput
00649     */
00650     function preStoreClassAttribute( $classAttribute, $version )
00651     {
00652     }
00653 
00654     /*!
00655      Stores the datatype data to the database which is related to the
00656      class attribute. The \a $version parameter determines which version
00657      is currently being stored, 0 is the real version while 1 is the
00658      temporary version.
00659      \return True if the value was stored correctly.
00660      \note The method is entirely up to the datatype, for instance
00661            it could reuse the available types in the the attribute or
00662            store in a separate object.
00663      \note This function is called after the attribute data has been stored.
00664            If you need to alter attribute data use preStoreClassAttribute instead.
00665      \sa fetchClassAttributeHTTPInput
00666     */
00667     function storeClassAttribute( $classAttribute, $version )
00668     {
00669     }
00670 
00671 
00672     /*!
00673      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00674      the calls within a db transaction; thus within db->begin and db->commit.
00675      */
00676     function storeDefinedClassAttribute( $classAttribute )
00677     {
00678     }
00679 
00680     function preStoreDefinedClassAttribute( $classAttribute )
00681     {
00682         $this->preStoreClassAttribute( $classAttribute, $classAttribute->attribute( 'version' ) );
00683     }
00684 
00685     /*!
00686      Validates the input for a class attribute and returns a validation
00687      state as defined in eZInputValidator.
00688      \note Default implementation does nothing and returns accepted.
00689     */
00690     function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
00691     {
00692         return eZInputValidator::STATE_ACCEPTED;
00693     }
00694 
00695     /*!
00696      Tries to do a fixup on the input text so that it's acceptable as
00697      class attribute input.
00698      \note Default implementation does nothing and returns accepted.
00699     */
00700     function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
00701     {
00702         return eZInputValidator::STATE_ACCEPTED;
00703     }
00704 
00705     /*!
00706      Fetches the HTTP input for the content class attribute.
00707      \note Default implementation does nothing.
00708     */
00709     function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
00710     {
00711     }
00712 
00713     /*!
00714      Executes a custom action for a class attribute which was defined on the web page.
00715      \note Default implementation does nothing.
00716     */
00717     function customClassAttributeHTTPAction( $http, $action, $classAttribute )
00718     {
00719     }
00720 
00721     /*!
00722      Matches the action against the action name \a $actionName
00723      and extracts the value from the action puts it into \a $value.
00724      \return \c true if the action matched and a value was found,
00725              \c false otherwise.
00726      \node If no match is made or no value found the \a $value parameter is not modified.
00727     */
00728     function fetchActionValue( $action, $actionName, &$value )
00729     {
00730         if ( preg_match( "#^" . $actionName . "_(.+)$#", $action, $matches ) )
00731         {
00732             $value = $matches[1];
00733             return true;
00734         }
00735         return false;
00736     }
00737 
00738     /*!
00739      Validates the input for an object attribute and returns a validation
00740      state as defined in eZInputValidator.
00741      \note Default implementation does nothing and returns accepted.
00742     */
00743     function validateObjectAttributeHTTPInput( $http, $base, $objectAttribute )
00744     {
00745         return eZInputValidator::STATE_ACCEPTED;
00746     }
00747 
00748     /*!
00749      Tries to do a fixup on the input text so that it's acceptable as
00750      object attribute input.
00751      \note Default implementation does nothing.
00752     */
00753     function fixupObjectAttributeHTTPInput( $http, $base, $objectAttribute )
00754     {
00755     }
00756 
00757     /*!
00758      Fetches the HTTP input for the content object attribute.
00759      \note Default implementation does nothing.
00760     */
00761     function fetchObjectAttributeHTTPInput( $http, $base, $objectAttribute )
00762     {
00763     }
00764 
00765     /*!
00766      Validates the input for an object attribute and returns a validation
00767      state as defined in eZInputValidator.
00768      \note Default implementation does nothing and returns accepted.
00769     */
00770     function validateCollectionAttributeHTTPInput( $http, $base, $objectAttribute )
00771     {
00772         return eZInputValidator::STATE_ACCEPTED;
00773     }
00774 
00775     /*!
00776      Tries to do a fixup on the input text so that it's acceptable as
00777      object attribute input.
00778      \note Default implementation does nothing.
00779     */
00780     function fixupCollectionAttributeHTTPInput( $http, $base, $objectAttribute )
00781     {
00782     }
00783 
00784     /*!
00785      Fetches the HTTP collected information for the content object attribute.
00786      \note Default implementation does nothing.
00787 
00788      \return true if variable was successfully fetched.
00789     */
00790     function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $objectAttribute )
00791     {
00792     }
00793 
00794     /*!
00795      Executes a custom action for an object attribute which was defined on the web page.
00796      \note Default implementation does nothing.
00797     */
00798     function customObjectAttributeHTTPAction( $http, $action, $objectAttribute, $parameters )
00799     {
00800     }
00801 
00802     /*!
00803      Takes care of custom action handling, this means checking if a custom action request
00804      must be sent to a contentobject attribute. This function is only useful for
00805      datatypes that must do custom action handling for sub objects and attributes.
00806      \note Default implementation does nothing.
00807     */
00808     function handleCustomObjectHTTPActions( $http, $attributeDataBaseName,
00809                                             $customActionAttributeArray, $customActionParameters )
00810     {
00811     }
00812 
00813     /*!
00814      Initializes the class attribute with some data.
00815      \note Default implementation does nothing.
00816     */
00817     function initializeClassAttribute( $classAttribute )
00818     {
00819     }
00820 
00821     /*!
00822      Clones the date from the old class attribute to the new one.
00823      \note Default implementation does nothing which is good enough for datatypes which does not use external tables.
00824     */
00825     function cloneClassAttribute( $oldClassAttribute, $newClassAttribute )
00826     {
00827     }
00828 
00829     /*!
00830      Initializes the object attribute with some data.
00831      \note Default implementation does nothing.
00832     */
00833     function initializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute )
00834     {
00835     }
00836 
00837     /*!
00838      Tries to do a repair on the content object attribute \a $contentObjectAttribute and returns \c true if it succeeds.
00839      \return \c false if it fails or \c null if it is not supported to do a repair.
00840     */
00841     function repairContentObjectAttribute( $contentObjectAttribute )
00842     {
00843         return null;
00844     }
00845 
00846     /*!
00847      Initializes the object attribute with some data after object attribute is already stored. It means that for initial version you allready have an attribute_id and you can store data somewhere using this id.
00848      \note Default implementation does nothing.
00849     */
00850     function postInitializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute )
00851     {
00852     }
00853 
00854     /*
00855      Makes some post-store operations. Called by framework after store of eZContentObjectAttribute object.
00856     */
00857     function postStore( $objectAttribute )
00858     {
00859     }
00860 
00861     /*!
00862      Do any necessary changes to stored object attribute when moving an object to trash.
00863      \note Default implementation does nothing.
00864     */
00865     function trashStoredObjectAttribute( $objectAttribute, $version = null )
00866     {
00867     }
00868 
00869     /*!
00870      Clean up stored object attribute
00871      \note Default implementation does nothing.
00872     */
00873     function deleteStoredObjectAttribute( $objectAttribute, $version = null )
00874     {
00875     }
00876 
00877     /*!
00878      Clean up stored class attribute
00879      \note Default implementation does nothing.
00880     */
00881     function deleteStoredClassAttribute( $classAttribute, $version = null )
00882     {
00883     }
00884 
00885     /*!
00886      \return the content action(s) which can be performed on object containing
00887      the current datatype.
00888     */
00889     function contentActionList( $classAttribute )
00890     {
00891         $actionList = array();
00892         if ( is_object( $classAttribute ) )
00893         {
00894             if ( $classAttribute->attribute( 'is_information_collector' ) == true )
00895             {
00896                 $actionList[] = array( 'name' => ezi18n( 'kernel/classes/datatypes', 'Send', 'Datatype information collector action' ),
00897                                        'action' => 'ActionCollectInformation' );
00898             }
00899         }
00900         else
00901         {
00902             eZDebug::writeError( '$classAttribute isn\'t an object.', 'eZDataType::contentActionList' );
00903         }
00904         return $actionList;
00905     }
00906 
00907     /*!
00908      \return true if the data type can do information collection
00909     */
00910     function hasInformationCollection()
00911     {
00912         return false;
00913     }
00914 
00915     /*!
00916      Returns the title of the current type, this is to form
00917      the title of the object.
00918     */
00919     function title( $objectAttribute, $name = null )
00920     {
00921         return "";
00922     }
00923 
00924     /*!
00925      \return true if the datatype can be indexed
00926     */
00927     function isIndexable()
00928     {
00929         return false;
00930     }
00931 
00932     /*!
00933      \return true if the datatype requires validation during add to basket procedure
00934     */
00935     function isAddToBasketValidationRequired()
00936     {
00937         return false;
00938     }
00939     /*!
00940      Validates the input for an object attribute during add to basket process
00941      and returns a validation state as defined in eZInputValidator.
00942      \note Default implementation does nothing and returns accepted.
00943     */
00944     function validateAddToBasket( $objectAttribute, $data, &$errors )
00945     {
00946         return eZInputValidator::STATE_ACCEPTED;
00947     }
00948 
00949     /*!
00950      Queries the datatype if the attribute containing this datatype can be
00951      removed from the class. This can be used by datatypes to ensure
00952      that very important datatypes that could cause system malfunction is
00953      not removed.
00954      The datatype will only need to reimplemented this if it wants to
00955      do some checking, the default returns \c true.
00956 
00957      \return \c true if the class attribute can be removed or \c false.
00958      \sa classAttributeRemovableInformation()
00959      \note The default code will call classAttributeRemovableInformation with
00960           $includeAll set to \c false, if it returns false or an empty \c 'list'
00961           it will return \c true.
00962     */
00963     function isClassAttributeRemovable( $classAttribute )
00964     {
00965         $info = $this->classAttributeRemovableInformation( $classAttribute, false );
00966         return ( $info === false or count( $info['list'] ) == 0 );
00967     }
00968 
00969     /*!
00970      If the call to isClassAttributeRemovable() returns \c false then this
00971      can be called to figure out why it cannot be removed, e.g to give
00972      information to the user.
00973      \return An array structure with information, or \c false if no info is available
00974              - text - Plain text explaining why it can't be removed
00975              - list - A list of reasons with details on why it can be removed
00976                       - identifier - The identifier of the reason (optional)
00977                       - text - Plain text explaning the reason
00978      \param $includeAll Controls whether the returned information will contain all
00979                         sources for not being to remove or just the first that it finds.
00980     */
00981     function classAttributeRemovableInformation( $classAttribute, $includeAll = true )
00982     {
00983         return false;
00984     }
00985 
00986     /*!
00987      \return true if the datatype can be used as an information collector
00988     */
00989     function isInformationCollector()
00990     {
00991         return false;
00992     }
00993 
00994     /*!
00995      \return the sort key for the datatype. This is used for sorting on attribute level.
00996     */
00997     function sortKey( $objectAttribute )
00998     {
00999         return "";
01000     }
01001 
01002     /*!
01003      \returns the type of the sort key int|string
01004       False is returned if sorting is not supported
01005     */
01006     function sortKeyType()
01007     {
01008         return false;
01009     }
01010 
01011     function customSorting()
01012     {
01013         return false;
01014     }
01015 
01016     function customSortingSQL( $params )
01017     {
01018         return false;
01019     }
01020 
01021     /*!
01022      \return the text which should be indexed in the search engine. An associative array can
01023       be returned to enable searching in specific parts of the data. E.g. array( 'first_column' => "foo",
01024      'second_column' => "bar" );
01025     */
01026     function metaData( $contentObjectAttribute )
01027     {
01028         return '';
01029     }
01030     /*!
01031      \return string representation of an contentobjectattribute data for simplified export
01032      */
01033     function toString( $objectAttribute )
01034     {
01035         return '';
01036     }
01037     function fromString( $objectAttribute, $string )
01038     {
01039     }
01040 
01041     /*!
01042      Can be called to figure out if a datatype has certain special templates that it relies on.
01043      This can for instance be used to figure out which override templates to include in a package.
01044      \return An array with template files that this datatype relies on.
01045              Each element can be one of the following types:
01046              - string - The filepath of the template
01047              - array - Advanced matching criteria, element 0 determines the type:
01048                - 'regexp' - A regular expression, element 1 is the regexp string (PREG)
01049              If \c false is returned it means there are no relations to any templates.
01050      \note All matching is done relative from templates directory in the given design.
01051      \note The templates that are found in content/datatype/* should not be included.
01052     */
01053     function templateList()
01054     {
01055         return false;
01056     }
01057 
01058     /*!
01059      Adds the necessary dom structure to the attribute parameters.
01060      \note The default is to add unsupported='true' to the attribute node,
01061            meaning that the datatype does not support serializing.
01062     */
01063     function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
01064     {
01065         if ( !$this->Attributes['properties']['serialize_supported'] )
01066             $attributeNode->setAttribute( 'unsupported', 'true' );
01067     }
01068 
01069     /*!
01070      Extracts values from the attribute parameters and sets it in the class attribute.
01071      \note This function is called after the attribute has been stored and a second store is
01072            called after this function is done.
01073     */
01074     function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
01075     {
01076     }
01077 
01078     /*!
01079      \param package
01080      \param content attribute
01081 
01082      \return a DOM representation of the content object attribute
01083     */
01084     function serializeContentObjectAttribute( $package, $objectAttribute )
01085     {
01086         $dom = new DOMDocument( '1.0', 'utf-8' );
01087 
01088         $node = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:attribute' );
01089 
01090         $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:id', $objectAttribute->attribute( 'id' ) );
01091         $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:identifier', $objectAttribute->contentClassAttributeIdentifier() );
01092         $node->setAttribute( 'name', $objectAttribute->contentClassAttributeName() );
01093         $node->setAttribute( 'type', $this->isA() );
01094 
01095         if ( $this->Attributes["properties"]['object_serialize_map'] )
01096         {
01097             $map = $this->Attributes["properties"]['object_serialize_map'];
01098             foreach ( $map as $attributeName => $xmlName )
01099             {
01100                 if ( $objectAttribute->hasAttribute( $attributeName ) )
01101                 {
01102                     $value = $objectAttribute->attribute( $attributeName );
01103                     unset( $attributeNode );
01104                     $attributeNode = $dom->createElement( $xmlName );
01105                     $attributeNode->appendChild( $dom->createTextNode( (string)$value ) );
01106                     $node->appendChild( $attributeNode );
01107                 }
01108                 else
01109                 {
01110                     eZDebug::writeError( "The attribute '$attributeName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ),
01111                                          'eZDataType::serializeContentObjectAttribute' );
01112                 }
01113             }
01114         }
01115         else
01116         {
01117             $dataIntNode = $dom->createElement( 'data-int' );
01118             $dataIntNode->appendChild( $dom->createTextNode( (string)$objectAttribute->attribute( 'data_int' ) ) );
01119             $node->appendChild( $dataIntNode );
01120             $dataFloatNode = $dom->createElement( 'data-float' );
01121             $dataFloatNode->appendChild( $dom->createTextNode( (string)$objectAttribute->attribute( 'data_float' ) ) );
01122             $node->appendChild( $dataFloatNode );
01123             $dataTextNode = $dom->createElement( 'data-text' );
01124             $dataTextNode->appendChild( $dom->createTextNode( $objectAttribute->attribute( 'data_text' ) ) );
01125             $node->appendChild( $dataTextNode );
01126         }
01127         return $node;
01128     }
01129 
01130     /*!
01131      Unserailize contentobject attribute
01132 
01133      \param package
01134      \param contentobject attribute object
01135      \param ezdomnode object
01136     */
01137     function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
01138     {
01139         if ( $this->Attributes["properties"]['object_serialize_map'] )
01140         {
01141             $map = $this->Attributes["properties"]['object_serialize_map'];
01142             foreach ( $map as $attributeName => $xmlName )
01143             {
01144                 if ( $objectAttribute->hasAttribute( $attributeName ) )
01145                 {
01146                     $elements = $attributeNode->getElementsByTagName( $xmlName );
01147                     if ( $elements->length !== 0 )
01148                     {
01149                         $value = $elements->item( 0 )->textContent;
01150                         $objectAttribute->setAttribute( $attributeName, $value );
01151                     }
01152                     else
01153                     {
01154                         eZDebug::writeError( "The xml element '$xmlName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ),
01155                                              'eZDataType::unserializeContentObjectAttribute' );
01156                     }
01157                 }
01158                 else
01159                 {
01160                     eZDebug::writeError( "The attribute '$attributeName' does not exist for contentobject attribute " . $objectAttribute->attribute( 'id' ),
01161                                          'eZDataType::unserializeContentObjectAttribute' );
01162                 }
01163             }
01164         }
01165         else
01166         {
01167             $objectAttribute->setAttribute( 'data_int', (int)$attributeNode->getElementsByTagName( 'data-int' )->item( 0 )->textContent );
01168             $objectAttribute->setAttribute( 'data_float', (float)$attributeNode->getElementsByTagName( 'data-float' )->item( 0 )->textContent );
01169             $objectAttribute->setAttribute( 'data_text', $attributeNode->getElementsByTagName( 'data-text' )->item( 0 )->textContent );
01170         }
01171     }
01172 
01173     /*
01174         Post unserialize. Called after all related objects are created.
01175         \return true means that attribute has been modified and should be stored
01176     */
01177     function postUnserializeContentObjectAttribute( $package, $objectAttribute )
01178     {
01179         return false;
01180     }
01181 
01182     static function allowedTypes()
01183     {
01184         $allowedTypes =& $GLOBALS["eZDataTypeAllowedTypes"];
01185         if ( !is_array( $allowedTypes ) )
01186         {
01187             $contentINI = eZINI::instance( 'content.ini' );
01188             $dataTypes = $contentINI->variable( 'DataTypeSettings', 'AvailableDataTypes' );
01189             $allowedTypes = array_unique( $dataTypes );
01190         }
01191         return $allowedTypes;
01192     }
01193 
01194     static function loadAndRegisterAllTypes()
01195     {
01196         $allowedTypes = eZDataType::allowedTypes();
01197         foreach( $allowedTypes as $type )
01198         {
01199             eZDataType::loadAndRegisterType( $type );
01200         }
01201     }
01202 
01203     static function loadAndRegisterType( $type )
01204     {
01205         $types =& $GLOBALS["eZDataTypes"];
01206         if ( isset( $types[$type] ) )
01207         {
01208             return false;
01209         }
01210 
01211         //include_once( 'lib/ezutils/classes/ezextension.php' );
01212         $baseDirectory = eZExtension::baseDirectory();
01213         $contentINI = eZINI::instance( 'content.ini' );
01214 
01215         $extensionDirectories = $contentINI->variable( 'DataTypeSettings', 'ExtensionDirectories' );
01216         $extensionDirectories = array_unique( $extensionDirectories );
01217         $repositoryDirectories = $contentINI->variable( 'DataTypeSettings', 'RepositoryDirectories' );
01218         $triedDirectories = $repositoryDirectories;
01219 
01220         foreach ( $extensionDirectories as $extensionDirectory )
01221         {
01222             $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/datatypes';
01223             $triedDirectories[] = $extensionPath;
01224             if ( file_exists( $extensionPath ) )
01225             {
01226                 $repositoryDirectories[] = $extensionPath;
01227             }
01228             else
01229             {
01230                 eZDebug::writeWarning( "Extension '$extensionDirectory' does not have the subdirectory 'datatypes'\n" .
01231                                        "Looked for directory '" . $extensionPath . "'\n" .
01232                                        "Cannot look for datatype '$type' in this extension." );
01233             }
01234         }
01235         $foundEventType = false;
01236         $repositoryDirectories = array_unique( $repositoryDirectories );
01237         foreach ( $repositoryDirectories as $repositoryDirectory )
01238         {
01239             $includeFile = "$repositoryDirectory/$type/" . $type . "type.php";
01240             if ( file_exists( $includeFile ) )
01241             {
01242                 $foundEventType = true;
01243                 break;
01244             }
01245         }
01246         if ( !$foundEventType )
01247         {
01248             eZDebug::writeError( "Datatype not found: '$type', searched in these directories: " . implode( ', ', $triedDirectories ), "eZDataType::loadAndRegisterType" );
01249             return false;
01250         }
01251         include_once( $includeFile );
01252         return true;
01253     }
01254 
01255     /*!
01256      Removes objects with given ID from the relations list
01257      \note Default implementation does nothing.
01258     */
01259     function removeRelatedObjectItem( $contentObjectAttribute, $objectID )
01260     {
01261     }
01262 
01263     /*!
01264     Fixes objects with given ID in the relations list according to what is done with object
01265      \note Default implementation does nothing.
01266     */
01267     function fixRelatedObjectItem( $contentObjectAttribute, $objectID, $mode )
01268     {
01269     }
01270     /**
01271      * Create empty content object attribute DOM node.
01272      *
01273      * The result is intended to be used in a datatype's
01274      * serializeContentObjectAttribute() method.
01275      *
01276      * \return "Empty" DOM node
01277      */
01278     function createContentObjectAttributeDOMNode( $objectAttribute )
01279     {
01280         $dom = new DOMDocument( '1.0', 'utf-8' );
01281 
01282         $node = $dom->createElementNS( 'http://ez.no/object/', 'ezobject:attribute' );
01283 
01284         $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:id', $objectAttribute->attribute( 'id' ) );
01285         $node->setAttributeNS( 'http://ez.no/ezobject', 'ezremote:identifier', $objectAttribute->contentClassAttributeIdentifier() );
01286         $node->setAttribute( 'name', $objectAttribute->contentClassAttributeName() );
01287         $node->setAttribute( 'type', $this->isA() );
01288 
01289         return $node;
01290     }
01291 
01292     /*!
01293       Method used by content diff system to retrieve changes in attributes.
01294       This method implements the default behaviour, which is to show old and
01295       new version values of the object.
01296     */
01297     function diff( $old, $new, $options = false )
01298     {
01299         //include_once( 'lib/ezdiff/classes/ezdiff.php' );
01300         $diff = new eZDiff();
01301         $diff->setDiffEngineType( $diff->engineType( 'container' ) );
01302         $diff->initDiffEngine();
01303         $diffObject = $diff->diff( $old, $new );
01304         return $diffObject;
01305     }
01306 
01307     /*!
01308       Returns dba-data file name of the specific datatype.
01309       This one is the default dba-data file name for all datatypes
01310     */
01311     function getDBAFileName()
01312     {
01313         return 'share/db_data.dba';
01314     }
01315 
01316     /*!
01317       Returns dba-data file path (relative to the system root folder) for the specific datatype.
01318     */
01319     function getDBAFilePath( $checkExtensions = true )
01320     {
01321          $fileName = 'kernel/classes/datatypes/' . $this->DataTypeString . '/' . $this->getDBAFileName();
01322          if ( !file_exists( $fileName ) and $checkExtensions === true )
01323          {
01324              $fileName = $this->getDBAExtensionFilePath();
01325          }
01326          return $fileName;
01327     }
01328 
01329     /*!
01330       Returns dba-data file extension path (relative to the system root folder) for the specific datatype.
01331       \return the first path that is found for the datatype. If not found, it will return false.
01332     */
01333     function getDBAExtensionFilePath()
01334     {
01335         include_once( 'lib/ezutils/classes/ezextension.php' );
01336 
01337         $activeExtensions = eZExtension::activeExtensions();
01338         $dataTypeString = $this->DataTypeString;
01339         $dbaFileName = $this->getDBAFileName();
01340         $fileName = false;
01341         foreach ( $activeExtensions as $activeExtension )
01342         {
01343             $extesionFileName = eZExtension::baseDirectory() . '/' . $activeExtension .
01344                                 '/datatypes/' . $dataTypeString . '/' . $dbaFileName;
01345             if ( file_exists( $extesionFileName ) )
01346             {
01347                 $fileName = $extesionFileName;
01348                 break;
01349             }
01350         }
01351         return $fileName;
01352     }
01353 
01354     /*!
01355       Used by setup-wizard to update database data using per datatype dba file
01356       which is usually placed in share subfolder of the datatype and (share/db_data.dba)
01357       Any reimplementation of this method must return true if import is succesfully done,
01358       otherwise false.
01359     */
01360     function importDBDataFromDBAFile( $dbaFilePath = false )
01361     {
01362         // If no file path is passed then get the common dba-data file name for the datatype
01363         if ( $dbaFilePath === false )
01364             $dbaFilePath = $this->getDBAFilePath();
01365 
01366         $fileExist = true;
01367         if ( !file_exists( $dbaFilePath ) )
01368         {
01369             $fileExist = false;
01370         }
01371         $result = true;
01372         if ( $fileExist === true )
01373         {
01374             //include_once( 'lib/ezdbschema/classes/ezdbschema.php' );
01375             $dataArray = eZDbSchema::read( $dbaFilePath, true );
01376             if ( is_array( $dataArray ) and count( $dataArray ) > 0 )
01377             {
01378                 $db = eZDB::instance();
01379                 $dataArray['type'] = strtolower( $db->databaseName() );
01380                 $dataArray['instance'] =& $db;
01381                 $dbSchema = eZDbSchema::instance( $dataArray );
01382 
01383                 $result = false;
01384                 if ( $dbSchema )
01385                 {
01386                     // Before adding the schema, make sure that the tables are empty.
01387                     if ( $this->cleanDBDataBeforeImport() )
01388                     {
01389                         // This will insert the data and
01390                         // run any sequence value correction SQL if required
01391                         $result = $dbSchema->insertSchema( array( 'schema' => false,
01392                                                                   'data' => true ) );
01393                     }
01394                 }
01395             }
01396         }
01397         else
01398         {
01399             $result = false;
01400         }
01401         return $result;
01402     }
01403 
01404     /*!
01405       \private
01406       Used by updateDBDataByDBAFile() method
01407       Must return true if successfull, or false otherwise.
01408     */
01409     function cleanDBDataBeforeImport()
01410     {
01411         return true;
01412     }
01413 
01414     /// \privatesection
01415     /// The datatype string ID, used for uniquely identifying a datatype
01416     public $DataTypeString;
01417     /// The descriptive name of the datatype, usually used for displaying to the user
01418     public $Name;
01419 }
01420 
01421 ?>