ultimix
link_dictionary_1_0_0 Class Reference

Public Member Functions

 __construct ()
 get_type_from_cache ($Object1Type, $Object2Type)
 fill_cache ()
 get_type_from_db ($Object1Type, $Object2Type)
 create_link_type ($Object1Type, $Object2Type)
 get_link_type ($Object1Type, $Object2Type)
 get_link_literal_type (&$Type)

Data Fields

 $LinkTypesDictionary = false
 $Database = false
 $Security = false

Detailed Description

Class allows to create many-to-many links.

Author
Dodonov A.A.

Definition at line 26 of file link_dictionary.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 67 of file link_dictionary.php.

{
try
{
$this->Database = get_package( 'database' , '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_link_type (   $Object1Type,
  $Object2Type 
)

Function creates new link type.

Parameters
$Object1Type- Type of the first object.
$Object2Type- Type of the second object.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 230 of file link_dictionary.php.

{
try
{
$Object1Type = $this->Security->get( $Object1Type , 'string' );
$Object2Type = $this->Security->get( $Object2Type , 'string' );
$this->Database->lock( array( 'umx_link_dictionary' ) , array( 'WRITE' ) );
$this->Database->insert( 'umx_link_dictionary' , 'object1_type , object2_type' ,
"'$Object1Type' , '$Object2Type'" );
$this->Database->commit();
$this->Database->unlock();
$this->LinkTypesDictionary = false;
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
fill_cache ( )

Function filles cache.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 152 of file link_dictionary.php.

{
try
{
if( $this->LinkTypesDictionary === false )
{
$this->Database->query_as( DB_OBJECT );
$this->LinkTypesDictionary = $this->Database->select( '*' , 'umx_link_dictionary' , "1 = 1" );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_link_literal_type ( $Type)

Getting link's type.

Parameters
$Type- Type of the object.
Returns
Literal type of the link.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 331 of file link_dictionary.php.

{
try
{
$Type = is_array( $Type ) === true ? $Type : array( $Type );
$this->fill_cache();
$Types = array();
foreach( $this->LinkTypesDictionary as $k => $v )
{
foreach( $Type as $i => $t )
{
if( $v->id == $t )
{
$Types [] = array(
'object1_type' => $v->object1_type , 'object2_type' => $v->object2_type
);
}
}
}
if( isset( $Types[ 0 ] ) === false )
{
throw( new Exception( 'Literal type of the link was not found' ) );
}
return( $Types );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_link_type (   $Object1Type,
  $Object2Type 
)

Getting link's type.

Parameters
$Object1Type- Type of the first object.
$Object2Type- Type of the second object.
Returns
Numeric type of the link.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 277 of file link_dictionary.php.

{
try
{
$LinkType = $this->get_type_from_db( $Object1Type , $Object2Type );
if( $LinkType === false )
{
if( $Object1Type === false || $Object2Type === false )
{
/* type with this parameters was not found */
return( 0 );
}
else
{
/* both types defined so we can create new link type */
$this->create_link_type( $Object1Type , $Object2Type );
return( $this->get_link_type( $Object1Type , $Object2Type ) );
}
}
else
{
return( $LinkType );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_type_from_cache (   $Object1Type,
  $Object2Type 
)

Getting link's type from the cache.

Parameters
$Object1Type- Type of the first object.
$Object2Type- Type of the second object.
Returns
Numeric type of the link or false if any error occured
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 106 of file link_dictionary.php.

{
try
{
$Types = array();
foreach( $this->LinkTypesDictionary as $k => $v )
{
if( $Object1Type !== false && $v->object1_type != $Object1Type )
{
continue;
}
if( $Object2Type !== false && $v->object2_type != $Object2Type )
{
continue;
}
$Types [] = $v->id;
}
if( isset( $Types[ 0 ] ) )
{
return( implode( ',' , $Types ) );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_type_from_db (   $Object1Type,
  $Object2Type 
)

Getting link's type.

Parameters
$Object1Type- Type of the first object.
$Object2Type- Type of the second object.
Returns
Numeric type of the link or false if any error occured.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 194 of file link_dictionary.php.

{
try
{
$this->fill_cache();
return( $this->get_type_from_cache( $Object1Type , $Object2Type ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$Database = false

Cached objects.

Author
Dodonov A.A.

Definition at line 50 of file link_dictionary.php.

$LinkTypesDictionary = false

Dictionary with link types.

Author
Dodonov A.A.

Definition at line 38 of file link_dictionary.php.

$Security = false

Definition at line 51 of file link_dictionary.php.


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