Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezbooleantype.php
Go to the documentation of this file.
1 <?php
18 class eZBooleanType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezboolean";
21
22 public function __construct()
23 {
24 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Checkbox", 'Datatype name' ),
25 array( 'serialize_supported' => true,
26 'object_serialize_map' => array( 'data_int' => 'value' ) ) );
27 }
28
32 function storeObjectAttribute( $attribute )
33 {
34 }
35
36
40 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
41 {
42 if ( $currentVersion != false )
43 {
44 $dataInt = $originalContentObjectAttribute->attribute( "data_int" );
45 $contentObjectAttribute->setAttribute( "data_int", $dataInt );
46 }
47 else
48 {
49 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
50 $default = $contentClassAttribute->attribute( "data_int3" );
51 $contentObjectAttribute->setAttribute( "data_int", $default );
52 }
53 }
54
58 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
59 {
60 $classAttribute = $contentObjectAttribute->contentClassAttribute();
61 if ( $contentObjectAttribute->validateIsRequired() and
62 !$classAttribute->attribute( 'is_information_collector' ) )
63 {
64 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ) )
65 {
66 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
67 if ( isset( $data ) )
68 return eZInputValidator::STATE_ACCEPTED;
69 }
70 else
71 {
72 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
73 'Input required.' ) );
74 return eZInputValidator::STATE_INVALID;
75 }
76 }
77 return eZInputValidator::STATE_ACCEPTED;
78 }
79
80 function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute )
81 {
82 if ( $contentObjectAttribute->validateIsRequired() )
83 {
84 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ) )
85 {
86 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
87 if ( isset( $data ) )
88 return eZInputValidator::STATE_ACCEPTED;
89 }
90 else
91 {
92 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
93 'Input required.' ) );
94 return eZInputValidator::STATE_INVALID;
95 }
96 }
97 }
98
102 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
103 {
104 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ))
105 {
106 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
107 if ( isset( $data ) && $data !== '0' && $data !== 'false' )
108 $data = 1;
109 else
110 $data = 0;
111 }
112 else
113 {
114 /*
115 * Note: in other DataTypes, false is returned if the variable is not present.
116 * Since HTTP checkboxes are not present in the POST when they are not checked,
117 * eZBooleanType might behave a bit differently. See EZP-24630 for a concrete use case.
118 */
119 $data = 0;
120 }
121 $contentObjectAttribute->setAttribute( "data_int", $data );
122 return true;
123 }
124
128 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute )
129 {
130 if ( $http->hasPostVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) ))
131 {
132 $data = $http->postVariable( $base . "_data_boolean_" . $contentObjectAttribute->attribute( "id" ) );
133 if ( isset( $data ) && $data !== '0' && $data !== 'false' )
134 $data = 1;
135 else
136 $data = 0;
137 }
138 else
139 {
140 $data = 0;
141 }
142 $collectionAttribute->setAttribute( 'data_int', $data );
143 return true;
144 }
145
146 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
147 {
148 if ( $http->hasPostVariable( $base . '_ezboolean_default_value_' . $classAttribute->attribute( 'id' ) . '_exists' ) )
149 {
150 if ( $http->hasPostVariable( $base . "_ezboolean_default_value_" . $classAttribute->attribute( "id" ) ))
151 {
152 $data = $http->postVariable( $base . "_ezboolean_default_value_" . $classAttribute->attribute( "id" ) );
153 if ( isset( $data ) )
154 $data = 1;
155 $classAttribute->setAttribute( "data_int3", $data );
156 }
157 else
158 {
159 $classAttribute->setAttribute( "data_int3", 0 );
160 }
161 }
162 return true;
163 }
164
165 function metaData( $contentObjectAttribute )
166 {
167 return $contentObjectAttribute->attribute( "data_int" );
168 }
173 function toString( $contentObjectAttribute )
174 {
175 return $contentObjectAttribute->attribute( 'data_int' );
176 }
177
178 function fromString( $contentObjectAttribute, $string )
179 {
180 return $contentObjectAttribute->setAttribute( 'data_int', $string );
181 }
182
183 function isIndexable()
184 {
185 return true;
186 }
187
188 function isInformationCollector()
189 {
190 return true;
191 }
192
193 function sortKey( $contentObjectAttribute )
194 {
195 return $contentObjectAttribute->attribute( 'data_int' );
196 }
197
198 function sortKeyType()
199 {
200 return 'int';
201 }
202
206 function objectAttributeContent( $contentObjectAttribute )
207 {
208 return $contentObjectAttribute->attribute( "data_int" );
209 }
210
214 function title( $contentObjectAttribute, $name = null )
215 {
216 return $contentObjectAttribute->attribute( "data_int" );
217 }
218
219 function hasObjectAttributeContent( $contentObjectAttribute )
220 {
221 return true;
222 }
223
224 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
225 {
226 $defaultValue = $classAttribute->attribute( 'data_int3' );
227 $dom = $attributeParametersNode->ownerDocument;
228 $defaultValueNode = $dom->createElement( 'default-value' );
229 $defaultValueNode->setAttribute( 'is-set', $defaultValue ? 'true' : 'false' );
230 $attributeParametersNode->appendChild( $defaultValueNode );
231 }
232
233 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
234 {
235
236 $defaultValue = strtolower( $attributeParametersNode->getElementsByTagName( 'default-value' )->item( 0 )->getAttribute( 'is-set' ) ) == 'true';
237 $classAttribute->setAttribute( 'data_int3', $defaultValue );
238 }
239
240 function supportsBatchInitializeObjectAttribute()
241 {
242 return true;
243 }
244
245 function batchInitializeObjectAttributeData( $classAttribute )
246 {
247 $default = $classAttribute->attribute( "data_int3" );
248 return array( 'data_int' => $default,
249 'sort_key_int' => $default );
250 }
251 }
252
253 eZDataType::register( eZBooleanType::DATA_TYPE_STRING, "eZBooleanType" );
254
255 ?>
eZBooleanType
Stores a boolean value.
Definition: ezbooleantype.php:19
eZBooleanType\batchInitializeObjectAttributeData
batchInitializeObjectAttributeData( $classAttribute)
Definition: ezbooleantype.php:245
eZBooleanType\isIndexable
isIndexable()
Definition: ezbooleantype.php:183
eZBooleanType\unserializeContentClassAttribute
unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezbooleantype.php:233
eZBooleanType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezbooleantype.php:206
eZBooleanType\toString
toString( $contentObjectAttribute)
Definition: ezbooleantype.php:173
eZBooleanType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezbooleantype.php:40
eZBooleanType\__construct
__construct()
Definition: ezbooleantype.php:22
eZBooleanType\storeObjectAttribute
storeObjectAttribute( $attribute)
Definition: ezbooleantype.php:32
eZBooleanType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $classAttribute)
Definition: ezbooleantype.php:146
eZBooleanType\sortKeyType
sortKeyType()
Definition: ezbooleantype.php:198
eZBooleanType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezbooleantype.php:20
eZBooleanType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezbooleantype.php:193
eZBooleanType\title
title( $contentObjectAttribute, $name=null)
Definition: ezbooleantype.php:214
eZBooleanType\fetchCollectionAttributeHTTPInput
fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
Definition: ezbooleantype.php:128
eZBooleanType\metaData
metaData( $contentObjectAttribute)
Definition: ezbooleantype.php:165
eZBooleanType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezbooleantype.php:102
eZBooleanType\validateCollectionAttributeHTTPInput
validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezbooleantype.php:80
eZBooleanType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezbooleantype.php:178
eZBooleanType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezbooleantype.php:219
eZBooleanType\serializeContentClassAttribute
serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode)
Definition: ezbooleantype.php:224
eZBooleanType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezbooleantype.php:58
eZBooleanType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezbooleantype.php:240
eZBooleanType\isInformationCollector
isInformationCollector()
Definition: ezbooleantype.php:188
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.