Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezrangeoption.php
Go to the documentation of this file.
1 <?php
18 class eZRangeOption
19 {
25 public function __construct( $name )
26 {
27 $this->Name = $name;
28 $this->Options = array();
29 $this->OptionCount = 0;
30 }
31
35 function setName( $name )
36 {
37 $this->Name = $name;
38 }
39
43 function name()
44 {
45 return $this->Name;
46 }
47
51 function attributes()
52 {
53 return array( 'name',
54 'start_value',
55 'stop_value',
56 'step_value',
57 'option_list' );
58 }
59
60 function hasAttribute( $name )
61 {
62 return in_array( $name, $this->attributes() );
63 }
64
65 function attribute( $name )
66 {
67 switch ( $name )
68 {
69 case "name" :
70 {
71 return $this->Name;
72 }break;
73 case "start_value" :
74 {
75 return $this->StartValue;
76 }break;
77 case "stop_value" :
78 {
79 return $this->StopValue;
80 }break;
81 case "step_value" :
82 {
83 return $this->StepValue;
84 }break;
85 case "option_list" :
86 {
87 return $this->Options;
88 }break;
89 default:
90 {
91 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
92 return null;
93 }break;
94 }
95 }
96
97 function addOption( $valueArray )
98 {
99 $this->Options[] = array( "id" => $this->OptionCount,
100 "value" => $valueArray['value'],
101 'additional_price' => 0,
102 "is_default" => false );
103
104 $this->OptionCount += 1;
105 }
106
107 function decodeXML( $xmlString )
108 {
109 $dom = new DOMDocument( '1.0', 'utf-8' );
110 $success = $dom->loadXML( $xmlString );
111
112 if ( $xmlString != "" )
113 {
114 // set the name of the node
115 $rangeOptionElement = $dom->documentElement;
116 $startValue = $rangeOptionElement->getAttribute( 'start_value' );
117 $stopValue = $rangeOptionElement->getAttribute( 'stop_value' );
118 $stepValue = $rangeOptionElement->getAttribute( 'step_value' );
119 if ( $stepValue == 0 )
120 $stepValue = 1;
121 $this->StartValue = $startValue;
122 $this->StopValue = $stopValue;
123 $this->StepValue = $stepValue;
124
125
126 $nameNode = $dom->getElementsByTagName( "name" )->item( 0 );
127 $this->setName( $nameNode->textContent );
128
129 for ( $i = $startValue; $i <= $stopValue; $i += $stepValue )
130 {
131 $this->addOption( array( 'value' => $i,
132 'additional_price' => 0 ) );
133 }
134 }
135 else
136 {
137 $this->StartValue = 0;
138 $this->StopValue = 0;
139 $this->StepValue = 0;
140 }
141 }
142
146 function xmlString( )
147 {
148 $doc = new DOMDocument( '1.0', 'utf-8' );
149
150 $root = $doc->createElement( "ezrangeoption" );
151 $root->setAttribute( "start_value", $this->StartValue );
152 $root->setAttribute( "stop_value", $this->StopValue );
153 $root->setAttribute( "step_value", $this->StepValue );
154 $doc->appendChild( $root );
155
156 $name = $doc->createElement( "name", $this->Name );
157 $root->appendChild( $name );
158
159 $xml = $doc->saveXML();
160
161 return $xml;
162 }
163
164 function setStartValue( $value )
165 {
166 $this->StartValue = $value;
167 }
168
169 function setStopValue( $value )
170 {
171 $this->StopValue = $value;
172 }
173
174 function setStepValue( $value )
175 {
176 $this->StepValue = $value;
177 }
178
179
181 public $Name;
182
184 public $Options;
185
187 public $OptionCount;
188 public $StartValue;
189 public $StopValue;
190 public $StepValue;
191 }
192
193 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZRangeOption
The class eZRangeOption does.
Definition: ezrangeoption.php:19
eZRangeOption\name
name()
Definition: ezrangeoption.php:43
eZRangeOption\setStartValue
setStartValue( $value)
Definition: ezrangeoption.php:164
eZRangeOption\setStepValue
setStepValue( $value)
Definition: ezrangeoption.php:174
eZRangeOption\$Name
$Name
Contains the Option name.
Definition: ezrangeoption.php:181
eZRangeOption\$StepValue
$StepValue
Definition: ezrangeoption.php:190
eZRangeOption\attributes
attributes()
Definition: ezrangeoption.php:51
eZRangeOption\hasAttribute
hasAttribute( $name)
Definition: ezrangeoption.php:60
eZRangeOption\xmlString
xmlString()
Definition: ezrangeoption.php:146
eZRangeOption\addOption
addOption( $valueArray)
Definition: ezrangeoption.php:97
eZRangeOption\attribute
attribute( $name)
Definition: ezrangeoption.php:65
eZRangeOption\$OptionCount
$OptionCount
Contains the option counter value.
Definition: ezrangeoption.php:187
eZRangeOption\decodeXML
decodeXML( $xmlString)
Definition: ezrangeoption.php:107
eZRangeOption\$Options
$Options
Contains the Options.
Definition: ezrangeoption.php:184
eZRangeOption\__construct
__construct( $name)
Definition: ezrangeoption.php:25
eZRangeOption\setName
setName( $name)
Definition: ezrangeoption.php:35
eZRangeOption\setStopValue
setStopValue( $value)
Definition: ezrangeoption.php:169
eZRangeOption\$StartValue
$StartValue
Definition: ezrangeoption.php:188
eZRangeOption\$StopValue
$StopValue
Definition: ezrangeoption.php:189
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.