View Single Post
Old 09-02-2009, 03:22 PM   #3 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Thanks! I think I have a basic idea of a structure I want to use for this that will accomplish this quite easially.

The difficult part is the part to allow users to add their own permissions..

Perhaps something like this as a syntax.
php Code:
<?php

    // Create the permissionlist
    $permList = new PermissionList();
   
    // Add some roles
    $permList->addRole('admin');
    $permList->addRole('moderator');
    $permList->addRole('member');
    $permList->addRole('banned');
    // $permList->addRole(array('admin', 'moderator', 'member', 'banned'));
   
    // Add pages
    $permList->addPage('usercp', array('member', 'moderator', 'admin'));
    $permList->addPage('gallery', array('member', 'moderator', 'admin'));
    // Add a feature
    $permList->addFeature('image_statistic', array('moderator', 'admin'));
   
    // Create the permissions for the user
    $perm = new Permission($permList);
    $perm->set($user);

That's for adding pages, features and roles. Will probably fetch all the roles, features and pages from the database and iterate through the result and add them automatically.

We set the user by passing in the user object of the user so we can access the current users' usergroup for instance.

php Code:
// if user can view usercp
    if($perm->canView('usercp'))
    {
   
        // echo some usercp stuff
       
        // if user can use the image statistic feature
        if($perm->canUse('image_statistic'))
        {
       
            // echo the image statistic feature control panel
       
        }
   
    }

To see if the user viewing the page is allowed to view usercp. If they can, it checks if the user logged in can use the image statistic feature(where they will be able to set their own permissions for who can see the image statistic on their gallery).

php Code:
if($perm->canView('gallery'))
    {
   
        // echo some gallery stuff
       
        if($perm->canSee('image_statistic', $idOfGallery))
        {
       
            // echo the image statistic
       
        }
   
    }

Again, checks if the user viewing the page has access to view the page gallery. Then they check if they can see the feature image statistic in the current gallery(so we pass through the gallery id so we can check the permissions the gallery owner has set).

Does that look OK?
__________________
Tanax is offline  
Reply With Quote