|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZMultiOption2Type class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZMultiOption2Type ezmultioption2type.php 00013 \ingroup eZDatatype 00014 \brief A datatype which works with multiple options. 00015 00016 This allows the user to add several option choices almost as if he 00017 was adding attributes with option datatypes. 00018 00019 This class implements the interface for a datatype but passes 00020 most of the work over to the eZMultiOption2 class which handles 00021 parsing, storing and manipulation of multioption2s and options. 00022 00023 This datatype supports: 00024 - fetch and validation of HTTP data 00025 - search indexing 00026 - product option information 00027 - class title 00028 - class serialization 00029 00030 */ 00031 00032 class eZMultiOption2Type extends eZDataType 00033 { 00034 const DEFAULT_NAME_VARIABLE = "_ezmultioption2_default_name_"; 00035 const MAX_CHILD_LEVEL = 50; 00036 const DATA_TYPE_STRING = "ezmultioption2"; 00037 00038 /*! 00039 Constructor to initialize the datatype. 00040 */ 00041 function eZMultiOption2Type() 00042 { 00043 $this->eZDataType( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Multi-option2", 'Datatype name' ), 00044 array( 'serialize_supported' => true ) ); 00045 } 00046 00047 /*! 00048 Validates the input for this datatype. 00049 \return True if input is valid. 00050 */ 00051 function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00052 { 00053 return eZInputValidator::STATE_ACCEPTED; 00054 } 00055 00056 /*! 00057 This function calles xmlString function to create xml string and then store the content. 00058 */ 00059 function storeObjectAttribute( $contentObjectAttribute ) 00060 { 00061 $optiongroup = $contentObjectAttribute->content(); 00062 $contentObjectAttribute->setAttribute( "data_text", $optiongroup->xmlString() ); 00063 } 00064 00065 /*! 00066 \return An eZMultiOption2 object which contains all the option data 00067 */ 00068 function objectAttributeContent( $contentObjectAttribute ) 00069 { 00070 $optiongroup = new eZMultiOption2( "" ); 00071 $optiongroup->decodeXML( $contentObjectAttribute->attribute( "data_text" ) ); 00072 return $optiongroup; 00073 } 00074 00075 function isIndexable() 00076 { 00077 return true; 00078 } 00079 00080 /*! 00081 \return The internal XML text. 00082 */ 00083 function metaData( $contentObjectAttribute ) 00084 { 00085 return $contentObjectAttribute->attribute( "data_text" ); 00086 } 00087 00088 /*! 00089 Fetches the http post var integer input and stores it in the data instance. 00090 */ 00091 function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) 00092 { 00093 $editMode = $http->postVariable( $base . "_data_edit_mode_" . $contentObjectAttribute->attribute( "id" ) ); 00094 if( $editMode == 'rules' ) 00095 { 00096 $optiongroup = $contentObjectAttribute->content(); 00097 00098 $optionRulesArray = $http->hasPostVariable( $base . "_data_multioption_rule_for" ) 00099 ? $http->postVariable( $base . "_data_multioption_rule_for" ) 00100 : array(); 00101 $rules = array(); 00102 foreach( $optionRulesArray as $ruleFor ) 00103 { 00104 $parentMultioptionIDList = $http->postVariable( $base . "_data_rule_parent_multioption_id_" . $ruleFor ); 00105 $rule = array(); 00106 foreach ( $parentMultioptionIDList as $parentMultioptionID ) 00107 { 00108 $parentMultioptionData = $optiongroup->findMultiOption( $parentMultioptionID ); 00109 $parentMultioptionGroup = $parentMultioptionData['group']; 00110 00111 $parentMultioptionOptionList = $parentMultioptionGroup->Options[$parentMultioptionData['id']]['optionlist']; 00112 00113 $ruleData = $http->hasPostVariable( $base . "_data_multioption_rule_" . $ruleFor . '_' . $parentMultioptionID ) 00114 ? $http->postVariable( $base . "_data_multioption_rule_" . $ruleFor . '_' . $parentMultioptionID ) 00115 : array(); 00116 if ( count( $parentMultioptionOptionList ) == count( $ruleData ) ) 00117 continue; 00118 $rule[$parentMultioptionID] = $ruleData; 00119 } 00120 if ( count( $rule ) ) 00121 $rules[$ruleFor] = $rule; 00122 } 00123 $optiongroup->Rules = $rules; 00124 $contentObjectAttribute->setContent( $optiongroup ); 00125 return true; 00126 } 00127 00128 $optiongroup = new eZMultiOption2( '' ); 00129 00130 $oldoptiongroup = $contentObjectAttribute->content(); 00131 if ( $oldoptiongroup->Rules ) 00132 $optiongroup->Rules = $oldoptiongroup->Rules; 00133 $this->fetchHTTPInputForGroup( $optiongroup, $http, $base, $contentObjectAttribute ); 00134 $optiongroup->initCountersRecursive(); 00135 $contentObjectAttribute->setContent( $optiongroup ); 00136 return true; 00137 } 00138 00139 function fetchHTTPInputForGroup( $parentOptionGroup, $http, $base, $contentObjectAttribute, $depth = 0 ) 00140 { 00141 00142 $optionGroupIDArray = $http->hasPostVariable( $base . "_data_optiongroup_id_" . 00143 $contentObjectAttribute->attribute( "id" ) . '_' . 00144 $parentOptionGroup->attribute( 'group_id' ) ) 00145 ? $http->postVariable( $base . "_data_optiongroup_id_" . 00146 $contentObjectAttribute->attribute( "id" ) . '_' . 00147 $parentOptionGroup->attribute( 'group_id' ) ) 00148 : array(); 00149 $optionGroupNameList = count( $optionGroupIDArray ) > 0 00150 ? $http->postVariable( $base . "_data_optiongroup_name_" . 00151 $contentObjectAttribute->attribute( "id" ) . '_' . 00152 $parentOptionGroup->attribute( 'group_id' ) ) 00153 : array(); 00154 foreach ( $optionGroupIDArray as $key => $optionGroupID ) 00155 { 00156 unset( $optionGroup ); 00157 $optionGroup = new eZMultiOption2( $optionGroupNameList[$key], 0,0,0, $optionGroupID ); 00158 00159 if ( $http->hasPostVariable( $base . "_data_optiongroup_id_parent_multioption_" . 00160 $contentObjectAttribute->attribute( "id" ) . '_' . 00161 $optionGroupID ) ) 00162 { 00163 $parentMultioptionID = $http->postVariable( $base . "_data_optiongroup_id_parent_multioption_" . 00164 $contentObjectAttribute->attribute( "id" ) . '_' . 00165 $optionGroupID ); 00166 $parentOptionGroup->addChildGroup( $optionGroup, $parentMultioptionID ); 00167 } 00168 else 00169 { 00170 $parentOptionGroup->addChildGroup( $optionGroup ); 00171 } 00172 if ( $optionGroupID == 0 ) 00173 continue ; 00174 00175 $multioptionIDArray = $http->hasPostVariable( $base . "_data_multioption_id_" . 00176 $contentObjectAttribute->attribute( "id" ) . '_' . 00177 $optionGroupID ) 00178 ? $http->postVariable( $base . "_data_multioption_id_" . 00179 $contentObjectAttribute->attribute( "id" ). '_' . 00180 $optionGroupID ) 00181 : array(); 00182 foreach( $multioptionIDArray as $multioptionID ) 00183 { 00184 00185 $multioptionName = $http->postVariable( $base . "_data_multioption_name_" . 00186 $contentObjectAttribute->attribute( "id" ). '_' . 00187 $optionGroupID . '_' . $multioptionID ); 00188 00189 $defaultValue = $http->hasPostVariable( $base . "_data_default_option_" . 00190 $contentObjectAttribute->attribute( "id" ). '_' . 00191 $optionGroupID . '_' . $multioptionID ) 00192 ? $http->postVariable( $base . "_data_default_option_" . 00193 $contentObjectAttribute->attribute( "id" ). '_' . 00194 $optionGroupID . '_' . $multioptionID ) 00195 : ''; 00196 00197 $multiOptionPriority = 0; 00198 00199 $newID = $optionGroup->addMultiOption( $multioptionName, $multiOptionPriority, $defaultValue, $multioptionID ); 00200 00201 00202 $optionCountArray = $http->hasPostVariable( $base . "_data_option_option_id_" . 00203 $contentObjectAttribute->attribute( "id" ) . '_' . 00204 $optionGroupID . '_' . $multioptionID ) 00205 ? $http->postVariable( $base . "_data_option_option_id_" . 00206 $contentObjectAttribute->attribute( "id" ) . '_' . 00207 $optionGroupID . '_' . $multioptionID ) 00208 : array(); 00209 00210 $optionValueArray = $http->hasPostVariable( $base . "_data_option_value_" . 00211 $contentObjectAttribute->attribute( "id" ) . '_' . 00212 $optionGroupID . '_' . $multioptionID ) 00213 ? $http->postVariable( $base . "_data_option_value_" . 00214 $contentObjectAttribute->attribute( "id" ) . '_' . 00215 $optionGroupID . '_' . $multioptionID ) 00216 : array(); 00217 $http->postVariable( $base . "_data_option_value_" . 00218 $contentObjectAttribute->attribute( "id" ) . '_' . 00219 $optionGroupID . '_' . $multioptionID ); 00220 $http->postVariable( $base . "_data_option_additional_price_" . 00221 $contentObjectAttribute->attribute( "id" ) . '_' . 00222 $optionGroupID . '_' . $multioptionID ); 00223 $optionAdditionalPriceArray = $http->hasPostVariable( $base . "_data_option_additional_price_" . 00224 $contentObjectAttribute->attribute( "id" ) . '_' . 00225 $optionGroupID . '_' . $multioptionID ) 00226 ? $http->postVariable( $base . "_data_option_additional_price_" . 00227 $contentObjectAttribute->attribute( "id" ) . '_' . 00228 $optionGroupID . '_' . $multioptionID ) 00229 : array(); 00230 for ( $i = 0; $i < count( $optionCountArray ); $i++ ) 00231 { 00232 $isSelectable = $http->hasPostVariable( $base . "_data_option_is_selectable_" . 00233 $contentObjectAttribute->attribute( "id" ) . '_' . 00234 $optionGroupID . '_' . $multioptionID . '_' . $optionCountArray[$i] ) 00235 ? 0 : 1; 00236 $objectID = $http->hasPostVariable( $base . "_data_option_object_" . 00237 $contentObjectAttribute->attribute( "id" ) . '_' . 00238 $optionGroupID . '_' . $multioptionID . '_' . $optionCountArray[$i] ) 00239 ? $http->postVariable( $base . "_data_option_object_" . 00240 $contentObjectAttribute->attribute( "id" ) . '_' . 00241 $optionGroupID . '_' . $multioptionID . '_' . $optionCountArray[$i] ) : 0; 00242 $optionGroup->addOption( $newID, $optionCountArray[$i], $optionValueArray[$i], $optionAdditionalPriceArray[$i], $isSelectable, $objectID ); 00243 } 00244 } 00245 if ( $depth > self::MAX_CHILD_LEVEL) 00246 die('max recursion level has been reached'); 00247 $this->fetchHTTPInputForGroup( $optionGroup, $http, $base, $contentObjectAttribute, $depth+1 ); 00248 00249 $parentOptionGroup->initCounters( $optionGroup ); 00250 00251 } 00252 00253 } 00254 00255 00256 /*! 00257 This function performs specific actions. 00258 00259 It has some special actions with parameters which is done by exploding 00260 $action into several parts with delimeter '_'. 00261 The first element is the name of specific action to perform. 00262 The second element will contain the key value or id. 00263 00264 The various operation's that is performed by this function are as follow. 00265 - new-option - A new option is added to a multioption. 00266 - remove-selected-option - Removes a selected option. 00267 - new_multioption - Adds a new multioption. 00268 - remove_selected_multioption - Removes all multioptions given by a selection list 00269 */ 00270 function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute, $parameters ) 00271 { 00272 $actionlist = explode( "_", $action ); 00273 if ( $actionlist[0] == "new-option" ) 00274 { 00275 $rootGroup = $contentObjectAttribute->content(); 00276 $groupID = $actionlist[1]; 00277 $multioptionID = $actionlist[2]; 00278 $optionID = $rootGroup->addOptionForMultioptionID( $multioptionID, "", "", "" ); 00279 00280 $group = $rootGroup->findGroup( $groupID ); 00281 00282 $rootGroup->addOptionToRules( $multioptionID, $optionID ); 00283 00284 $rootGroup->initCounters( $group ); 00285 $rootGroup->initCountersRecursive(); 00286 $contentObjectAttribute->setContent( $rootGroup ); 00287 $contentObjectAttribute->store(); 00288 } 00289 else if ( $actionlist[0] == "new-sublevel" ) 00290 { 00291 $rootGroup = $contentObjectAttribute->content(); 00292 $groupID = $actionlist[1]; 00293 $multioptionID = $actionlist[2]; 00294 00295 $group = $rootGroup->findGroup( $groupID ); 00296 if ( !$group ) 00297 return; 00298 $childGroup = new eZMultiOption2( '', 0, $rootGroup->getMultiOptionIDCounter(),$rootGroup->getOptionCounter() ); 00299 00300 $group->addChildGroup( $childGroup, $multioptionID ); 00301 00302 $newID = $childGroup->addMultiOption( "", 0, false , '' ); 00303 $childGroup->addOption( $newID, "", "", "" ); 00304 $rootGroup->initCounters( $childGroup ); 00305 00306 $rootGroup->initCountersRecursive(); 00307 00308 $contentObjectAttribute->setContent( $rootGroup ); 00309 $contentObjectAttribute->store(); 00310 } 00311 else if ( $actionlist[0] == "new-group" ) 00312 { 00313 $rootGroup = $contentObjectAttribute->content(); 00314 $childGroup = new eZMultiOption2( '', 0, $rootGroup->getMultiOptionIDCounter(),$rootGroup->getOptionCounter() ); 00315 $rootGroup->addChildGroup( $childGroup ); 00316 $newID = $childGroup->addMultiOption( "", 0, false , '' ); 00317 $childGroup->addOption( $newID, "", "", "" ); 00318 $rootGroup->initCounters( $childGroup ); 00319 $rootGroup->initCountersRecursive(); 00320 00321 $contentObjectAttribute->setContent( $rootGroup ); 00322 $contentObjectAttribute->store(); 00323 } 00324 else if ( $actionlist[0] == "remove-selected-option" ) 00325 { 00326 $rootGroup = $contentObjectAttribute->content(); 00327 $groupID = $actionlist[1]; 00328 $multioptionID = $actionlist[2]; 00329 $postvarname = "ContentObjectAttribute" . "_data_option_remove_" . $contentObjectAttribute->attribute( "id" ) . "_" . 00330 $groupID . "_" . $multioptionID; 00331 $array_remove = $http->hasPostVariable( $postvarname ) ? $http->postVariable( $postvarname ) : array(); 00332 00333 $group = $rootGroup->findGroup( $groupID ); 00334 00335 if ( $group ) 00336 { 00337 $group->removeOptions( $array_remove, $multioptionID ); 00338 $rootGroup->cleanupRules(); 00339 $contentObjectAttribute->setContent( $rootGroup ); 00340 $contentObjectAttribute->store(); 00341 } 00342 } 00343 else if ( $actionlist[0] == "new-multioption" ) 00344 { 00345 $rootGroup = $contentObjectAttribute->content(); 00346 $groupID = $actionlist[1]; 00347 $group = $rootGroup->findGroup( $groupID ); 00348 if ( !$group ) 00349 return; 00350 00351 $newID = $group->addMultiOption( "" ,0,false, '' ); 00352 $group->addOption( $newID, "", "", "" ); 00353 $group->addOption( $newID, "" ,"", "" ); 00354 $rootGroup->initCounters( $group ); 00355 $rootGroup->initCountersRecursive(); 00356 $contentObjectAttribute->setContent( $rootGroup ); 00357 $contentObjectAttribute->store(); 00358 00359 } 00360 else if ( $actionlist[0] == "remove-selected-multioption" ) 00361 { 00362 $rootGroup = $contentObjectAttribute->content(); 00363 $groupID = $actionlist[1]; 00364 $postvarname = "ContentObjectAttribute" . "_data_multioption_remove_" . $contentObjectAttribute->attribute( "id" ) . "_" . $groupID; 00365 $array_remove = $http->hasPostVariable( $postvarname ) ? $http->postVariable( $postvarname ) : array(); 00366 00367 $group = $rootGroup->findGroup( $groupID ); 00368 00369 if ( $group ) 00370 { 00371 $group->removeMultiOptions( $array_remove ); 00372 $rootGroup->cleanupRules(); 00373 if ( count( $group->attribute( 'multioption_list') ) == 0 ) 00374 { 00375 $rootGroup->removeChildGroup( $group->attribute( 'group_id' ) ); 00376 } 00377 $contentObjectAttribute->setContent( $rootGroup ); 00378 $contentObjectAttribute->store(); 00379 } 00380 00381 } 00382 else if ( $actionlist[0] == "switch-mode" ) 00383 { 00384 $editMode = $actionlist[1]; 00385 $sessionVarName = 'eZEnhancedMultioption_edit_mode_' . $contentObjectAttribute->attribute( 'id' ); 00386 $http->setSessionVariable( $sessionVarName, $editMode ); 00387 $rootGroup = $contentObjectAttribute->content(); 00388 $contentObjectAttribute->setContent( $rootGroup ); 00389 } 00390 else if ( $actionlist[0] == "reset-rules" ) 00391 { 00392 $rootGroup = $contentObjectAttribute->content(); 00393 $rootGroup->Rules = array(); 00394 $contentObjectAttribute->setContent( $rootGroup ); 00395 $contentObjectAttribute->store(); 00396 00397 } 00398 else if ( $actionlist[0] == "set-object" ) 00399 { 00400 00401 if ( $http->hasPostVariable( 'BrowseActionName' ) and 00402 $http->postVariable( 'BrowseActionName' ) == ( 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ) ) and 00403 $http->hasPostVariable( "SelectedObjectIDArray" ) ) 00404 { 00405 if ( !$http->hasPostVariable( 'BrowseCancelButton' ) ) 00406 { 00407 $selectedObjectArray = $http->hasPostVariable( "SelectedObjectIDArray" ); 00408 $selectedObjectIDArray = $http->postVariable( "SelectedObjectIDArray" ); 00409 $rootGroup = $contentObjectAttribute->content(); 00410 $groupID = $actionlist[1]; 00411 $multioptionID = $actionlist[2]; 00412 $optionID = $actionlist[3]; 00413 00414 $objectID = $selectedObjectIDArray[0]; 00415 00416 $rootGroup->setObjectForOption( $multioptionID, $optionID, $objectID ); 00417 $contentObjectAttribute->setContent( $rootGroup ); 00418 $contentObjectAttribute->store(); 00419 00420 } 00421 } 00422 } 00423 else if ( $actionlist[0] == "browse-object" ) 00424 { 00425 $module = $parameters['module']; 00426 00427 $redirectionURI = $parameters['current-redirection-uri']; 00428 $ini = eZINI::instance( 'content.ini' ); 00429 00430 $browseType = 'AddRelatedObjectToDataType'; 00431 $browseTypeINIVariable = $ini->variable( 'ObjectRelationDataTypeSettings', 'ClassAttributeStartNode' ); 00432 foreach( $browseTypeINIVariable as $value ) 00433 { 00434 list( $classAttributeID, $type ) = explode( ';',$value ); 00435 if ( $classAttributeID == $contentObjectAttribute->attribute( 'contentclassattribute_id' ) && strlen( $type ) > 0 ) 00436 { 00437 $browseType = $type; 00438 break; 00439 } 00440 } 00441 eZContentBrowse::browse( array( 'action_name' => 'AddRelatedObject_' . $contentObjectAttribute->attribute( 'id' ), 00442 'type' => $browseType, 00443 'browse_custom_action' => array( 'name' => 'CustomActionButton[' . $contentObjectAttribute->attribute( 'id' ) . 00444 '_set-object_'. $actionlist[1] . '_' . $actionlist[2] . '_' .$actionlist[3] . ']', 00445 'value' => $contentObjectAttribute->attribute( 'id' ) ), 00446 'persistent_data' => array( 'HasObjectInput' => 0 ), 00447 'from_page' => $redirectionURI ), 00448 $module ); 00449 00450 } 00451 else if ( $actionlist[0] == "remove-object" ) 00452 { 00453 00454 00455 $rootGroup = $contentObjectAttribute->content(); 00456 $groupID = $actionlist[1]; 00457 $multioptionID = $actionlist[2]; 00458 $optionID = $actionlist[3]; 00459 00460 $rootGroup->removeObjectFromOption( $multioptionID, $optionID ); 00461 00462 $contentObjectAttribute->setContent( $rootGroup ); 00463 $contentObjectAttribute->store(); 00464 00465 00466 } 00467 else 00468 { 00469 eZDebug::writeError( "Unknown custom HTTP action: " . $action, "eZMultiOptionType" ); 00470 } 00471 } 00472 00473 /*! 00474 Finds the option which has the correct ID , if found it returns an option structure. 00475 */ 00476 function productOptionInformation( $objectAttribute, $optionID, $productItem ) 00477 { 00478 $optiongroup = $objectAttribute->attribute( 'content' ); 00479 00480 $option = $optiongroup->findOption( false, $optionID ); 00481 if ( $option ) 00482 { 00483 return array( 'id' => $option['option_id'], 00484 'name' => $option['multioption_name'], 00485 'value' => $option['value'], 00486 'additional_price' => $option['additional_price'] ); 00487 } 00488 return null; 00489 } 00490 00491 00492 /*! 00493 \return \c true if there are more than one multioption in the list. 00494 */ 00495 function hasObjectAttributeContent( $contentObjectAttribute ) 00496 { 00497 $groups = $contentObjectAttribute->content(); 00498 $grouplist = $groups->attribute( 'optiongroup_list' ); 00499 return count( $grouplist ) > 0; 00500 } 00501 00502 /*! 00503 Sets default multioption values. 00504 */ 00505 function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute ) 00506 { 00507 if ( $currentVersion == false ) 00508 { 00509 $optiongroup = $contentObjectAttribute->content(); 00510 if ( $optiongroup ) 00511 { 00512 $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); 00513 $optiongroup->setName( $contentClassAttribute->attribute( 'data_text1' ) ); 00514 $contentObjectAttribute->setAttribute( "data_text", $optiongroup->xmlString() ); 00515 $contentObjectAttribute->setContent( $optiongroup ); 00516 } 00517 } 00518 else 00519 { 00520 $dataText = $originalContentObjectAttribute->attribute( "data_text" ); 00521 $contentObjectAttribute->setAttribute( "data_text", $dataText ); 00522 } 00523 } 00524 00525 function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) 00526 { 00527 return false; 00528 } 00529 00530 00531 /*! 00532 Validates the input for an object attribute during add to basket process 00533 and returns a validation state as defined in eZInputValidator. 00534 */ 00535 function validateAddToBasket( $objectAttribute, $data, &$errors ) 00536 { 00537 00538 $optiongroup = $objectAttribute->attribute( 'content' ); 00539 $rules = $optiongroup->Rules; 00540 00541 $validationErrors = array(); 00542 00543 00544 foreach( $data as $moptionID => $selectedItem ) 00545 { 00546 $failedOptionData = $optiongroup->findMultiOption( $moptionID ); 00547 $failedMultiOption = $failedOptionData['group']->Options[$failedOptionData['id']]; 00548 $failedOption = $optiongroup->findOption( $failedMultiOption, $selectedItem ); 00549 if ( $failedOption['is_selectable'] != 1 ) 00550 { 00551 $objectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00552 "You cannot choose option value \"%1\" from \"%2\" because it is unselectable " ), 00553 $failedOption['value'], 00554 $failedMultiOption['name'] ); 00555 $validationErrors[] = $objectAttribute->attribute( 'validation_error' ); 00556 } 00557 if ( ! isset( $rules[$selectedItem] ) ) 00558 continue; 00559 00560 $rulesForOption = $rules[$selectedItem]; 00561 foreach( array_keys( $rulesForOption ) as $ruleKey ) 00562 { 00563 00564 if ( isset( $data[$ruleKey] ) ) 00565 { 00566 $selectedMultioptionValue = $data[$ruleKey]; 00567 $canSelectIfIdArray = $rulesForOption[$ruleKey]; 00568 if ( !in_array( $data[$ruleKey], $canSelectIfIdArray ) ) 00569 { 00570 $wrongParentData = $optiongroup->findMultiOption( $ruleKey ); 00571 $wrongParentMultiOption = $wrongParentData['group']->Options[$wrongParentData['id']]; 00572 00573 $wrongParentOptionID = $data[$ruleKey]; 00574 $wrongParentOption = $optiongroup->findOption( $wrongParentMultiOption, $wrongParentOptionID ); 00575 00576 $objectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 00577 "You cannot choose option value \"%1\" from \"%2\" \n if you selected option \"%3\" from \"%4\" " ), 00578 $failedOption['value'], 00579 $failedMultiOption['name'], 00580 $wrongParentOption['value'], 00581 $wrongParentMultiOption['name'] ); 00582 $validationErrors[] = $objectAttribute->attribute( 'validation_error' ); 00583 00584 } 00585 } 00586 } 00587 } 00588 00589 if ( count( $validationErrors ) > 0 ) 00590 { 00591 $errors = $validationErrors; 00592 return eZInputValidator::STATE_INVALID; 00593 } 00594 return eZInputValidator::STATE_ACCEPTED; 00595 } 00596 00597 /*! 00598 \return true if the datatype requires validation during add to basket procedure 00599 */ 00600 function isAddToBasketValidationRequired() 00601 { 00602 return true; 00603 } 00604 00605 function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00606 { 00607 $defaultValue = $classAttribute->attribute( 'data_text1' ); 00608 $dom = $attributeParametersNode->ownerDocument; 00609 $defaultValueNode = $dom->createElement( 'default-value' ); 00610 $defaultValueNode->appendChild( $dom->createTextNode( $defaultValue ) ); 00611 $attributeParametersNode->appendChild( $defaultValueNode ); 00612 } 00613 00614 function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode ) 00615 { 00616 $defaultValue = $attributeParametersNode->getElementsByTagName( 'default-value' )->item( 0 )->textContent; 00617 $classAttribute->setAttribute( 'data_text1', $defaultValue ); 00618 } 00619 00620 function serializeContentObjectAttribute( $package, $objectAttribute ) 00621 { 00622 $node = $this->createContentObjectAttributeDOMNode( $objectAttribute ); 00623 00624 $dom = new DOMDocument( '1.0', 'utf-8' ); 00625 $success = $dom->loadXML( $objectAttribute->attribute( 'data_text' ) ); 00626 00627 $importedNode = $node->ownerDocument->importNode( $dom->documentElement, true ); 00628 $node->appendChild( $importedNode ); 00629 00630 return $node; 00631 } 00632 00633 function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode ) 00634 { 00635 $rootNode = $attributeNode->getElementsByTagName( 'ezmultioption2' )->item( 0 ); 00636 $xmlString = $attributeNode->ownerDocument->saveXML( $rootNode ); 00637 $objectAttribute->setAttribute( 'data_text', $xmlString ); 00638 } 00639 00640 /*! 00641 \return the template name to use for editing the attribute. 00642 \note Default is to return the datatype string which is OK 00643 for most datatypes, if you want dynamic templates 00644 reimplement this function and return a template name. 00645 \note The returned template name does not include the .tpl extension. 00646 \sa viewTemplate, informationTemplate 00647 */ 00648 function editTemplate( $contentObjectAttribute ) 00649 { 00650 $http = eZHTTPTool::instance(); 00651 $sessionVarName = 'eZEnhancedMultioption_edit_mode_' . $contentObjectAttribute->attribute( 'id' ); 00652 if ( $http->hasSessionVariable( $sessionVarName ) && $http->sessionVariable( $sessionVarName ) == 'rules' ) 00653 { 00654 return $this->DataTypeString . '_rules'; 00655 } 00656 return $this->DataTypeString; 00657 } 00658 00659 function supportsBatchInitializeObjectAttribute() 00660 { 00661 return true; 00662 } 00663 00664 function batchInitializeObjectAttributeData( $classAttribute ) 00665 { 00666 $optionGroup = new eZMultiOption2( $classAttribute->attribute( 'data_text1' ) ); 00667 $db = eZDB::instance(); 00668 return array( 'data_text' => "'" . $db->escapeString( $optionGroup->xmlString() ) . "'" ); 00669 } 00670 } 00671 00672 eZDataType::register( eZMultiOption2Type::DATA_TYPE_STRING, "eZMultiOption2Type" ); 00673 00674 ?>