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 require_once( 'kernel/classes/ezdatatype.php' );
00039 require_once( 'kernel/classes/ezproductcategory.php' );
00040
00041 define( "EZ_DATATYPESTRING_PRODUCTCATEGORY", "ezproductcategory" );
00042
00043 class eZProductCategoryType extends eZDataType
00044 {
00045 function eZProductCategoryType()
00046 {
00047 $this->eZDataType( EZ_DATATYPESTRING_PRODUCTCATEGORY, ezi18n( 'kernel/classes/datatypes', "Product category", 'Datatype name' ),
00048 array( 'serialize_supported' => true,
00049 'object_serialize_map' => array( 'data_int' => 'value' ) ) );
00050 }
00051
00052
00053
00054
00055 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00056 {
00057 if ( $currentVersion != false )
00058 {
00059 $dataInt = $originalContentObjectAttribute->attribute( "data_int" );
00060 $contentObjectAttribute->setAttribute( "data_int", $dataInt );
00061 }
00062 else
00063 {
00064 $default = 0;
00065 $contentObjectAttribute->setAttribute( "data_int", $default );
00066 }
00067 }
00068
00069
00070
00071
00072 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00073 {
00074 if ( !$contentObjectAttribute->validateIsRequired() )
00075 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00076
00077 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ) )
00078 {
00079 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
00080
00081 if ( is_numeric( $data ) )
00082 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00083 }
00084
00085 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00086 'Input required.' ) );
00087 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00088 }
00089
00090
00091
00092
00093 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00094 {
00095 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ))
00096 {
00097 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
00098 if ( !is_numeric( $data ) )
00099 $data = 0;
00100 }
00101 else
00102 {
00103 $data = 0;
00104 }
00105
00106 $contentObjectAttribute->setAttribute( "data_int", $data );
00107 return true;
00108 }
00109
00110
00111
00112
00113
00114 function fetchCollectionAttributeHTTPInput( &$collection, &$collectionAttribute, &$http, $base, &$contentObjectAttribute )
00115 {
00116 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ))
00117 {
00118 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
00119 if ( !is_numeric( $data ) )
00120 $data = 0;
00121 }
00122 else
00123 {
00124 $data = 0;
00125 }
00126
00127 $collectionAttribute->setAttribute( 'data_int', $data );
00128 return true;
00129 }
00130
00131 function metaData( &$contentObjectAttribute )
00132 {
00133 return $contentObjectAttribute->attribute( "data_int" );
00134 }
00135
00136
00137
00138
00139 function isIndexable()
00140 {
00141 return true;
00142 }
00143
00144
00145
00146
00147 function isInformationCollector()
00148 {
00149 return true;
00150 }
00151
00152
00153
00154
00155 function sortKey( &$contentObjectAttribute )
00156 {
00157 return $contentObjectAttribute->attribute( 'data_int' );
00158 }
00159
00160
00161
00162
00163 function sortKeyType()
00164 {
00165 return 'int';
00166 }
00167
00168
00169
00170
00171 function &objectAttributeContent( &$contentObjectAttribute )
00172 {
00173 require_once( 'kernel/classes/ezproductcategory.php' );
00174 $category = eZProductCategory::fetch( $contentObjectAttribute->attribute( 'data_int' ) );
00175 return $category;
00176 }
00177
00178
00179
00180
00181 function hasObjectAttributeContent( &$contentObjectAttribute )
00182 {
00183 $productCategory = $this->objectAttributeContent( $contentObjectAttribute );
00184 return is_object( $productCategory );
00185 }
00186
00187 function toString( $contentObjectAttribute )
00188 {
00189 $category = $contentObjectAttribute->attribute( 'content' );
00190 if ( $category )
00191 {
00192 return implode( '|', array( $category->attribute( 'name' ), $category->attribute( 'id' ) ) );
00193 }
00194 return '';
00195 }
00196
00197
00198 function fromString( &$contentObjectAttribute, $string )
00199 {
00200 if ( $string == '' )
00201 return true;
00202 $categoryData = explode( '|', $string );
00203
00204 if ( isset ( $categoryData[1] ) )
00205 {
00206 $category = eZProductCategory::fetch( $categoryData[1] );
00207 if ( $category )
00208 {
00209 $contentObjectAttribute->setAttribute( 'data_int', $category->attribute( 'id' ) );
00210 return true;
00211 }
00212 }
00213
00214 if ( isset ( $categoryData[1] ) )
00215 {
00216 $category = eZProductCategory::fetchByName( $categoryData[0] );
00217 if ( $category )
00218 {
00219 $contentObjectAttribute->setAttribute( 'data_int', $category->attribute( 'id' ) );
00220 return true;
00221 }
00222 }
00223 return false;
00224 }
00225
00226
00227
00228
00229 function title( &$contentObjectAttribute )
00230 {
00231 $categoryID = $contentObjectAttribute->attribute( "data_int" );
00232 $category = $categoryID > 0 ? eZProductCategory::fetch( $categoryID ) : false;
00233 return is_object( $category ) ? $category->attribute( 'name' ) : '';
00234 }
00235
00236
00237
00238
00239 function diff( $old, $new, $options = null )
00240 {
00241 return null;
00242 }
00243 }
00244
00245 eZDataType::register( EZ_DATATYPESTRING_PRODUCTCATEGORY, "ezproductcategorytype" );
00246
00247 ?>