|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZBooleanType class 00004 // 00005 // Created on: <27-Jun-2002 18:24:54 sp> 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 eZBooleanType ezbooleantype.php 00033 \ingroup eZDatatype 00034 \brief Stores a boolean value 00035 00036 */ 00037 00038 //include_once( "kernel/classes/ezdatatype.php" ); 00039 00040 class eZBooleanType extends eZDataType 00041 { 00042 const DATA_TYPE_STRING = "ezboolean"; 00043 00044 function eZBooleanType() 00045 { 00046 $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', "Checkbox", 'Datatype name' ), 00047 array( 'serialize_supported' => true, 00048 'object_serialize_map' => array( 'data_int' => 'value' ) ) ); 00049 } 00050 00051 /*! 00052 Store content 00053 */ 00054 function storeObjectAttribute( $attribute ) 00055 { 00056 } 00057 00058 00059 /*! 00060 Sets the default value. 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 Validates the http post var boolean input. 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 eZInputValidator::STATE_ACCEPTED; 00091 } 00092 else 00093 { 00094 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00095 'Input required.' ) ); 00096 return eZInputValidator::STATE_INVALID; 00097 } 00098 } 00099 return eZInputValidator::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 eZInputValidator::STATE_ACCEPTED; 00113 } 00114 else 00115 { 00116 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 00117 'Input required.' ) ); 00118 return eZInputValidator::STATE_INVALID; 00119 } 00120 } 00121 } 00122 00123 /*! 00124 Fetches the http post var boolean input and stores it in the data instance. 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 \reimp 00146 Fetches the http post variables for collected information 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 \return string representation of an contentobjectattribute data for simplified export 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 \reimp 00205 */ 00206 function isIndexable() 00207 { 00208 return true; 00209 } 00210 00211 /*! 00212 \reimp 00213 */ 00214 function isInformationCollector() 00215 { 00216 return true; 00217 } 00218 00219 /*! 00220 \reimp 00221 */ 00222 function sortKey( $contentObjectAttribute ) 00223 { 00224 return $contentObjectAttribute->attribute( 'data_int' ); 00225 } 00226 00227 /*! 00228 \reimp 00229 */ 00230 function sortKeyType() 00231 { 00232 return 'int'; 00233 } 00234 00235 /*! 00236 Returns the content. 00237 */ 00238 function objectAttributeContent( $contentObjectAttribute ) 00239 { 00240 return $contentObjectAttribute->attribute( "data_int" ); 00241 } 00242 00243 /*! 00244 Returns the integer value. 00245 */ 00246 function title( $contentObjectAttribute, $name = null ) 00247 { 00248 return $contentObjectAttribute->attribute( "data_int" ); 00249 } 00250 00251 function hasObjectAttributeContent( $contentObjectAttribute ) 00252 { 00253 return true; 00254 } 00255 00256 /*! 00257 \reimp 00258 */ 00259 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00260 { 00261 $defaultValue = $classAttribute->attribute( 'data_int3' ); 00262 $dom = $attributeParametersNode->ownerDocument; 00263 $defaultValueNode = $dom->createElement( 'default-value' ); 00264 $defaultValueNode->setAttribute( 'is-set', $defaultValue ? 'true' : 'false' ); 00265 $attributeParametersNode->appendChild( $defaultValueNode ); 00266 } 00267 00268 /*! 00269 \reimp 00270 */ 00271 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00272 { 00273 00274 $defaultValue = strtolower( $attributeParametersNode->getElementsByTagName( 'default-value' )->item( 0 )->getAttribute( 'is-set' ) ) == 'true'; 00275 $classAttribute->setAttribute( 'data_int3', $defaultValue ); 00276 } 00277 } 00278 00279 eZDataType::register( eZBooleanType::DATA_TYPE_STRING, "eZBooleanType" ); 00280 00281 ?>