PHP Classes
elePHPant
Icontem

File: example

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Raskin Veniamin  >  Manage PHP Permissions Framework  >  example  >  Download  
File: example
Role: Example script
Content type: text/plain
Description: example
Class: Manage PHP Permissions Framework
Manage role based user permissions store in MySQL
Author: By
Last change: Updates comments
Date: 1 year ago
Size: 2,065 bytes
 

Contents

Class file image Download
<?php
/**
 * example.php
 */
require_once 'VsManagePermissions.php';


echo
'<pre>';
$vsMP = VsManagePermissions::getInstance();

class
SomeUser {
   function
getId() { return 1; }
}

$user = new SomeUser();

/*
 * Create items
$vsMP->createItemComand('ComandA');
$vsMP->createItemComand('ComandB');
$vsMP->createItemComand('ComandC');

$item = $vsMP->createItemGroup('Comand');
$item->addChild('ComandA');
$item->addChild('ComandB');
$item->addChild('ComandC');

$vsMP->createItemComand('Post');
$vsMP->createItemComand('User');
$item = $vsMP->createItemGroup('Some');
$item->addChild('Post');
$item->addChild('User');

$item = $vsMP->createItemRole('Admin');
$item->addChild('Comand');
$item->addChild('Some');

$item = $vsMP->createItemRole('Writer');
$item->addChild('Post');

$access = VsManagePermissions::MODE_CREATE | VsManagePermissions::MODE_DELETE | VsManagePermissions::MODE_READ | VsManagePermissions::MODE_UPDATE;
//The first parameter is the user ID.
//The second parameter is the name of the role (command,group).
//The third parameter access mask
$vsMP->userAddItem($user->getId(), 'Admin', $access);
*/

$access = VsManagePermissions::MODE_CREATE | VsManagePermissions::MODE_READ | VsManagePermissions::MODE_UPDATE;
//The first parameter is the user ID.
//The second parameter is the name of the role (command,group).
//The third parameter access mask
$vsMP->userUpdateItem($user->getId(), 'Admin', $access);

//To detect the role of the user with id 1
echo "User has Post: ".($vsMP->hasAccess('Post', $user->getId()) ? "Yes" : "No"). " <br>";
echo
"User has create Post: ".($vsMP->hasAccessCreate('Post', $user->getId()) ? "Yes" : "No"). " <br>";
echo
"User has read Post: ".($vsMP->hasAccessRead('Post', $user->getId()) ? "Yes" : "No"). " <br>";
echo
"User has update Post: ".($vsMP->hasAccessUpdate('Post', $user->getId()) ? "Yes" : "No"). " <br>";
echo
"User has delete Post: ".($vsMP->hasAccessDelete('Post', $user->getId()) ? "Yes" : "No"). " <br>";

echo
'</pre>';
?>