Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezoption.php
Go to the documentation of this file.
1 <?php
28 class eZOption
29 {
35 public function __construct( $name )
36 {
37 $this->Name = $name;
38 $this->Options = array();
39 $this->OptionCount = 0;
40 }
41
45 function setName( $name )
46 {
47 $this->Name = $name;
48 }
49
50
54 function name()
55 {
56 return $this->Name;
57 }
58
62 function addOption( $valueArray )
63 {
64 $value = isset( $valueArray['value'] ) ? $valueArray['value'] : '';
65 $additional_price = isset( $valueArray['additional_price'] ) ? $valueArray['additional_price'] : '';
66 $this->Options[] = array( "id" => $this->OptionCount,
67 "value" => $value,
68 'additional_price' => $additional_price,
69 "is_default" => false );
70
71 $this->OptionCount += 1;
72 }
73
74 function insertOption( $valueArray, $beforeID )
75 {
76 array_splice( $this->Options, $beforeID, 0 , array( array( "id" => $this->OptionCount,
77 "value" => $valueArray['value'],
78 'additional_price' => $valueArray['additional_price'],
79 "is_default" => false ) ) );
80 $this->OptionCount += 1;
81 }
82
83 function removeOptions( $array_remove )
84 {
85 $shiftvalue = 0;
86 foreach( $array_remove as $id )
87 {
88 array_splice( $this->Options, $id - $shiftvalue, 1 );
89 $shiftvalue++;
90 }
91 $this->OptionCount -= $shiftvalue;
92 }
93
94 function attributes()
95 {
96 return array( 'name',
97 'option_list' );
98 }
99
100 function hasAttribute( $name )
101 {
102 return in_array( $name, $this->attributes() );
103 }
104
105 function attribute( $name )
106 {
107 switch ( $name )
108 {
109 case "name" :
110 {
111 return $this->Name;
112 }break;
113 case "option_list" :
114 {
115 return $this->Options;
116 }break;
117 default:
118 {
119 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
120 return null;
121 }break;
122 }
123 }
124
128 function decodeXML( $xmlString )
129 {
130 if ( $xmlString != "" )
131 {
132 $dom = new DOMDocument( '1.0', 'utf-8' );
133 $success = $dom->loadXML( $xmlString );
134
135 // set the name of the node
136 $nameNode = $dom->getElementsByTagName( "name" )->item( 0 );
137 $this->setName( $nameNode->textContent );
138
139 $optionNodes = $dom->getElementsByTagName( "option" );
140 $this->OptionCount = 0;
141
142 foreach ( $optionNodes as $optionNode )
143 {
144 $this->addOption( array( 'value' => $optionNode->textContent,
145 'additional_price' => $optionNode->getAttribute( 'additional_price' ) ) );
146 }
147 }
148 else
149 {
150 $this->addOption( "" );
151 $this->addOption( "" );
152 }
153 }
154
158 function xmlString( )
159 {
160 $doc = new DOMDocument( '1.0', 'utf-8' );
161
162 $root = $doc->createElement( "ezoption" );
163 $doc->appendChild( $root );
164
165 $name = $doc->createElement( "name" );
166 $name->appendChild( $doc->createCDATASection( $this->Name ) );
167 $root->appendChild( $name );
168
169 $options = $doc->createElement( "options" );
170 $root->appendChild( $options );
171
172 foreach ( $this->Options as $option )
173 {
174 $optionNode = $doc->createElement( "option" );
175 $optionNode->appendChild( $doc->createCDATASection( $option["value"] ) );
176 $optionNode->setAttribute( "id", $option['id'] );
177 $optionNode->setAttribute( 'additional_price', $option['additional_price'] );
178 $options->appendChild( $optionNode );
179 }
180
181 $xml = $doc->saveXML();
182
183 return $xml;
184 }
185
187 public $Name;
188
190 public $Options;
191
193 public $OptionCount;
194 }
195
196 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZOption
eZOption handles option set datatypes
Definition: ezoption.php:29
eZOption\attributes
attributes()
Definition: ezoption.php:94
eZOption\hasAttribute
hasAttribute( $name)
Definition: ezoption.php:100
eZOption\xmlString
xmlString()
Definition: ezoption.php:158
eZOption\__construct
__construct( $name)
Definition: ezoption.php:35
eZOption\name
name()
Definition: ezoption.php:54
eZOption\$Name
$Name
Contains the Option name.
Definition: ezoption.php:187
eZOption\attribute
attribute( $name)
Definition: ezoption.php:105
eZOption\decodeXML
decodeXML( $xmlString)
Definition: ezoption.php:128
eZOption\addOption
addOption( $valueArray)
Definition: ezoption.php:62
eZOption\removeOptions
removeOptions( $array_remove)
Definition: ezoption.php:83
eZOption\insertOption
insertOption( $valueArray, $beforeID)
Definition: ezoption.php:74
eZOption\$OptionCount
$OptionCount
Contains the option counter value.
Definition: ezoption.php:193
eZOption\setName
setName( $name)
Definition: ezoption.php:45
eZOption\$Options
$Options
Contains the Options.
Definition: ezoption.php:190
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.