81 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
82 $this->DatabaseAlgorithms =
get_package(
'database::database_algorithms' ,
'last' , __FILE__ );
83 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
84 $this->SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
126 if( $this->AddLimitations ===
'1 = 1' )
128 $this->AddLimitations = $theAddLimitation;
132 throw(
new Exception(
'"AddLimitations" was already set' ) );
135 catch( Exception $e )
167 $Script =
'title:string;root_id:integer;direct_category:integer,default_0,allow_not_set;'.
168 'mask:integer,default_0,allow_not_set';
169 $Record = $this->SecurityParser->parse_parameters( $Record , $Script );
171 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
173 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
175 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
176 $EventManager->trigger_event(
'on_after_create_category' , array(
'id' => $id ) );
180 catch( Exception $e )
212 $id = $this->Security->get( $id ,
'integer_list' );
214 $Script =
'title:string;root_id:integer;direct_category:integer;mask:integer';
216 $Record = $this->SecurityParser->parse_parameters( $Record , $Script ,
'allow_not_set' );
218 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
220 if( isset( $Fields[ 0 ] ) )
222 $Condition =
"( $this->AddLimitations ) AND id IN ( $id )";
224 $this->Database->update( $this->NativeTable , $Fields , $Values , $Condition );
226 $this->Database->commit();
229 catch( Exception $e )
261 $id = $this->Security->get( $id ,
'integer_list' );
263 return( $this->
unsafe_select( $this->NativeTable.
".id IN ( $id )" ) );
265 catch( Exception $e )
289 function delete( $cid )
293 $cid = $this->Security->get( $cid ,
'integer_list' );
295 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
296 $EventManager->trigger_event(
'on_before_delete_category' , array(
'id' => $cid ) );
298 $this->Database->delete(
'umx_category' ,
"( $this->AddLimitations ) AND id IN ( $cid )" );
299 $this->Database->commit();
301 $EventManager =
get_package(
'event_manager' ,
'last' , __FILE__ );
302 $EventManager->trigger_event(
'on_after_delete_category' , array(
'id' => $cid ) );
304 catch( Exception $e )
332 $cid = $this->Security->get( $cid ,
'integer_list' );
334 $NewRootId = $this->Security->get( $NewRootId ,
'integer' );
336 $Condition =
"( $this->AddLimitations ) AND root_id IN ( $cid )";
338 $this->Database->update( $this->NativeTable , array(
'root_id' ) , array( $NewRootId ) , $Condition );
340 $this->Database->commit();
342 catch( Exception $e )
376 return( $this->Database->select(
'*' ,
'umx_category' ,
"( $this->AddLimitations ) AND $Condition" ) );
378 catch( Exception $e )
406 private function get_fetch_parameters( $Condition )
410 $Fields =
'umx_category.id AS cid , umx_category.title AS ctitle , c2.title AS croot_title , '.
411 'c3.title AS cdirect_title , umx_category.mask AS cmask , umx_category.category_name '.
414 $Tables =
'umx_category , umx_category AS c2 , umx_category AS c3';
416 $Condition =
'( ( umx_category.root_id = c2.id AND umx_category.direct_category = c3.id ) OR '.
417 "( umx_category.id = c2.id AND c2.id = c3.id AND umx_category.root_id = 0 ) ) AND $Condition";
419 return( array( $Fields , $Tables , $Condition ) );
421 catch( Exception $e )
465 function select( $Start , $Limit , $Field =
false , $Order =
false , $Condition =
'1 = 1' )
469 $Condition = $this->DatabaseAlgorithms->select_condition(
470 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
475 list( $Fields , $Tables , $Condition ) = $this->get_fetch_parameters( $Condition );
477 return( $this->Database->select( $Fields , $Tables , $Condition ) );
479 catch( Exception $e )
511 if( $this->Dictionary ===
false )
513 $this->Dictionary = $this->
unsafe_select(
'category_name IS NOT NULL' );
516 foreach( $this->Dictionary as $k => $v )
518 if(
get_field( $v ,
'category_name' ) == $Name )
524 throw(
new Exception(
"Category with name '$Name' was not found" ) );
526 catch( Exception $e )
558 $id = $this->Security->get( $id ,
'integer' );
560 return( $this->
unsafe_select(
"root_id = $id ORDER BY title" ) );
562 catch( Exception $e )
594 $id = $this->Security->get( $id ,
'integer' );
596 return( count( $this->
unsafe_select(
"root_id = $id ORDER BY title" ) ) );
598 catch( Exception $e )
630 $ids = $this->Security->get( $id ,
'integer' );
636 $Children = $this->
unsafe_select(
"root_id IN ( $ids ) ORDER BY title" );
638 if( isset( $Children[ 0 ] ) )
640 $Siblings = array_merge( $Siblings , $Children );
644 $ids = implode(
',' , $ids );
652 catch( Exception $e )
684 $ids = $this->Security->get( $id ,
'integer' );
686 $SiblingsIds = array();
690 $Children = $this->
unsafe_select(
"root_id IN ( $ids ) ORDER BY title" );
692 if( isset( $Children[ 0 ] ) )
696 $SiblingsIds = array_merge( $SiblingsIds , $ids );
698 $ids = implode(
',' , $ids );
702 return( $SiblingsIds );
706 catch( Exception $e )
738 $id = $this->Security->get( $id ,
'integer' );
740 return( $this->
unsafe_select(
"direct_category = $id ORDER BY title" ) );
742 catch( Exception $e )