|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZProductCategoryType class 00004 // 00005 // Created on: <19-Feb-2006 14:08:26 vs> 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 /*! 00032 \class eZProductCategoryType ezproductcategorytype.php 00033 \ingroup eZDatatype 00034 \brief Stores product category. 00035 00036 */ 00037 00038 require_once( 'kernel/classes/ezdatatype.php' ); 00039 require_once( 'kernel/classes/ezproductcategory.php' ); 00040 00041 class eZProductCategoryType extends eZDataType 00042 { 00043 const DATA_TYPE_STRING = "ezproductcategory"; 00044 00045 function eZProductCategoryType() 00046 { 00047 $this->eZDataType( self::DATA_TYPE_STRING, 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 Sets the default value. 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 Validates the http post var. 00071 */ 00072 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00073 { 00074 if ( !$contentObjectAttribute->validateIsRequired() ) 00075 return eZInputValidator::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 eZInputValidator::STATE_ACCEPTED; 00083 } 00084 00085 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00086 'Input required.' ) ); 00087 return eZInputValidator::STATE_INVALID; 00088 } 00089 00090 /*! 00091 Fetches the http post var and stores it in the data instance. 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 \reimp 00112 Fetches the http post variable for collected information 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 \reimp 00138 */ 00139 function isIndexable() 00140 { 00141 return true; 00142 } 00143 00144 /*! 00145 \reimp 00146 */ 00147 function isInformationCollector() 00148 { 00149 return true; 00150 } 00151 00152 /*! 00153 \reimp 00154 */ 00155 function sortKey( $contentObjectAttribute ) 00156 { 00157 return $contentObjectAttribute->attribute( 'data_int' ); 00158 } 00159 00160 /*! 00161 \reimp 00162 */ 00163 function sortKeyType() 00164 { 00165 return 'int'; 00166 } 00167 00168 /*! 00169 Returns the content. 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 \reimp 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 Returns the integer value. 00228 */ 00229 function title( $contentObjectAttribute, $name = null ) 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 \reimp 00238 */ 00239 function diff( $old, $new, $options = null ) 00240 { 00241 return null; 00242 } 00243 } 00244 00245 eZDataType::register( eZProductCategoryType::DATA_TYPE_STRING, "eZProductCategoryType" ); 00246 00247 ?>