00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( "kernel/classes/ezdatatype.php" );
00039
00040 define( "EZ_DATATYPESTRING_TEXT", "eztext" );
00041 define( 'EZ_DATATYPESTRING_TEXT_COLS_FIELD', 'data_int1' );
00042 define( 'EZ_DATATYPESTRING_TEXT_COLS_VARIABLE', '_eztext_cols_' );
00043
00044 class eZTextType extends eZDataType
00045 {
00046 function eZTextType()
00047 {
00048 $this->eZDataType( EZ_DATATYPESTRING_TEXT, ezi18n( 'kernel/classes/datatypes', "Text block", 'Datatype name' ),
00049 array( 'serialize_supported' => true,
00050 'object_serialize_map' => array( 'data_text' => 'text' ) ) );
00051 }
00052
00053
00054
00055
00056 function initializeClassAttribute( &$classAttribute )
00057 {
00058 if ( $classAttribute->attribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD ) == null )
00059 $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD, 10 );
00060 $classAttribute->store();
00061 }
00062
00063
00064
00065
00066 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00067 {
00068 if ( $currentVersion != false )
00069 {
00070 $dataText = $originalContentObjectAttribute->attribute( "data_text" );
00071 $contentObjectAttribute->setAttribute( "data_text", $dataText );
00072 }
00073 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
00074 if ( $contentClassAttribute->attribute( "data_int1" ) == 0 )
00075 {
00076 $contentClassAttribute->setAttribute( "data_int1", 10 );
00077 $contentClassAttribute->store();
00078 }
00079 }
00080
00081
00082
00083
00084
00085 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00086 {
00087 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00088 {
00089 $data = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00090 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00091
00092 if ( $data == "" )
00093 {
00094 if ( !$classAttribute->attribute( 'is_information_collector' ) and
00095 $contentObjectAttribute->validateIsRequired() )
00096 {
00097 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00098 'Input required.' ) );
00099 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00100 }
00101 }
00102 }
00103 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00104 }
00105
00106
00107
00108 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00109 {
00110 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00111 {
00112 $data = $http->postVariable( $base . '_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00113 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00114
00115 if ( $data == "" )
00116 {
00117 if ( $contentObjectAttribute->validateIsRequired() )
00118 {
00119 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00120 'Input required.' ) );
00121 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00122 }
00123 }
00124 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00125 }
00126 else
00127 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00128 }
00129
00130
00131
00132
00133 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00134 {
00135 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00136 {
00137 $data = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00138 $contentObjectAttribute->setAttribute( "data_text", $data );
00139 return true;
00140 }
00141 return false;
00142 }
00143
00144
00145
00146
00147 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
00148 {
00149 if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
00150 {
00151 $dataText = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
00152 $collectionAttribute->setAttribute( 'data_text', $dataText );
00153 return true;
00154 }
00155 return false;
00156 }
00157
00158
00159
00160
00161 function storeObjectAttribute( &$attribute )
00162 {
00163 }
00164
00165
00166
00167
00168
00169 function isSimpleStringInsertionSupported()
00170 {
00171 return true;
00172 }
00173
00174
00175
00176
00177
00178 function insertSimpleString( &$object, $objectVersion, $objectLanguage,
00179 &$objectAttribute, $string,
00180 &$result )
00181 {
00182 $result = array( 'errors' => array(),
00183 'require_storage' => true );
00184 $objectAttribute->setContent( $string );
00185 $objectAttribute->setAttribute( 'data_text', $string );
00186 return true;
00187 }
00188
00189
00190
00191
00192 function &objectAttributeContent( &$contentObjectAttribute )
00193 {
00194 return $contentObjectAttribute->attribute( "data_text" );
00195 }
00196
00197 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00198 {
00199 $column = $base .EZ_DATATYPESTRING_TEXT_COLS_VARIABLE . $classAttribute->attribute( 'id' );
00200 if ( $http->hasPostVariable( $column ) )
00201 {
00202 $columnValue = $http->postVariable( $column );
00203 $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD, $columnValue );
00204 return true;
00205 }
00206 return false;
00207 }
00208
00209
00210
00211
00212 function metaData( $contentObjectAttribute )
00213 {
00214 return $contentObjectAttribute->attribute( "data_text" );
00215 }
00216
00217
00218
00219
00220
00221 function toString( $contentObjectAttribute )
00222 {
00223 return $contentObjectAttribute->attribute( 'data_text' );
00224 }
00225
00226 function fromString( &$contentObjectAttribute, $string )
00227 {
00228 return $contentObjectAttribute->setAttribute( 'data_text', $string );
00229 }
00230
00231 function hasObjectAttributeContent( &$contentObjectAttribute )
00232 {
00233 return trim( $contentObjectAttribute->attribute( 'data_text' ) ) != '';
00234 }
00235
00236
00237
00238
00239 function title( &$data_instance )
00240 {
00241 return $data_instance->attribute( "data_text" );
00242 }
00243
00244
00245
00246
00247 function isIndexable()
00248 {
00249 return true;
00250 }
00251
00252
00253
00254
00255 function isInformationCollector()
00256 {
00257 return true;
00258 }
00259
00260
00261
00262
00263 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00264 {
00265 $textColumns = $classAttribute->attribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD );
00266 $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'text-column-count', $textColumns ) );
00267 }
00268
00269
00270
00271
00272 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00273 {
00274 $textColumns = $attributeParametersNode->elementTextContentByName( 'text-column-count' );
00275 $classAttribute->setAttribute( EZ_DATATYPESTRING_TEXT_COLS_FIELD, $textColumns );
00276 }
00277
00278
00279
00280
00281 function diff( $old, $new, $options = false )
00282 {
00283 include_once( 'lib/ezdiff/classes/ezdiff.php' );
00284 $diff = new eZDiff();
00285 $diff->setDiffEngineType( $diff->engineType( 'text' ) );
00286 $diff->initDiffEngine();
00287 $diffObject = $diff->diff( $old->content(), $new->content() );
00288 return $diffObject;
00289 }
00290
00291 }
00292
00293 eZDataType::register( EZ_DATATYPESTRING_TEXT, "eztexttype" );
00294
00295 ?>