00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( 'kernel/classes/ezdatatype.php' );
00039 include_once( 'kernel/common/i18n.php' );
00040
00041 include_once( 'kernel/classes/datatypes/ezkeyword/ezkeyword.php' );
00042
00043 define( 'EZ_DATATYPESTRING_KEYWORD', 'ezkeyword' );
00044
00045 class eZKeywordType extends eZDataType
00046 {
00047
00048
00049
00050 function eZKeywordType()
00051 {
00052 $this->eZDataType( EZ_DATATYPESTRING_KEYWORD, ezi18n( 'kernel/classes/datatypes', 'Keywords', 'Datatype name' ),
00053 array( 'serialize_supported' => true ) );
00054 }
00055
00056
00057
00058
00059 function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
00060 {
00061 if ( $currentVersion != false )
00062 {
00063 $originalContentObjectAttributeID = $originalContentObjectAttribute->attribute( 'id' );
00064 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
00065
00066
00067 if ( $originalContentObjectAttributeID != $contentObjectAttributeID )
00068 {
00069
00070 $keyword =& $originalContentObjectAttribute->content();
00071 if ( is_object( $keyword ) )
00072 {
00073 $keyword->store( $contentObjectAttribute );
00074 }
00075 }
00076 }
00077 }
00078
00079
00080
00081
00082
00083 function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00084 {
00085 if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00086 {
00087 $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00088 $classAttribute =& $contentObjectAttribute->contentClassAttribute();
00089
00090 if ( $data == "" )
00091 {
00092 if ( !$classAttribute->attribute( 'is_information_collector' ) and
00093 $contentObjectAttribute->validateIsRequired() )
00094 {
00095 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00096 'Input required.' ) );
00097 return EZ_INPUT_VALIDATOR_STATE_INVALID;
00098 }
00099 }
00100 }
00101 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00102 }
00103
00104
00105
00106
00107 function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
00108 {
00109 if ( $http->hasPostVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) ) )
00110 {
00111 $data = $http->postVariable( $base . '_ezkeyword_data_text_' . $contentObjectAttribute->attribute( 'id' ) );
00112 $keyword = new eZKeyword();
00113 $keyword->initializeKeyword( $data );
00114 $contentObjectAttribute->setContent( $keyword );
00115 return true;
00116 }
00117 return false;
00118 }
00119
00120
00121
00122
00123
00124 function storeObjectAttribute( &$attribute )
00125 {
00126
00127 $keyword =& $attribute->content();
00128 if ( is_object( $keyword ) )
00129 {
00130 $keyword->store( $attribute );
00131 }
00132 }
00133
00134 function storeClassAttribute( &$attribute, $version )
00135 {
00136 }
00137
00138 function storeDefinedClassAttribute( &$attribute )
00139 {
00140 }
00141
00142
00143
00144
00145 function validateClassAttributeHTTPInput( &$http, $base, &$attribute )
00146 {
00147 return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
00148 }
00149
00150
00151
00152
00153 function fixupClassAttributeHTTPInput( &$http, $base, &$attribute )
00154 {
00155 }
00156
00157
00158
00159
00160 function fetchClassAttributeHTTPInput( &$http, $base, &$attribute )
00161 {
00162 return true;
00163 }
00164
00165
00166
00167
00168 function &objectAttributeContent( &$attribute )
00169 {
00170 $keyword = new eZKeyword();
00171 $keyword->fetch( $attribute );
00172
00173 return $keyword;
00174 }
00175
00176
00177
00178
00179 function metaData( &$attribute )
00180 {
00181 $keyword = new eZKeyword();
00182 $keyword->fetch( $attribute );
00183 $return = $keyword->keywordString();
00184
00185 return $return;
00186 }
00187
00188
00189
00190
00191 function contentActionList( &$classAttribute )
00192 {
00193 return array();
00194 }
00195
00196
00197
00198
00199 function deleteStoredObjectAttribute( &$contentObjectAttribute, $version = null )
00200 {
00201 if ( $version != null )
00202 {
00203 return;
00204 }
00205
00206 $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
00207
00208 $db =& eZDB::instance();
00209
00210
00211 $res = $db->arrayQuery( "SELECT keyword_id
00212 FROM ezkeyword_attribute_link
00213 WHERE objectattribute_id='$contentObjectAttributeID'" );
00214 if ( !count ( $res ) )
00215 {
00216
00217
00218 return;
00219 }
00220 $keywordIDs = array();
00221 foreach ( $res as $record )
00222 $keywordIDs[] = $record['keyword_id'];
00223 $keywordIDString = implode( ', ', $keywordIDs );
00224
00225
00226 $res = $db->arrayQuery( "SELECT keyword_id
00227 FROM ezkeyword, ezkeyword_attribute_link
00228 WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id
00229 AND ezkeyword.id IN ($keywordIDString)
00230 GROUP BY keyword_id
00231 HAVING COUNT(*) = 1" );
00232 $unusedKeywordIDs = array();
00233 foreach ( $res as $record )
00234 $unusedKeywordIDs[] = $record['keyword_id'];
00235 $unusedKeywordIDString = implode( ', ', $unusedKeywordIDs );
00236
00237
00238 if ( $unusedKeywordIDString )
00239 $db->query( "DELETE FROM ezkeyword WHERE id IN ($unusedKeywordIDString)" );
00240
00241
00242
00243 $db->query( "DELETE FROM ezkeyword_attribute_link
00244 WHERE objectattribute_id='$contentObjectAttributeID'" );
00245 }
00246
00247
00248
00249
00250 function title( &$attribute )
00251 {
00252 $keyword = new eZKeyword();
00253 $keyword->fetch( $attribute );
00254 $return = $keyword->keywordString();
00255
00256 return $return;
00257 }
00258
00259 function hasObjectAttributeContent( &$contentObjectAttribute )
00260 {
00261 $keyword = new eZKeyword();
00262 $keyword->fetch( $contentObjectAttribute );
00263 $array =& $keyword->keywordArray();
00264
00265 return count( $array ) > 0;
00266 }
00267
00268
00269
00270
00271 function isIndexable()
00272 {
00273 return true;
00274 }
00275
00276
00277
00278
00279
00280 function toString( $contentObjectAttribute )
00281 {
00282 $keyword = new eZKeyword();
00283 $keyword->fetch( $contentObjectAttribute );
00284 return $keyword->keywordString();
00285 }
00286
00287 function fromString( &$contentObjectAttribute, $string )
00288 {
00289 if ( $string != '' )
00290 {
00291 $keyword = new eZKeyword();
00292 $keyword->initializeKeyword( $string );
00293 $contentObjectAttribute ->setContent( $keyword );
00294 }
00295 return true;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305 function serializeContentObjectAttribute( &$package, &$objectAttribute )
00306 {
00307 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00308
00309 $keyword = new eZKeyword();
00310 $keyword->fetch( $objectAttribute );
00311 $keyWordString = $keyword->keywordString();
00312 $node->appendChild( eZDOMDocument::createElementTextNode( 'keyword-string', $keyWordString ) );
00313
00314 return $node;
00315 }
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
00326 {
00327 $keyWordString = $attributeNode->elementTextContentByName( 'keyword-string' );
00328 $keyword = new eZKeyword();
00329 $keyword->initializeKeyword( $keyWordString );
00330 $objectAttribute->setContent( $keyword );
00331 }
00332 }
00333
00334 eZDataType::register( EZ_DATATYPESTRING_KEYWORD, 'ezkeywordtype' );
00335
00336 ?>