ultimix
category_algorithms_1_0_0 Class Reference

Public Member Functions

 __construct ()
 get_children ($RootId, &$AllItems)
 get_previous_items ($AllItems, $LeafId)
 get_object_categories ($MasterId, $MasterType)
 get_by_id ($id)
 object_exists ($id)
 create ($Record)
 update_category_title ($cid, $Title)
 get_category_ids ($Names)
 get_children_by_name ($Name)
 select_categories_list_by_name ($Name)

Data Fields

 $CategoryAccess = false
 $Link = false
 $Security = false

Detailed Description

Working with algorithms.

Author
Dodonov A.A.

Definition at line 26 of file category_algorithms.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Author
Dodonov A.A.

Definition at line 52 of file category_algorithms.php.

{
try
{
$this->CategoryAccess = get_package( 'category::category_access' , 'last' , __FILE__ );
$this->Link = get_package( 'link' , 'last' , __FILE__ );
$this->Security = get_package( 'security' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

create (   $Record)

Creating record.

Parameters
$RecordExample for creation.
Returns
id of the created record.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 330 of file category_algorithms.php.

{
try
{
$id = $this->CategoryAccess->create( $Record );
if( get_field( $Record , 'direct_category' , false ) === false )
{
$RootId = get_field( $Record , 'root_id' );
if( $this->object_exists( $RootId ) )
{
$RootCategory = $this->get_by_id( $RootId );
$DirectCategory = get_field( $RootCategory , 'direct_category' );
$this->CategoryAccess->update( $id , array( 'direct_category' => $DirectCategory ) );
}
}
return( $id );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_by_id (   $id)

Function returns category by it's id.

Parameters
$id- Id of the searching category.
Returns
Category object.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 247 of file category_algorithms.php.

{
try
{
$id = $this->Security->get( $id , 'integer' );
$Users = $this->CategoryAccess->unsafe_select( $this->CategoryAccess->NativeTable.".id = $id" );
if( count( $Users ) === 0 || count( $Users ) > 1 )
{
throw( new Exception( 'Category with id '.$id.' was not found' ) );
}
else
{
return( $Users[ 0 ] );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_category_ids (   $Names)

Function returns ids of the categories by their names.

Parameters
$Names- Names.
Returns
Ids.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 419 of file category_algorithms.php.

{
try
{
if( $Names == '' )
{
return( array() );
}
if( is_string( $Names ) )
{
$Names = explode( ',' , $Names );
}
$Ids = array();
foreach( $Names as $k => $v )
{
$Ids [] = $this->CategoryAccess->get_category_id( $v );
}
return( $Ids );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_children (   $RootId,
$AllItems 
)

Function returns children.

Parameters
$RootId- id of the tree's root.
$AllItems- All elements of the tree.
Returns
List of children.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 94 of file category_algorithms.php.

{
try
{
$ReturnItems = array();
foreach( $AllItems as $k => $v )
{
if( get_field( $v , 'root_id' ) == $RootId )
{
$ReturnItems [] = $v;
}
}
return( $ReturnItems );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_children_by_name (   $Name)

Function returns subcategories.

Parameters
$Name- Name of the category.
Returns
Subcategories.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 470 of file category_algorithms.php.

{
try
{
$id = $this->CategoryAccess->get_category_id( $Name );
return( $this->CategoryAccess->get_children( $id ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_object_categories (   $MasterId,
  $MasterType 
)

Function returns object's categories.

Parameters
$MasterId- Master object's id.
$MasterType- Master object's type.
Returns
Records.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 200 of file category_algorithms.php.

{
try
{
$Links = $this->Link->get_links( $MasterId , false , $MasterType , 'category' );
$CategoryIds = get_field_ex( $Links , 'object2_id' );
if( isset( $CategoryIds[ 0 ] ) )
{
$CategoryIds = implode( ',' , $CategoryIds );
return( $this->CategoryAccess->unsafe_select( "id IN ( $CategoryIds )" ) );
}
else
{
return( array() );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_previous_items (   $AllItems,
  $LeafId 
)

Function returns subtree.

Parameters
$AllItems- all elements of the tree.
$LeafId- id of the leaf.
Returns
List of parents.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 142 of file category_algorithms.php.

{
try
{
$ReturnItems = array();
$CurrentId = $LeafId;
$ItemFound = false;
do
{
$ItemFound = false;
foreach( $AllItems as $k => $v )
{
if( $v->id == $CurrentId )
{
$ReturnItems [] = $v;
$CurrentId = $v->root_id;
$ItemFound = true;
break;
}
}
}
while( $ItemFound );
return( array_reverse( isset( $ReturnItems[ 1 ] ) ? $ReturnItems : array() ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
object_exists (   $id)

Function validates object's existense.

Parameters
$id- Record's id.
Returns
true if the object exists.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 292 of file category_algorithms.php.

{
try
{
$id = $this->Security->get( $id , 'integer' );
$Records = $this->CategoryAccess->unsafe_select( $this->CategoryAccess->NativeTable.".id = $id" );
return( count( $Records ) === 1 );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
select_categories_list_by_name (   $Name)

Function returns all subcategories.

Parameters
$Name- Name of the category.
Returns
Subcategories.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 506 of file category_algorithms.php.

{
try
{
$id = $this->CategoryAccess->get_category_id( $Name );
return( $this->CategoryAccess->select_categories_list( $id ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
update_category_title (   $cid,
  $Title 
)

Updating records.

Parameters
$cid- Record's id.
$Title- Category's title.
Returns
Record.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 382 of file category_algorithms.php.

{
try
{
$cid = $this->Security->get( $cid , 'integer' );
$Title = $this->Security->get( $Title , 'string' );
$this->CategoryAccess->update( $cid , array( 'title' => $Title ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$CategoryAccess = false

Cached objects.

Author
Dodonov A.A.

Definition at line 38 of file category_algorithms.php.

$Link = false

Definition at line 39 of file category_algorithms.php.

$Security = false

Definition at line 40 of file category_algorithms.php.


The documentation for this class was generated from the following file: