ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields
permit_access_1_0_0 Class Reference

## Public Member Functions
| __construct ()
| set_add_limitations ($theAddLimitation)
| unsafe_select ($Condition= '1=1')
| get_permit_by_name ($Permit)
| select ($Start=false, $Limit=false, $Field=false, $Order=false, $Condition= '1=1')
| create ($Record)
| delete ($id)
| select_list ($id)
| update ($id, $Record)
| get_permits_for_object ($id, $Type, $Default)
| get_permits_for_user_group ($uid)
| add_permit_for_object ($Permit, $Object, $ObjectType= 'page')
| set_permit_for_object ($Permit, $Object, $ObjectType= 'page')
| toggle_permit_for_object ($Permit, $Object, $ObjectType= 'page')
| delete_permit_for_object ($Permit, $Object, $ObjectType= 'page')
| get_permits_for_page ($Object)

## Data Fields
| $NativeTable = '`umx_permit`'
| $CachedMultyFS = false
| $Database = false
| $DatabaseAlgorithms = false
| $Link = false
| $LinkDictionary = false
| $Security = false
| $SecurityParser = false
| $UserAlgorithms = false
| $PermitsCache = array()
| $AddLimitations = '1 = 1'

## Detailed Description

Class provides routine for permits.

Author
  Dodonov A.A.

Definition at line 26 of file permit_access.php.

## Constructor & Destructor Documentation

__construct | ( |  | ) |

Constructor.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 85 of file permit_access.php.

{
try
{
$this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
$this->Database = get_package( 'database' , 'last' , __FILE__ );
$this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
$this->Link = get_package( 'link' , 'last' , __FILE__ );
$this->LinkDictionary = get_package( 'link::link_dictionary' , 'last' , __FILE__ );
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
$this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Member Function Documentation

add_permit_for_object | ( |  | $Permit,
|  |  | $Object,
|  |  | $ObjectType = `'page'`
| ) |  |

Function adds permit for object.

Parameters

  $Permit | - Permit to add.
  $Object | - Object.
  $ObjectType | - Type of the object (may be menu, user, page).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 580 of file permit_access.php.

{
try
{
$this->PermitsCache = array();
$Permit = $this->Security->get( $Permit , 'command' );
$Object = $this->Security->get( $Object , 'string' );
$ObjectType = $this->Security->get( $ObjectType , 'command' );
$Permits = array();
if( $ObjectType == 'user' || $ObjectType == 'group' || $ObjectType == 'page' )
{
$Permit = $this->unsafe_select( "permit LIKE '$Permit'" );
$Permit = $Permit[ 0 ];
$this->Link->create_link( $Object , $Permit->id , $ObjectType , 'permit' , true );
return;
}
throw( new Exception( "Undefined \"$ObjectType\"" ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

create | ( |  | $Record | ) |

Creating record.

Parameters

  $Record | Example for update.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 306 of file permit_access.php.

{
try
{
$Record = $this->SecurityParser->parse_parameters( $Record , 'permit:command;comment:string' );
list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
$id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

delete | ( |  | $id | ) |

Deleting record from database.

Parameters

  $id | - Comma separated list of record's id.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 340 of file permit_access.php.

{
try
{
$id = $this->Security->get( $id , 'integer_list' );
$this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
$this->Database->commit();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

delete_permit_for_object | ( |  | $Permit,
|  |  | $Object,
|  |  | $ObjectType = `'page'`
| ) |  |

Function deletes permit for object.

Parameters

  $Permit | - Permit to delete.
  $Object | - Object.
  $ObjectType | - Type of the object (may be menu, user, page).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 741 of file permit_access.php.

{
try
{
$this->PermitsCache = array();
$Permit = $this->Security->get( $Permit , 'command' );
$Permit = $this->unsafe_select( "permit LIKE '$Permit'" );
if( isset( $Permit[ 0 ] ) === false )
{
throw( new Exception( "Permit \"$Permit\" was not found" ) );
}
$Permit = $Permit[ 0 ];
$Object = $this->Security->get( $Object , 'string' );
$ObjectType = $this->Security->get( $ObjectType , 'command' );
$this->Link->delete_link( $Object , get_field( $Permit , 'id' ) , $ObjectType , 'permit' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_permit_by_name | ( |  | $Permit | ) |

Selecting record.

Parameters

  $Permit | Permit's title.

Returns
  Object.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 212 of file permit_access.php.

{
try
{
$Permit = $this->Security->get( $Permit , 'command' );
$Items = $this->unsafe_select( "( $this->AddLimitations ) AND permit LIKE '$Permit'" );
if( count( $Items ) == 0 )
{
throw( new Exception( "Permit $Permit was not found" ) );
}
return( $Items[ 0 ] );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_permits_for_object | ( |  | $id,
|  |  | $Type,
|  |  | $Default
| ) |  |

Function returns permits for the object.

Parameters

  $id | - Object's id.
  $Type | - Object type.
  $Default | - Default permits.

Note
  If permits were not defined at all, then object has $Default permit.

Returns
  List of permits.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 476 of file permit_access.php.

{
try
{
$id = $this->Security->get( $id , 'integer' );
$Type = $this->Security->get( $Type , 'command' );
$Links = $this->Link->get_links( $id , false , $Type , 'permit' );
if( isset( $Links[ 0 ] ) === false )
{
return( $Default );
}
else
{
$ids = get_field_ex( $Links , 'object2_id' );
$Permits = $this->select_list( implode( ',' , $ids ) );
return( get_field_ex( $Permits , 'permit' ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_permits_for_page | ( |  | $Object | ) |

Function returns permits for the page.

Parameters

  $Object | - Page to be accessed.

Returns
  List of permits.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 788 of file permit_access.php.

{
try
{
$Object = $this->Security->get( $Object , 'string' );
if( $this->CachedMultyFS->file_exists( dirname( __FILE__ )."/data/p$Object" ) )
{
$Permits = $this->CachedMultyFS->file_get_contents( dirname( __FILE__ )."/data/p$Object" );
return( explode( ',' , $Permits ) );
}
else
{
return( array( 'admin' ) );
}
}
catch( Exception $e )
{
$Args = func_get_args();_throw_exception_object( __METHOD__ , $Args , $e );
}
}

get_permits_for_user_group | ( |  | $uid | ) |

Function returns permits for the user.

Parameters

  $uid | - User's id.

Returns
  List of permits.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 526 of file permit_access.php.

{
try
{
$uid = ( $uid === false ) ? $this->UserAlgorithms->get_id() : $this->Security->get( $uid , 'integer' );
$Type = $this->LinkDictionary->get_link_type( 'user' , 'group' );
$this->Database->query_as( DB_OBJECT );
$Items = $this->Database->select(
'`umx_group`.id' , '`umx_group` , umx_link' ,
"umx_group.id = umx_link.object2_id AND umx_link.object1_id = $uid AND type = $Type"
);
$Permits = array();
foreach( $Items as $i )
{
$Permits = array_merge( $Permits , $this->get_permits_for_object( $i->id , 'group' , array() ) );
}
return( array_unique( $Permits ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

select | ( |  | $Start = `false`,
|  |  | $Limit = `false`,
|  |  | $Field = `false`,
|  |  | $Order = `false`,
|  |  | $Condition = `'1 = 1'`
| ) |  |

Function returns list of records.

Parameters

  $Start | - Number of the first record.
  $Limit | - Count of records limitation.
  $Field | - Field to sort by.
  $Order | - Sorting order.
  $Condition | - Additional conditions.

Returns
  List of records.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 271 of file permit_access.php.

{
try
{
$Condition = $this->DatabaseAlgorithms->select_condition(
$Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
);
return( $this->unsafe_select( $Condition ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

select_list | ( |  | $id | ) |

Function selects list of objects.

Parameters

  $id | - Comma separated list of record's id.

Returns
  Array of records.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 378 of file permit_access.php.

{
try
{
$id = $this->Security->get( $id , 'integer_list' );
return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

set_add_limitations | ( |  | $theAddLimitation | ) |

Constructor.

Author
  Dodonov A.A.

Definition at line 126 of file permit_access.php.

{
try
{
if( $this->AddLimitations === '1 = 1' )
{
$this->AddLimitations = $theAddLimitation;
}
else
{
throw( new Exception( '"AddLimitations" was already set' ) );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

set_permit_for_object | ( |  | $Permit,
|  |  | $Object,
|  |  | $ObjectType = `'page'`
| ) |  |

Function set permit for object.

Parameters

  $Permit | - Permit to add.
  $Object | - Object.
  $ObjectType | - Type of the object (may be menu, user, page).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 634 of file permit_access.php.

{
try
{
$this->PermitsCache = array();
$Permit = $this->Security->get( $Permit , 'command' );
$Permit = $this->unsafe_select( "permit LIKE '$Permit'" );
if( isset( $Permit[ 0 ] ) === false )
{
throw( new Exception( "Permit \"$Permit\" was not found" ) );
}
$Permit = $Permit[ 0 ];
$Object = $this->Security->get( $Object , 'string' );
$ObjectType = $this->Security->get( $ObjectType , 'command' );
$this->Link->create_link( $Object , get_field( $Permit , 'id' ) , $ObjectType , 'permit' , true );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

toggle_permit_for_object | ( |  | $Permit,
|  |  | $Object,
|  |  | $ObjectType = `'page'`
| ) |  |

Function toggles permit for object.

Parameters

  $Permit | - Permit to toggle.
  $Object | - Object.
  $ObjectType | - Type of the object (may be menu, user, page).

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 685 of file permit_access.php.

{
try
{
$this->PermitsCache = array();
$Permit = $this->Security->get( $Permit , 'command' );
$Permit = $this->unsafe_select( "permit LIKE '$Permit'" );
if( isset( $Permit[ 0 ] ) === false )
{
throw( new Exception( "Permit \"$Permit\" was not found" ) );
}
$Permit = $Permit[ 0 ];
$Object = $this->Security->get( $Object , 'string' );
$ObjectType = $this->Security->get( $ObjectType , 'command' );
if( is_array( $Object ) === false )
{
$Object = array( $Object );
}
$this->PermitAccessUtilities->toggle_permits();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

unsafe_select | ( |  | $Condition = `'1 = 1'` | ) |

Selecting records.

Parameters

  $Condition | - records selection condition.

Returns
  Array of objects.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 167 of file permit_access.php.

{
try
{
$this->Database->query_as( DB_OBJECT );
$Condition = "( $this->AddLimitations ) AND $Condition";
$Records = $this->Database->select( '*' , $this->NativeTable , $Condition );
foreach( $Records as $k => $v )
{
$Records[ $k ]->permit = htmlspecialchars_decode( $Records[ $k ]->permit , ENT_QUOTES );
$Records[ $k ]->comment = htmlspecialchars_decode( $Records[ $k ]->comment , ENT_QUOTES );
}
return( $Records );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

update | ( |  | $id,
|  |  | $Record
| ) |  |

Updating record.

Parameters

  $id | - Comma separated list of record's id.
  $Record | - Example for creation.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 414 of file permit_access.php.

{
try
{
$id = $this->Security->get( $id , 'integer_list' );
$Record = $this->SecurityParser->parse_parameters(
$Record , 'permit:command;comment:string' , 'allow_not_set'
);
list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
if( isset( $Fields[ 0 ] ) )
{
$Condition = "( $this->AddLimitations ) AND id IN ( $id )";
$this->Database->update( $this->NativeTable , $Fields , $Values , $Condition );
$this->Database->commit();
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Field Documentation

$AddLimitations = '1 = 1'

Definition at line 114 of file permit_access.php.

$CachedMultyFS = false

Cached objects.

Author
  Dodonov A.A.

Definition at line 50 of file permit_access.php.

$Database = false

Definition at line 51 of file permit_access.php.

$DatabaseAlgorithms = false

Definition at line 52 of file permit_access.php.

$Link = false

Definition at line 53 of file permit_access.php.

$LinkDictionary = false

Definition at line 54 of file permit_access.php.

$NativeTable = '`umx_permit`'

Table name in wich objects of this entity are stored.

Author
  Dodonov A.A.

Definition at line 38 of file permit_access.php.

$PermitsCache = array()

Cache of permits.

Author
  Dodonov A.A.

Definition at line 69 of file permit_access.php.

$Security = false

Definition at line 55 of file permit_access.php.

$SecurityParser = false

Definition at line 56 of file permit_access.php.

$UserAlgorithms = false

Definition at line 57 of file permit_access.php.

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

- packages/permit/packages/permit_access/permit_access.php