71 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
72 $this->DatabaseAlgorithms =
get_package(
'database::database_algorithms' ,
'last' , __FILE__ );
73 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
74 $this->SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
75 $this->UserAccess =
get_package(
'user::user_access' ,
'last' , __FILE__ );
76 $this->UserAlgorithms =
get_package(
'user::user_algorithms' ,
'last' , __FILE__ );
118 if( $this->AddLimitations ===
'1 = 1' )
120 $this->AddLimitations = $theAddLimitation;
124 throw(
new Exception(
'"AddLimitations" was already set' ) );
127 catch( Exception $e )
162 $this->Database->select(
163 $this->UserAccess->NativeTable.
'.* , '.$this->NativeTable.
164 '.id , rank , review , page , creation_date , author' ,
165 $this->NativeTable.
' , '.$this->UserAccess->NativeTable ,
166 $this->NativeTable.
'.author = '.$this->UserAccess->NativeTable.
".id
167 AND ( $this->AddLimitations ) AND $Condition"
171 catch( Exception $e )
215 function select( $Start =
false , $Limit =
false , $Field =
false ,
216 $Order =
false , $Condition =
'1 = 1' )
220 $Condition = $this->DatabaseAlgorithms->select_condition(
221 $Start , $Limit , $Field ===
false ? $this->NativeTable.
'.id' : $Field ,
222 $Order , $Condition , $this->NativeTable
227 catch( Exception $e )
255 function delete( $id , $Options =
' 1 = 1' )
260 $Link->delete_link(
false , $id ,
false ,
'review' );
262 $id = $this->Security->get( $id ,
'integer_list' );
263 $this->Database->delete( $this->NativeTable ,
"( $this->AddLimitations ) AND id IN ( $id )" );
264 $this->Database->commit();
266 catch( Exception $e )
294 private function fetch_data( $Record )
298 $MasterLink = $this->SecurityParser->parse_parameters(
299 $Record ,
'master_type:command;master_id:integer'
302 $Record = $this->SecurityParser->parse_parameters(
303 $Record ,
'rank:integer,min_-5,max_5;review:string'
305 set_field( $Record ,
'author' , $this->UserAlgorithms->get_id() );
306 set_field( $Record ,
'page' , $this->Security->get_srv(
'REQUEST_URI' ,
'string' ,
'./index.html' ) );
308 return( array( $MasterLink , $Record ) );
310 catch( Exception $e )
342 list( $MasterLink , $Record ) = $this->fetch_data( $Record );
344 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record ,
CREATION_DATE );
346 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
350 get_field( $MasterLink ,
'master_id' ) , $id ,
351 get_field( $MasterLink ,
'master_type' ) ,
'review'
354 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
355 $EventManager->trigger_event(
'on_after_create_review' , array(
'id' => $id ) );
359 catch( Exception $e )
391 $id = $this->Security->get( $id ,
'integer_list' );
392 $Record = $this->SecurityParser->parse_parameters(
393 $Record ,
'rank:integer;review:string' ,
'allow_not_set'
396 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
398 if( isset( $Fields[ 0 ] ) )
400 $this->Database->update(
401 $this->NativeTable , $Fields , $Values ,
"( $this->AddLimitations ) AND id IN ( $id )"
403 $this->Database->commit();
406 catch( Exception $e )
438 $id = $this->Security->get( $id ,
'integer_list' );
440 return( $this->
unsafe_select( $this->NativeTable.
".id IN ( $id ) ORDER BY creation_date ASC" ) );
442 catch( Exception $e )
478 $Type = $this->Security->get( $Type ,
'command' );
479 $id = $this->Security->get( $id ,
'command' );
481 $LinkDictionary =
get_package(
'link::link_dictionary' ,
'last' , __FILE__ );
482 $LinkType = $LinkDictionary->get_link_type( $Type ,
'review' );
484 $Records = $this->Database->select(
485 'SUM( '.$this->NativeTable.
'.rank ) AS total_rank' , $this->NativeTable.
' , umx_link' ,
486 "umx_link.type = $LinkType AND ".$this->NativeTable.
".id = umx_link.object2_id
487 AND umx_link.object1_id = $id AND ( $this->AddLimitations ) AND $Condition"
490 return( isset( $Records[ 0 ] ) ?
get_field( $Records[ 0 ] ,
'total_rank' ) : 0 );
492 catch( Exception $e )