ultimix

- Main Page
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Data Fields

Public Member Functions | Data Fields
subscription_algorithms_1_0_0 Class Reference

## Public Member Functions
| __construct ()
| compile_subscription ($User, $Subscription)
| calculate_hash ($UserId, $SubscriptionId)
| unsubscribe_user ($UserId, $Hash)
| is_subscribed ($UserId, $SubscriptionId)
| get_by_id ($id)
| send_subscription_for_user ($UserId, $SubscriptionId)

## Data Fields
| $AutoMarkup = false
| $CachedMultyFS = false
| $Link = false
| $Security = false
| $SecurityParser = false
| $String = false
| $UserAlgorithms = false

## Detailed Description

Class provides records access routine.

Author
  Dodonov A.A.

Definition at line 26 of file subscription_algorithms.php.

## Constructor & Destructor Documentation

__construct | ( |  | ) |

Constructor.

Author
  Dodonov A.A.

Definition at line 56 of file subscription_algorithms.php.

{
try
{
$this->AutoMarkup = get_package( 'page::auto_markup' , 'last' , __FILE__ );
$this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
$this->Link = get_package( 'link' , 'last' , __FILE__ );
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
$this->String = get_package( 'string' , 'last' , __FILE__ );
$this->SubscriptionAccess = get_package( 'subscription::subscription_access' , '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

calculate_hash | ( |  | $UserId,
|  |  | $SubscriptionId
| ) |  |

Function calculates unsibscribe hash.

Parameters

  $UserId | - User id.
  $SubscriptionId | - Subscription id.

Returns
  Unsibscribe hash or false.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 149 of file subscription_algorithms.php.

{
try
{
$UserId = $this->Security->get( $UserId , 'integer' );
$SubscriptionId = $this->Security->get( $SubscriptionId , 'integer' );
$Link = $this->Link->get_links( $UserId , $SubscriptionId , 'user' , 'subscription' );
if( isset( $Link[ 0 ] ) )
{
$LinkId = get_field( $Link[ 0 ] , 'id' );
return( md5( "$UserId.$LinkId" ) );
}
return( false );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

compile_subscription | ( |  | $User,
|  |  | $Subscription
| ) |  |

Function unsubscribes user.

Parameters

  $User | - User object.
  $Subscription | - Subscription object.

Returns
  HTML code.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 101 of file subscription_algorithms.php.

{
try
{
$Code = $this->CachedMultyFS->get_template( __FILE__ , get_field( $Subscription , 'template' ).'.tpl' );
$User = set_field( $User , 'user_id' , get_field( $User , 'id' ) );
$Code = $this->String->print_record( $Code , $User );
$Subscription = set_field( $Subscription , 'subscription_id' , get_field( $Subscription , 'id' ) );
$Code = $this->String->print_record( $Code , $Subscription );
$Code = $this->AutoMarkup->compile_string( $Code );
return( $Code );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

get_by_id | ( |  | $id | ) |

Function returns subscription by it's id.

Parameters

  $id | - Id of the searching subscription.

Returns
  Subscription.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 285 of file subscription_algorithms.php.

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

is_subscribed | ( |  | $UserId,
|  |  | $SubscriptionId
| ) |  |

Is user subscribed.

Parameters

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

Returns
  true/false.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 246 of file subscription_algorithms.php.

{
try
{
$UserId = $this->Security->get( $UserId , 'integer' );
$SubscriptionId = $this->Security->get( $SubscriptionId , 'integer' );
$Links = $this->Link->get_links( $UserId , $SubscriptionId , 'user' , 'subscription' );
return( isset( $Links[ 0 ] ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

send_subscription_for_user | ( |  | $UserId,
|  |  | $SubscriptionId
| ) |  |

Function sends subscription if necessary.

Parameters

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

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 463 of file subscription_algorithms.php.

{
try
{
$UserId = $this->Security->get( $UserId , 'integer' );
$SubscriptionId = $this->Security->get( $SubscriptionId , 'integer' );
if( $this->is_subscribed( $UserId , $SubscriptionId ) )
{
$User = $this->UserAlgorithms->get_by_id( $UserId );
$Subscription = $this->get_by_id( $SubscriptionId );
$Message = $this->compile_subscription( $User , $Subscription );
$this->send_email( get_field( $User , 'email' ) , $Message , $Subscription );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

unsubscribe_user | ( |  | $UserId,
|  |  | $Hash
| ) |  |

Function unsubscribes user.

Parameters

  $UserId | - Comma separated list of users's id.
  $Hash | - Unsibscribe hash.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 194 of file subscription_algorithms.php.

{
try
{
$UserId = $this->Security->get( $UserId , 'integer' );
$Hash = $this->Security->get( $Hash , 'string' );
$Subscriptions = $this->SubscriptionAccess->get_subscriptions_for_user( $UserId );
foreach( $Subscriptions as $i => $Subscription )
{
$SubscriptionId = get_field( $Subscription , 'id' );
if( $this->calculate_hash( $UserId , $SubscriptionId ) == $Hash )
{
$this->SubscriptionAccess->unsubscribe_user( $UserId , $SubscriptionId );
return;
}
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

## Field Documentation

$AutoMarkup = false

Cached objects.

Author
  Dodonov A.A.

Definition at line 38 of file subscription_algorithms.php.

$CachedMultyFS = false

Definition at line 39 of file subscription_algorithms.php.

$Link = false

Definition at line 40 of file subscription_algorithms.php.

$Security = false

Definition at line 41 of file subscription_algorithms.php.

$SecurityParser = false

Definition at line 42 of file subscription_algorithms.php.

$String = false

Definition at line 43 of file subscription_algorithms.php.

$UserAlgorithms = false

Definition at line 44 of file subscription_algorithms.php.

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

- packages/subscription/packages/subscription_algorithms/subscription_algorithms.php