ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

graph_data_access.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 graph_data_access_1_0_0{
27
38 var $NativeTable = '`umx_graph_data`';
39
50 var $Database = false;
51 var $DatabaseAlgorithms = false;
52 var $Security = false;
53 var $SecurityParser = false;
54 var $UserAlgorithms = false;
55
66 function __construct()
67 {
68 try
69 {
70 $this->Database = get_package( 'database' , 'last' , __FILE__ );
71 $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
72 $this->Security = get_package( 'security' , 'last' , __FILE__ );
73 $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
74 $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
75 }
76 catch( Exception $e )
77 {
78 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
79 }
80 }
81
92 var $AddLimitations = '1 = 1';
93
112 function set_add_limitations( $theAddLimitation )
113 {
114 try
115 {
116 if( $this->AddLimitations === '1 = 1' )
117 {
118 $this->AddLimitations = $theAddLimitation;
119 }
120 else
121 {
122 throw( new Exception( '"AddLimitations" was already set' ) );
123 }
124 }
125 catch( Exception $e )
126 {
127 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
128 }
129 }
130
153 function unsafe_select( $Condition , $Fields = false )
154 {
155 try
156 {
157 $this->Database->query_as( DB_OBJECT );
158
159 return(
160 $this->Database->select(
161 $Fields === false ? $this->NativeTable.'.*' : $Fields , $this->NativeTable ,
162 "( $this->AddLimitations ) AND $Condition"
163 )
164 );
165 }
166 catch( Exception $e )
167 {
168 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
169 }
170 }
171
194 private function fetch_create_parameters( $Record )
195 {
196 try
197 {
198 if( get_field( $Record , 'author' , false ) === false )
199 {
200 set_field( $Record , 'author' , $this->UserAlgorithms->get_id() );
201 }
202
203 $Record = $this->SecurityParser->parse_parameters(
204 $Record , 'author:integer;graph_type:integer;ordinatus:float;abscissa:integer'
205 );
206
207 return( $this->DatabaseAlgorithms->compile_fields_values( $Record ) );
208 }
209 catch( Exception $e )
210 {
211 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
212 }
213 }
214
237 function create( $Record )
238 {
239 try
240 {
241 list( $Fields , $Values ) = $this->fetch_create_parameters( $Record );
242
243 $this->Database->delete(
244 $this->NativeTable , "( $this->AddLimitations ) AND abscissa = ".get_field( $Record , 'abscissa' ).
245 ' AND graph_type = '.get_field( $Record , 'graph_type' )
246 );
247 $this->Database->commit();
248
249 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
250
251 $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
252 $EventManager->trigger_event( 'on_after_create_graph_data' , array( 'id' => $id ) );
253
254 return( $id );
255 }
256 catch( Exception $e )
257 {
258 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
259 }
260 }
261 }
262
263 ?>