ACL Extension  0.3
 All Data Structures Namespaces Files Functions Variables
RequestingActiveRecord Class Reference

Public Member Functions

 may ($obj, $action)
 grant ($obj, $actions)
 deny ($obj, $actions)
 afterSave ()
 beforeDelete ()

Protected Member Functions

 loadAro ()

Protected Attributes

 $aro = NULL

Detailed Description

Definition at line 13 of file RequestingActiveRecord.php.


Member Function Documentation

afterSave ( )

This method takes care to associate an ARO-collection with this one

Parameters:
CEvent$evt

Definition at line 82 of file RequestingActiveRecord.php.

{
if($this->isNewRecord){
$class = Strategy::getClass('Aro');
$aro = new $class();
$aro->model = get_class($this);
$aro->foreign_key = $this->getPrimaryKey();
if(!$aro->save())
throw new RuntimeError("Unable to save Aro-Collection");
}
}
beforeDelete ( )

This method takes care that every associated ACL-objects are properly removed

Definition at line 97 of file RequestingActiveRecord.php.

{
//Ok he has the right to do that - remove all the ACL-objects associated with this object
$class = Strategy::getClass('Aro');
$aro = $class::model()->find('model = :model AND foreign_key = :key', array(':model' => get_class( $this), ':key' => $this->id));
if(!$aro)
throw new RuntimeException('No associated Aro-Collection!');
$transaction = Yii::app()->db->beginTransaction();
try{
$suc =$aro->delete()&& parent::beforeDelete();
$transaction->commit();
return $suc;
}
catch(Exception $e){
$transaction->rollback();
throw $e;
}
}
deny (   $obj,
  $actions 
)

Denies the object denoted by the $obj-identifier the given actions

Parameters:
type$objthe object identifier
array$actionsthe actions to deny
Returns:
bool

Definition at line 72 of file RequestingActiveRecord.php.

{
$this->loadAro();
return $this->aro->deny($obj, $actions);
}
grant (   $obj,
  $actions 
)

Grants the object denoted by the $obj-identifier the given actions

Parameters:
type$objthe object identifier
array$actionsthe actions to grant
Returns:
bool

Definition at line 61 of file RequestingActiveRecord.php.

{
$this->loadAro();
return $this->aro->grant($obj, $actions);
}
loadAro ( )
protected

Loads the associated Aro_Object

Exceptions:
RuntimeException

Definition at line 25 of file RequestingActiveRecord.php.

{
$class = Strategy::getClass('Aro');
if($this->aro === NULL){
$this->aro = $class::model()->find('model = :model AND foreign_key = :foreign_key',
array(':model' => get_class($this), 'foreign_key' => $this->id));
//If there's no such Aro-Collection... use Guest ^^
$guest = Strategy::get('guestGroup');
if(!$this->aro && $guest){
$this->aro = $class::model()->find('alias = :alias', array(':alias' => $guest));
//If there's no guest...
if(!$this->aro)
throw new RuntimeException('There is no associated Aro nor a guest-group');
}
}
}
may (   $obj,
  $action 
)

Looks up if the user is granted a specific action to the given object

Parameters:
string | array$objThe object to be checked
string$actionthe action to be performed
Returns:
bool true if access is granted, false otherwise

Definition at line 50 of file RequestingActiveRecord.php.

{
$this->loadAro();
return $this->aro->may($obj, $action);
}

Field Documentation

$aro = NULL
protected

Definition at line 19 of file RequestingActiveRecord.php.


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