ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

db_settings.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class db_settings_1_0_0{
27
38 var $NativeTable = '`umx_setting`';
39
50 var $Database = false;
51 var $DatabaseAlgorithms = false;
52 var $Security = false;
53 var $SecurityParser = false;
54
65 function __construct()
66 {
67 try
68 {
69 $this->Database = get_package( 'database' , 'last' , __FILE__ );
70 $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
71 $this->Security = get_package( 'security' , 'last' , __FILE__ );
72 $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
73 }
74 catch( Exception $e )
75 {
76 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
77 }
78 }
79
102 function unsafe_select( $Condition )
103 {
104 try
105 {
106 $this->Database->query_as( DB_OBJECT );
107
108 $Settings = $this->Database->select( '*' , $this->NativeTable , "$Condition" );
109
110 return( $Settings );
111 }
112 catch( Exception $e )
113 {
114 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
115 }
116 }
117
140 function create( $Record )
141 {
142 try
143 {
144 $Record = $this->SecurityParser->parse_parameters( $Record , 'name:string;value:string' );
145
146 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
147
148 $this->Database->lock( array( $this->NativeTable ) , array( 'WRITE' ) );
149
150 $this->Database->insert( $this->NativeTable , implode( ',' , $Fields ) , implode( ',' , $Values ) );
151 $this->Database->commit();
152
153 $id = $this->Database->select( '*' , $this->NativeTable , '1 = 1 ORDER by id DESC LIMIT 0 , 1' );
154 $id = get_field( $id[ 0 ] , 'id' );
155
156 $this->Database->unlock();
157
158 return( $id );
159 }
160 catch( Exception $e )
161 {
162 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
163 }
164 }
165
188 function get_setting( $SettingName , $DefaultValue = '_throw_exception' )
189 {
190 try
191 {
192 $SettingName = $this->Security->get( $SettingName , 'command' );
193 $Time = time();
194
195 $Settings = $this->unsafe_select(
196 "name LIKE '$SettingName' AND date_from <= $Time AND $Time <= date_to"
197 );
198
199 if( isset( $Settings[ 0 ] ) )
200 {
201 return( get_field( $Settings[ 0 ] , 'value' ) );
202 }
203 elseif( $DefaultValue === '_throw_exception' )
204 {
205 throw( new Exception( "Setting \"$SettingName\" was not found" ) );
206 }
207 else
208 {
209 return( $DefaultValue );
210 }
211 }
212 catch( Exception $e )
213 {
214 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
215 }
216 }
217
240 function set_setting( $SettingName , $Value )
241 {
242 try
243 {
244 $SettingName = $this->Security->get( $SettingName , 'command' );
245 $Time = time();
246
247 $Settings = $this->unsafe_select(
248 "name LIKE '$SettingName' AND date_from <= $Time AND $Time <= date_to"
249 );
250
251 if( isset( $Settings[ 0 ] ) )
252 {
253 $id = get_field( $Settings[ 0 ] , 'id' );
254 $Chronological = get_package( 'database::chronological' , 'last' , __FILE__ );
255 $Chronological->update_record(
256 $id , array( 'name' => get_field( $Settings[ 0 ] , 'name' ) , 'value' => $Value ) , $this
257 );
258 }
259 else
260 {
261 throw( new Exception( "Setting \"$SettingName\" was not found" ) );
262 }
263 }
264 catch( Exception $e )
265 {
266 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
267 }
268 }
269
288 function __toString()
289 {
290 try
291 {
292 return( serialize( $this->SettingsList ) );
293 }
294 catch( Exception $e )
295 {
296 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
297 }
298 }
299 }
300
301 ?>