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