Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezproductcategorytype.php
Go to the documentation of this file.
1 <?php
18 class eZProductCategoryType extends eZDataType
19 {
20 const DATA_TYPE_STRING = "ezproductcategory";
21
22 public function __construct()
23 {
24 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Product category", 'Datatype name' ),
25 array( 'serialize_supported' => true,
26 'object_serialize_map' => array( 'data_int' => 'value' ) ) );
27 }
28
32 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
33 {
34 if ( $currentVersion != false )
35 {
36 $dataInt = $originalContentObjectAttribute->attribute( "data_int" );
37 $contentObjectAttribute->setAttribute( "data_int", $dataInt );
38 }
39 else
40 {
41 $default = 0;
42 $contentObjectAttribute->setAttribute( "data_int", $default );
43 }
44 }
45
49 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
50 {
51 if ( !$contentObjectAttribute->validateIsRequired() )
52 return eZInputValidator::STATE_ACCEPTED;
53
54 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ) )
55 {
56 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
57
58 if ( is_numeric( $data ) )
59 return eZInputValidator::STATE_ACCEPTED;
60 }
61
62 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
63 'Input required.' ) );
64 return eZInputValidator::STATE_INVALID;
65 }
66
70 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
71 {
72 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ))
73 {
74 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
75 if ( !is_numeric( $data ) )
76 $data = 0;
77 }
78 else
79 {
80 $data = 0;
81 }
82
83 $contentObjectAttribute->setAttribute( "data_int", $data );
84 return true;
85 }
86
90 function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute )
91 {
92 if ( $http->hasPostVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) ))
93 {
94 $data = $http->postVariable( $base . "_category_id_" . $contentObjectAttribute->attribute( "id" ) );
95 if ( !is_numeric( $data ) )
96 $data = 0;
97 }
98 else
99 {
100 $data = 0;
101 }
102
103 $collectionAttribute->setAttribute( 'data_int', $data );
104 return true;
105 }
106
107 function metaData( $contentObjectAttribute )
108 {
109 return $contentObjectAttribute->attribute( "data_int" );
110 }
111
112 function isIndexable()
113 {
114 return true;
115 }
116
117 function isInformationCollector()
118 {
119 return true;
120 }
121
122 function sortKey( $contentObjectAttribute )
123 {
124 return $contentObjectAttribute->attribute( 'data_int' );
125 }
126
127 function sortKeyType()
128 {
129 return 'int';
130 }
131
135 function objectAttributeContent( $contentObjectAttribute )
136 {
137 $category = eZProductCategory::fetch( $contentObjectAttribute->attribute( 'data_int' ) );
138 return $category;
139 }
140
141 function hasObjectAttributeContent( $contentObjectAttribute )
142 {
143 $productCategory = $this->objectAttributeContent( $contentObjectAttribute );
144 return is_object( $productCategory );
145 }
146
147 function toString( $contentObjectAttribute )
148 {
149 $category = $contentObjectAttribute->attribute( 'content' );
150 if ( $category )
151 {
152 return implode( '|', array( $category->attribute( 'name' ), $category->attribute( 'id' ) ) );
153 }
154 return '';
155 }
156
157
158 function fromString( $contentObjectAttribute, $string )
159 {
160 if ( $string == '' )
161 return true;
162 $categoryData = explode( '|', $string );
163
164 if ( isset ( $categoryData[1] ) )
165 {
166 $category = eZProductCategory::fetch( $categoryData[1] );
167 if ( $category )
168 {
169 $contentObjectAttribute->setAttribute( 'data_int', $category->attribute( 'id' ) );
170 return true;
171 }
172 }
173
174 if ( isset ( $categoryData[1] ) )
175 {
176 $category = eZProductCategory::fetchByName( $categoryData[0] );
177 if ( $category )
178 {
179 $contentObjectAttribute->setAttribute( 'data_int', $category->attribute( 'id' ) );
180 return true;
181 }
182 }
183 return false;
184 }
185
189 function title( $contentObjectAttribute, $name = null )
190 {
191 $categoryID = $contentObjectAttribute->attribute( "data_int" );
192 $category = $categoryID > 0 ? eZProductCategory::fetch( $categoryID ) : false;
193 return is_object( $category ) ? $category->attribute( 'name' ) : '';
194 }
195
196 function diff( $old, $new, $options = null )
197 {
198 return null;
199 }
200
201 function supportsBatchInitializeObjectAttribute()
202 {
203 return true;
204 }
205
206 function batchInitializeObjectAttributeData( $classAttribute )
207 {
208 $default = 0;
209 return array( 'data_int' => $default, 'sort_key_int' => $default );
210 }
211 }
212
213 eZDataType::register( eZProductCategoryType::DATA_TYPE_STRING, "eZProductCategoryType" );
214
215 ?>
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
eZProductCategoryType
Stores product category.
Definition: ezproductcategorytype.php:19
eZProductCategoryType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezproductcategorytype.php:158
eZProductCategoryType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezproductcategorytype.php:20
eZProductCategoryType\metaData
metaData( $contentObjectAttribute)
Definition: ezproductcategorytype.php:107
eZProductCategoryType\isIndexable
isIndexable()
Definition: ezproductcategorytype.php:112
eZProductCategoryType\isInformationCollector
isInformationCollector()
Definition: ezproductcategorytype.php:117
eZProductCategoryType\toString
toString( $contentObjectAttribute)
Definition: ezproductcategorytype.php:147
eZProductCategoryType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezproductcategorytype.php:201
eZProductCategoryType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezproductcategorytype.php:70
eZProductCategoryType\__construct
__construct()
Definition: ezproductcategorytype.php:22
eZProductCategoryType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezproductcategorytype.php:141
eZProductCategoryType\objectAttributeContent
objectAttributeContent( $contentObjectAttribute)
Definition: ezproductcategorytype.php:135
eZProductCategoryType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezproductcategorytype.php:32
eZProductCategoryType\sortKey
sortKey( $contentObjectAttribute)
Definition: ezproductcategorytype.php:122
eZProductCategoryType\diff
diff( $old, $new, $options=null)
Definition: ezproductcategorytype.php:196
eZProductCategoryType\sortKeyType
sortKeyType()
Definition: ezproductcategorytype.php:127
eZProductCategoryType\fetchCollectionAttributeHTTPInput
fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
Definition: ezproductcategorytype.php:90
eZProductCategoryType\batchInitializeObjectAttributeData
batchInitializeObjectAttributeData( $classAttribute)
Definition: ezproductcategorytype.php:206
eZProductCategoryType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezproductcategorytype.php:49
eZProductCategoryType\title
title( $contentObjectAttribute, $name=null)
Definition: ezproductcategorytype.php:189
eZProductCategory\fetch
static fetch( $id, $asObject=true)
Definition: ezproductcategory.php:35
eZProductCategory\fetchByName
static fetchByName( $name, $asObject=true)
Definition: ezproductcategory.php:43
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+.