56 $this->CategoryAccess =
get_package(
'category::category_access' ,
'last' , __FILE__ );
58 $this->Link =
get_package(
'link' ,
'last' , __FILE__ );
60 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
98 $ReturnItems = array();
100 foreach( $AllItems as $k => $v )
102 if(
get_field( $v ,
'root_id' ) == $RootId )
104 $ReturnItems [] = $v;
108 return( $ReturnItems );
110 catch( Exception $e )
146 $ReturnItems = array();
147 $CurrentId = $LeafId;
153 foreach( $AllItems as $k => $v )
155 if( $v->id == $CurrentId )
157 $ReturnItems [] = $v;
158 $CurrentId = $v->root_id;
166 return( array_reverse( isset( $ReturnItems[ 1 ] ) ? $ReturnItems : array() ) );
168 catch( Exception $e )
204 $Links = $this->Link->get_links( $MasterId ,
false , $MasterType ,
'category' );
208 if( isset( $CategoryIds[ 0 ] ) )
210 $CategoryIds = implode(
',' , $CategoryIds );
212 return( $this->CategoryAccess->unsafe_select(
"id IN ( $CategoryIds )" ) );
219 catch( Exception $e )
251 $id = $this->Security->get( $id ,
'integer' );
253 $Users = $this->CategoryAccess->unsafe_select( $this->CategoryAccess->NativeTable.
".id = $id" );
255 if( count( $Users ) === 0 || count( $Users ) > 1 )
257 throw(
new Exception(
'Category with id '.$id.
' was not found' ) );
261 return( $Users[ 0 ] );
264 catch( Exception $e )
296 $id = $this->Security->get( $id ,
'integer' );
298 $Records = $this->CategoryAccess->unsafe_select( $this->CategoryAccess->NativeTable.
".id = $id" );
300 return( count( $Records ) === 1 );
302 catch( Exception $e )
334 $id = $this->CategoryAccess->create( $Record );
336 if(
get_field( $Record ,
'direct_category' ,
false ) ===
false )
338 $RootId =
get_field( $Record ,
'root_id' );
342 $RootCategory = $this->
get_by_id( $RootId );
343 $DirectCategory =
get_field( $RootCategory ,
'direct_category' );
344 $this->CategoryAccess->update( $id , array(
'direct_category' => $DirectCategory ) );
350 catch( Exception $e )
386 $cid = $this->Security->get( $cid ,
'integer' );
387 $Title = $this->Security->get( $Title ,
'string' );
389 $this->CategoryAccess->update( $cid , array(
'title' => $Title ) );
391 catch( Exception $e )
428 if( is_string( $Names ) )
430 $Names = explode(
',' , $Names );
435 foreach( $Names as $k => $v )
437 $Ids [] = $this->CategoryAccess->get_category_id( $v );
442 catch( Exception $e )
474 $id = $this->CategoryAccess->get_category_id( $Name );
476 return( $this->CategoryAccess->get_children( $id ) );
478 catch( Exception $e )
510 $id = $this->CategoryAccess->get_category_id( $Name );
512 return( $this->CategoryAccess->select_categories_list( $id ) );
514 catch( Exception $e )