Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
RGenerator Class Reference

Public Member Functions

 init ()
 run ()
 addItems ($items, $type)
 getControllerActions ($items=null)

Public Attributes

 $db

Protected Member Functions

 getAllControllers ()
 getControllersInPath ($path)
 getControllersInModules ($path)

Detailed Description

Rights generator component class file.

Author
Christoffer Niska cnisk.nosp@m.a@li.nosp@m.ve.co.nosp@m.m
Since
0.9.8

Definition at line 9 of file RGenerator.php.

Member Function Documentation

RGenerator::addItems (   $items,
  $type 
)

Appends items to be generated of a specific type.

Parameters
array$itemsthe items to be generated.
integer$typethe item type.

Definition at line 86 of file RGenerator.php.

{
if( isset($this->_items[ $type ])===false )
$this->_items[ $type ] = array();
foreach( $items as $itemname )
$this->_items[ $type ][] = $itemname;
}
RGenerator::getAllControllers ( )
protected

Returns a list of all application controllers.

Returns
array the controllers.

Definition at line 137 of file RGenerator.php.

References getControllersInModules(), and getControllersInPath().

Referenced by getControllerActions().

{
$basePath = Yii::app()->basePath;
$items['controllers'] = $this->getControllersInPath($basePath.DIRECTORY_SEPARATOR.'controllers');
$items['modules'] = $this->getControllersInModules($basePath);
return $items;
}
RGenerator::getControllerActions (   $items = null)

Returns all the controllers and their actions.

Parameters
array$itemsthe controllers and actions.

Definition at line 99 of file RGenerator.php.

References getAllControllers().

{
if( $items===null )
$items = $this->getAllControllers();
foreach( $items['controllers'] as $controllerName=>$controller )
{
$actions = array();
$file = fopen($controller['path'], 'r');
$lineNumber = 0;
while( feof($file)===false )
{
++$lineNumber;
$line = fgets($file);
preg_match('/public[ \t]+function[ \t]+action([A-Z]{1}[a-zA-Z0-9]+)[ \t]*\(/', $line, $matches);
if( $matches!==array() )
{
$name = $matches[1];
$actions[ strtolower($name) ] = array(
'name'=>$name,
'line'=>$lineNumber
);
}
}
$items['controllers'][ $controllerName ]['actions'] = $actions;
}
foreach( $items['modules'] as $moduleName=>$module )
$items['modules'][ $moduleName ] = $this->getControllerActions($module);
return $items;
}
RGenerator::getControllersInModules (   $path)
protected

Returns all the controllers under the specified path.

Parameters
string$paththe path.
Returns
array the controllers.

Definition at line 187 of file RGenerator.php.

References getControllersInPath().

Referenced by getAllControllers().

{
$items = array();
$modulePath = $path.DIRECTORY_SEPARATOR.'modules';
if( file_exists($modulePath)===true )
{
$moduleDirectory = scandir($modulePath);
foreach( $moduleDirectory as $entry )
{
if( substr($entry, 0, 1)!=='.' && $entry!=='rights' )
{
$subModulePath = $modulePath.DIRECTORY_SEPARATOR.$entry;
if( file_exists($subModulePath)===true )
{
$items[ $entry ]['controllers'] = $this->getControllersInPath($subModulePath.DIRECTORY_SEPARATOR.'controllers');
$items[ $entry ]['modules'] = $this->getControllersInModules($subModulePath);
}
}
}
}
return $items;
}
RGenerator::getControllersInPath (   $path)
protected

Returns all controllers under the specified path.

Parameters
string$paththe path.
Returns
array the controllers.

Definition at line 150 of file RGenerator.php.

Referenced by getAllControllers(), and getControllersInModules().

{
$controllers = array();
if( file_exists($path)===true )
{
$controllerDirectory = scandir($path);
foreach( $controllerDirectory as $entry )
{
if( $entry{0}!=='.' )
{
$entryPath = $path.DIRECTORY_SEPARATOR.$entry;
if( strpos(strtolower($entry), 'controller')!==false )
{
$name = substr($entry, 0, -14);
$controllers[ strtolower($name) ] = array(
'name'=>$name,
'file'=>$entry,
'path'=>$entryPath,
);
}
if( is_dir($entryPath)===true )
foreach( $this->getControllersInPath($entryPath) as $controllerName=>$controller )
$controllers[ $controllerName ] = $controller;
}
}
}
return $controllers;
}
RGenerator::init ( )

Initializes the generator.

Definition at line 22 of file RGenerator.php.

{
$this->_authManager = Yii::app()->getAuthManager();
$this->db = $this->_authManager->db;
}
RGenerator::run ( )

Runs the generator.

Returns
the items generated or false if failed.

Definition at line 34 of file RGenerator.php.

{
$authManager = $this->_authManager;
$itemTable = $authManager->itemTable;
// Start transaction
$txn = $this->db->beginTransaction();
try
{
$generatedItems = array();
// Loop through each type of items
foreach( $this->_items as $type=>$items )
{
// Loop through items
foreach( $items as $name )
{
// Make sure the item does not already exist
if( $authManager->getAuthItem($name)===null )
{
// Insert item
$sql = "INSERT INTO {$itemTable} (name, type, data)
VALUES (:name, :type, :data)";
$command = $this->db->createCommand($sql);
$command->bindValue(':name', $name);
$command->bindValue(':type', $type);
$command->bindValue(':data', 'N;');
$command->execute();
$generatedItems[] = $name;
}
}
}
// All commands executed successfully, commit
$txn->commit();
return $generatedItems;
}
catch( CDbException $e )
{
// Something went wrong, rollback
$txn->rollback();
return false;
}
}

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