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_BOOLEAN", "ezboolean" );
00041
00042 class eZBooleanType extends eZDataType
00043 {
00044 function eZBooleanType()
00045 {
00046 $this->eZDataType( EZ_DATATYPESTRING_BOOLEAN, ezi18n( 'kernel/classes/datatypes', "Checkbox", 'Datatype name' ),
00047 array( 'serialize_supported' => true,
00048 'object_serialize_map' => array( 'data_int' => 'value' ) ) );
00049 }
00050
00051
00052
00053
00054 function storeObjectAttribute( &$attribute )
00055 {
00056 }
00057
00058
00059
00060
00061
00062 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00063 {
00064 if ( $currentVersion != false )
00065 {
00066 $dataInt = $originalContentObjectAttribute->attribute( "data_int" );
00067 $contentObjectAttribute->setAttribute( "data_int", $dataInt );
00068 }
00069 else
00070 {
00071 $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
00072 $default = $contentClassAttribute->attribute( "data_int3" );
00073 $contentObjectAttribute->setAttribute( "data_int", $default );
00074 }
00075 }
00076
00077
00078
00079
00080 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00081 {
00082 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00083 if ( $contentObjectAttribute->validateIsRequired() and
00084 !$classAttribute->attribute( 'is_information_collector' ) )
00085 {
00086 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ) )
00087 {
00088 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
00089 if ( isset( $data ) )
00090 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00091 }
00092 else
00093 {
00094 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00095 'Input required.' ) );
00096 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00097 }
00098 }
00099 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00100 }
00101
00102
00103
00104 function validateCollectionAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00105 {
00106 if ( $contentObjectAttribute->validateIsRequired() )
00107 {
00108 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ) )
00109 {
00110 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
00111 if ( isset( $data ) )
00112 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00113 }
00114 else
00115 {
00116 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00117 'Input required.' ) );
00118 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00119 }
00120 }
00121 }
00122
00123
00124
00125
00126 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00127 {
00128 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ))
00129 {
00130 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
00131 if ( isset( $data ) && $data !== '0' && $data !== 'false' )
00132 $data = 1;
00133 else
00134 $data = 0;
00135 }
00136 else
00137 {
00138 $data = 0;
00139 }
00140 $contentObjectAttribute->setAttribute( "data_int", $data );
00141 return true;
00142 }
00143
00144
00145
00146
00147
00148 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
00149 {
00150 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ))
00151 {
00152 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
00153 if ( isset( $data ) && $data !== '0' && $data !== 'false' )
00154 $data = 1;
00155 else
00156 $data = 0;
00157 }
00158 else
00159 {
00160 $data = 0;
00161 }
00162 $collectionAttribute->setAttribute( 'data_int', $data );
00163 return true;
00164 }
00165
00166 function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
00167 {
00168 if ( $http->hasPostVariable( $base . '_ezboolean_default_value_' . $classAttribute->attribute( 'id' ) . '_exists' ) )
00169 {
00170 if ( $http->hasPostVariable( $base . "_ezboolean_default_value_" . $classAttribute->attribute( "id" ) ))
00171 {
00172 $data = $http->postVariable( $base . "_ezboolean_default_value_" . $classAttribute->attribute( "id" ) );
00173 if ( isset( $data ) )
00174 $data = 1;
00175 $classAttribute->setAttribute( "data_int3", $data );
00176 }
00177 else
00178 {
00179 $classAttribute->setAttribute( "data_int3", 0 );
00180 }
00181 }
00182 return true;
00183 }
00184
00185 function metaData( &$contentObjectAttribute )
00186 {
00187 return $contentObjectAttribute->attribute( "data_int" );
00188 }
00189
00190
00191
00192
00193 function toString( $contentObjectAttribute )
00194 {
00195 return $contentObjectAttribute->attribute( 'data_int' );
00196 }
00197
00198 function fromString( &$contentObjectAttribute, $string )
00199 {
00200 return $contentObjectAttribute->setAttribute( 'data_int', $string );
00201 }
00202
00203
00204
00205
00206 function isIndexable()
00207 {
00208 return true;
00209 }
00210
00211
00212
00213
00214 function isInformationCollector()
00215 {
00216 return true;
00217 }
00218
00219
00220
00221
00222 function sortKey( &$contentObjectAttribute )
00223 {
00224 return $contentObjectAttribute->attribute( 'data_int' );
00225 }
00226
00227
00228
00229
00230 function sortKeyType()
00231 {
00232 return 'int';
00233 }
00234
00235
00236
00237
00238 function &objectAttributeContent( &$contentObjectAttribute )
00239 {
00240 return $contentObjectAttribute->attribute( "data_int" );
00241 }
00242
00243
00244
00245
00246 function title( &$contentObjectAttribute )
00247 {
00248 return $contentObjectAttribute->attribute( "data_int" );
00249 }
00250
00251 function hasObjectAttributeContent( &$contentObjectAttribute )
00252 {
00253 return true;
00254 }
00255
00256
00257
00258
00259 function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00260 {
00261 $defaultValue = $classAttribute->attribute( 'data_int3' );
00262 $attributeParametersNode->appendChild( eZDOMDocument::createElementNode( 'default-value',
00263 array( 'is-set' => $defaultValue ? 'true' : 'false' ) ) );
00264 }
00265
00266
00267
00268
00269 function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
00270 {
00271 $defaultValueNode = $attributeParametersNode->elementByName( 'default-value' );
00272 $defaultValue = strtolower( $defaultValueNode->attributeValue( 'is-set' ) ) == 'true' ? 1 : 0;
00273 $classAttribute->setAttribute( 'data_int3', $defaultValue );
00274 }
00275 }
00276
00277 eZDataType::register( EZ_DATATYPESTRING_BOOLEAN, "ezbooleantype" );
00278
00279 ?>