ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields
link_1_0_0 Class Reference

## Public Member Functions
| __construct ()
| create_link_object ($Object1Id, $Object2Id, $Object1Type, $Object2Type, $SingleLinkOnly=false)
| create_link ($Object1Id, $Object2Id, $Object1Type, $Object2Type, $SingleLinkOnly=false)
| compile_select_condition ($ObjectId, $FieldName, $Conditions)
| prepare_conditions ($Object1Id, $Object2Id, $Object1Type, $Object2Type)
| get_links ($Object1Id, $Object2Id, $Object1Type, $Object2Type)
| delete_link ($Object1Id, $Object2Id, $Object1Type, $Object2Type)
| get_links_count ($Object1Id, $Object2Id, $Object1Type, $Object2Type)
| link_exists ($Object1Id, $Object2Id, $Object1Type, $Object2Type)
| update_link ($Object1Id, $OldObject2Id, $NewObject2Id, $Object1Type, $Object2Type)

## Data Fields
| $Database = false
| $LinkDictionary = false
| $Security = false

## Detailed Description

Class allows to create many-to-many links.

Author
  Dodonov A.A.

Definition at line 26 of file link.php.

## Constructor & Destructor Documentation

__construct | ( |  | ) |

Constructor.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 56 of file link.php.

{
try
{
$this->Database = get_package( 'database' , 'last' , __FILE__ );
$this->LinkDictionary = get_package( 'link::link_dictionary' , '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

compile_select_condition | ( |  | $ObjectId,
|  |  | $FieldName,
|  |  | $Conditions
| ) |  |

Function creates conditions for query.

Parameters

  $ObjectId | - Object's id.
  $FieldName | - Field name.
  $Conditions | - Conditions.

Returns
  New conditions.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 226 of file link.php.

{
try
{
if( $ObjectId !== false )
{
if( is_array( $ObjectId ) )
{
$ObjectId = implode( ',' , $ObjectId );
}
$ObjectId = $this->Security->get( $ObjectId , 'integer_list' );
$Conditions [] = "$FieldName IN ( $ObjectId )";
}
return( $Conditions );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

create_link | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type,
|  |  | $SingleLinkOnly = `false`
| ) |  |

Function creates link.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.
  $SingleLinkOnly | - Only one link allowed.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 164 of file link.php.

{
try
{
if( is_array( $Object1Id ) )
{
foreach( $Object1Id as $k => $o1id )
{
$this->create_link( $o1id , $Object2Id , $Object1Type , $Object2Type , $SingleLinkOnly );
}
}
elseif( is_array( $Object2Id ) )
{
foreach( $Object2Id as $k => $o2id )
{
$this->create_link( $Object1Id , $o2id , $Object1Type , $Object2Type , $SingleLinkOnly );
}
}
else
{
$this->create_link_object(
$Object1Id , $Object2Id , $Object1Type , $Object2Type , $SingleLinkOnly
);
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

create_link_object | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type,
|  |  | $SingleLinkOnly = `false`
| ) |  |

Function creates link object.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.
  $SingleLinkOnly | - Only one link allowed.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 104 of file link.php.

{
try
{
if( $SingleLinkOnly && $this->link_exists( $Object1Id , $Object2Id , $Object1Type , $Object2Type ) )
{
return;
}
$Object1Id = $this->Security->get( $Object1Id , 'integer' );
$Object2Id = $this->Security->get( $Object2Id , 'integer' );
$LinkType = $this->LinkDictionary->get_link_type( $Object1Type , $Object2Type );
$this->Database->insert(
'umx_link' , 'object1_id , object2_id , type' , "$Object1Id , $Object2Id , $LinkType"
);
$this->Database->commit();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

delete_link | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function deletes link.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 384 of file link.php.

{
try
{
if( $Object1Type === false && $Object2Type === false )
{
throw( new Exception( "At least one type must be set" ) );
}
$Conditions = $this->prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
$this->Database->delete( 'umx_link' , $Conditions );
$this->Database->commit();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_links | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function returns all links for the object.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Returns
  Array of links.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 338 of file link.php.

{
try
{
$Conditions = $this->prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
$Fields = 'umx_link.* , umx_link_dictionary.object1_type , umx_link_dictionary.object2_type';
$Conditions = "umx_link.type = umx_link_dictionary.id AND $Conditions";
return( $this->Database->select( $Fields , 'umx_link , umx_link_dictionary' , $Conditions ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_links_count | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function returns count of links for the object.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Returns
  Array of links.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 438 of file link.php.

{
try
{
$Conditions = $this->prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
$Records = $this->Database->select( 'COUNT( * ) AS links_count' , 'umx_link' , $Conditions );
return( isset( $Records[ 0 ] ) === false ? 0 : get_field( $Records[ 0 ] , 'links_count' ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

link_exists | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function validates if the link exists.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Returns
  true if the link exists.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 487 of file link.php.

{
try
{
return( $this->get_links_count( $Object1Id , $Object2Id , $Object1Type , $Object2Type ) > 0 );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

prepare_conditions | ( |  | $Object1Id,
|  |  | $Object2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function prepares records fetching conditions.

Parameters

  $Object1Id | - Id of the first object.
  $Object2Id | - Id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Returns
  Fetching condition.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 282 of file link.php.

{
try
{
$Conditions = array();
$Conditions = $this->compile_select_condition( $Object1Id , 'object1_id' , $Conditions );
$Conditions = $this->compile_select_condition( $Object2Id , 'object2_id' , $Conditions );
if( $Object1Type !== false || $Object2Type != false )
{
$Types = $this->LinkDictionary->get_link_type( $Object1Type , $Object2Type );
$Conditions [] = "type IN ( $Types )";
}
return( implode( ' AND ' , $Conditions ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

update_link | ( |  | $Object1Id,
|  |  | $OldObject2Id,
|  |  | $NewObject2Id,
|  |  | $Object1Type,
|  |  | $Object2Type
| ) |  |

Function updates object's links.

Parameters

  $Object1Id | - Id of the first object.
  $OldObject2Id | - Id of the second object.
  $NewObject2Id | - New id of the second object.
  $Object1Type | - Type of the first object.
  $Object2Type | - Type of the second object.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 533 of file link.php.

{
try
{
if( strpos( $Object1Id , ',' ) === true )
{
$Object1Id = explode( ',' , $Object1Id );
}
else
{
$Object1Id = array( $Object1Id );
}
foreach( $Object1Id as $k => $id )
{
$this->delete_link( $id , $OldObject2Id , $Object1Type , $Object2Type );
$this->create_link( $id , $NewObject2Id , $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 38 of file link.php.

$LinkDictionary = false

Definition at line 39 of file link.php.

$Security = false

Definition at line 40 of file link.php.

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

- packages/link/link.php