Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezkeywordtype.php
Go to the documentation of this file.
1 <?php
20 class eZKeywordType extends eZDataType
21 {
22 const DATA_TYPE_STRING = 'ezkeyword';
23
24 public function __construct()
25 {
26 parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', 'Keywords', 'Datatype name' ),
27 array( 'serialize_supported' => true ) );
28 }
29
33 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
34 {
35 if ( $currentVersion != false )
36 {
37 $originalContentObjectAttributeID = $originalContentObjectAttribute->attribute( 'id' );
38 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
39
40 // if translating or copying an object
41 if ( $originalContentObjectAttributeID != $contentObjectAttributeID )
42 {
43 // copy keywords links as well
44 $keyword = $originalContentObjectAttribute->content();
45 if ( is_object( $keyword ) )
46 {
47 $keyword->store( $contentObjectAttribute );
48 }
49 }
50 }
51 }
52
57 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
58 {
59 $classAttribute = $contentObjectAttribute->contentClassAttribute();
60
61 if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
62 {
63 $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
64
65 if ( $data == "" )
66 {
67 if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() )
68 {
69 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
70 'Input required.' ) );
71 return eZInputValidator::STATE_INVALID;
72 }
73 }
74 }
75 else if ( !$classAttribute->attribute( 'is_information_collector' ) and $contentObjectAttribute->validateIsRequired() )
76 {
77 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
78 return eZInputValidator::STATE_INVALID;
79 }
80 return eZInputValidator::STATE_ACCEPTED;
81 }
82
86 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
87 {
88 if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
89 {
90 $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
91 $keyword = new eZKeyword();
92 $keyword->initializeKeyword( $data );
93 $contentObjectAttribute->setContent( $keyword );
94 return true;
95 }
96 return false;
97 }
98
103 function storeObjectAttribute( $attribute )
104 {
105 // create keyword index
106 $keyword = $attribute->content();
107 if ( is_object( $keyword ) )
108 {
109 $keyword->store( $attribute );
110 }
111 }
112
113 function storeClassAttribute( $attribute, $version )
114 {
115 }
116
117 function storeDefinedClassAttribute( $attribute )
118 {
119 }
120
121 function validateClassAttributeHTTPInput( $http, $base, $attribute )
122 {
123 return eZInputValidator::STATE_ACCEPTED;
124 }
125
126 function fixupClassAttributeHTTPInput( $http, $base, $attribute )
127 {
128 }
129
130 function fetchClassAttributeHTTPInput( $http, $base, $attribute )
131 {
132 return true;
133 }
134
138 function objectAttributeContent( $attribute )
139 {
140 $keyword = new eZKeyword();
141 $keyword->fetch( $attribute );
142
143 return $keyword;
144 }
145
149 function metaData( $attribute )
150 {
151 $keyword = new eZKeyword();
152 $keyword->fetch( $attribute );
153 $return = $keyword->keywordString();
154
155 return $return;
156 }
157
161 function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null )
162 {
163 if ( $version != null ) // Do not delete if discarding draft
164 {
165 return;
166 }
167
168 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
169
170 $db = eZDB::instance();
171
172 /* First we retrieve all the keyword ID related to this object attribute */
173 $res = $db->arrayQuery( "SELECT keyword_id
174 FROM ezkeyword_attribute_link
175 WHERE objectattribute_id='$contentObjectAttributeID'" );
176 if ( !count ( $res ) )
177 {
178 /* If there are no keywords at all, we abort the function as there
179 * is nothing more to do */
180 return;
181 }
182 $keywordIDs = array();
183 foreach ( $res as $record )
184 $keywordIDs[] = $record['keyword_id'];
185 $keywordIDString = implode( ', ', $keywordIDs );
186
187 /* Then we see which ones only have a count of 1 */
188 $res = $db->arrayQuery( "SELECT keyword_id
189 FROM ezkeyword, ezkeyword_attribute_link
190 WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id
191 AND ezkeyword.id IN ($keywordIDString)
192 GROUP BY keyword_id
193 HAVING COUNT(*) = 1" );
194 $unusedKeywordIDs = array();
195 foreach ( $res as $record )
196 $unusedKeywordIDs[] = $record['keyword_id'];
197 $unusedKeywordIDString = implode( ', ', $unusedKeywordIDs );
198
199 /* Then we delete those unused keywords */
200 if ( $unusedKeywordIDString )
201 $db->query( "DELETE FROM ezkeyword WHERE id IN ($unusedKeywordIDString)" );
202
203 /* And as last we remove the link between the keyword and the object
204 * attribute to be removed */
205 $db->query( "DELETE FROM ezkeyword_attribute_link
206 WHERE objectattribute_id='$contentObjectAttributeID'" );
207 }
208
212 function title( $attribute, $name = null )
213 {
214 $keyword = new eZKeyword();
215 $keyword->fetch( $attribute );
216 $return = $keyword->keywordString();
217
218 return $return;
219 }
220
221 function hasObjectAttributeContent( $contentObjectAttribute )
222 {
223 $keyword = new eZKeyword();
224 $keyword->fetch( $contentObjectAttribute );
225 $array = $keyword->keywordArray();
226
227 return count( $array ) > 0;
228 }
229
230 function isIndexable()
231 {
232 return true;
233 }
234
242 function toString( $contentObjectAttribute )
243 {
244 $keyword = new eZKeyword();
245 $keyword->fetch( $contentObjectAttribute );
246 return $keyword->keywordString();
247 }
248
249 function fromString( $contentObjectAttribute, $string )
250 {
251 $keyword = new eZKeyword();
252 $keyword->initializeKeyword( $string );
253 $contentObjectAttribute->setContent( $keyword );
254 return true;
255 }
256
257 function serializeContentObjectAttribute( $package, $objectAttribute )
258 {
259 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
260
261 $keyword = new eZKeyword();
262 $keyword->fetch( $objectAttribute );
263 $keyWordString = $keyword->keywordString();
264 $dom = $node->ownerDocument;
265 $keywordStringNode = $dom->createElement( 'keyword-string' );
266 $keywordStringNode->appendChild( $dom->createTextNode( $keyWordString ) );
267 $node->appendChild( $keywordStringNode );
268
269 return $node;
270 }
271
272 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
273 {
274 $keyWordString = $attributeNode->getElementsByTagName( 'keyword-string' )->item( 0 )->textContent;
275 $keyword = new eZKeyword();
276 $keyword->initializeKeyword( $keyWordString );
277 $objectAttribute->setContent( $keyword );
278 }
279
280 function supportsBatchInitializeObjectAttribute()
281 {
282 return true;
283 }
284 }
285
286 eZDataType::register( eZKeywordType::DATA_TYPE_STRING, 'eZKeywordType' );
287
288 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDataType
Base class for content datatypes.
Definition: ezdatatype.php:46
eZDataType\register
static register( $dataTypeString, $className)
Definition: ezdatatype.php:203
eZDataType\createContentObjectAttributeDOMNode
createContentObjectAttributeDOMNode( $objectAttribute)
Definition: ezdatatype.php:1371
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZKeywordType
A content datatype which handles keyword indexes.
Definition: ezkeywordtype.php:21
eZKeywordType\isIndexable
isIndexable()
Definition: ezkeywordtype.php:230
eZKeywordType\validateObjectAttributeHTTPInput
validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezkeywordtype.php:57
eZKeywordType\objectAttributeContent
objectAttributeContent( $attribute)
Definition: ezkeywordtype.php:138
eZKeywordType\storeDefinedClassAttribute
storeDefinedClassAttribute( $attribute)
Definition: ezkeywordtype.php:117
eZKeywordType\storeClassAttribute
storeClassAttribute( $attribute, $version)
Definition: ezkeywordtype.php:113
eZKeywordType\deleteStoredObjectAttribute
deleteStoredObjectAttribute( $contentObjectAttribute, $version=null)
Definition: ezkeywordtype.php:161
eZKeywordType\serializeContentObjectAttribute
serializeContentObjectAttribute( $package, $objectAttribute)
Definition: ezkeywordtype.php:257
eZKeywordType\validateClassAttributeHTTPInput
validateClassAttributeHTTPInput( $http, $base, $attribute)
Definition: ezkeywordtype.php:121
eZKeywordType\initializeObjectAttribute
initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute)
Definition: ezkeywordtype.php:33
eZKeywordType\storeObjectAttribute
storeObjectAttribute( $attribute)
Definition: ezkeywordtype.php:103
eZKeywordType\metaData
metaData( $attribute)
Definition: ezkeywordtype.php:149
eZKeywordType\hasObjectAttributeContent
hasObjectAttributeContent( $contentObjectAttribute)
Definition: ezkeywordtype.php:221
eZKeywordType\fetchClassAttributeHTTPInput
fetchClassAttributeHTTPInput( $http, $base, $attribute)
Definition: ezkeywordtype.php:130
eZKeywordType\fromString
fromString( $contentObjectAttribute, $string)
Definition: ezkeywordtype.php:249
eZKeywordType\__construct
__construct()
Definition: ezkeywordtype.php:24
eZKeywordType\supportsBatchInitializeObjectAttribute
supportsBatchInitializeObjectAttribute()
Definition: ezkeywordtype.php:280
eZKeywordType\fetchObjectAttributeHTTPInput
fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute)
Definition: ezkeywordtype.php:86
eZKeywordType\unserializeContentObjectAttribute
unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode)
Definition: ezkeywordtype.php:272
eZKeywordType\title
title( $attribute, $name=null)
Definition: ezkeywordtype.php:212
eZKeywordType\DATA_TYPE_STRING
const DATA_TYPE_STRING
Definition: ezkeywordtype.php:22
eZKeywordType\toString
toString( $contentObjectAttribute)
Definition: ezkeywordtype.php:242
eZKeywordType\fixupClassAttributeHTTPInput
fixupClassAttributeHTTPInput( $http, $base, $attribute)
Definition: ezkeywordtype.php:126
eZKeyword
A content datatype which handles keyword index instances.
Definition: ezkeyword.php:19
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+.