Assign Permissions to an Item

This example shows how to present a single item permission in a form.

When first invoked, a form is displayed showing the current permission.

If the form is submitted, we show the POST variables, and save the specified permissions.


Example permission

There are 1 groups(s) with permission for this item.

Code


<?php

use Xmf\Debug;
use 
Xmf\Request;
use 
Xmf\Module\Helper;
use 
Xmf\Module\Helper\Permission;


$dir basename(__DIR__);
$permHelper = new Permission($dir);

if (
$permHelper) {
    
// this is the name and item we are going to work with
    
$gperm_name='xmfdemo-perm';
    
$gperm_itemid=1;

    
// if this is a post operation get and save our variables
    
if ('POST' == Request::getMethod()) {
        echo 
'<h4>$_POST Input</h4>';
        
Debug::dump($_POST);
        
$name $permHelper->defaultFieldName($gperm_name$gperm_itemid);
        
$groups Request::getVar($name, array(), $hash 'POST');
        
$permHelper->savePermissionForItem($gperm_name$gperm_itemid$groups);
    }

    
$form = new \XoopsThemeForm(_MA_XMFDEMO_PERMFORM_CAPTION'form''''POST');
    
$grpElement $permHelper->getGroupSelectFormForItem(
        
$gperm_name,
        
$gperm_itemid,
        
_MA_XMFDEMO_PERM_CAPTION,
        
null,
        
true
    
);
    
$form->addElement($grpElement);
    
$form->addElement(new \XoopsFormButton('''submit'_MA_XMFDEMO_FORM_SUBMIT'submit'));

    echo 
$form->render();

    
$count count($permHelper->getGroupsForItem($gperm_name$gperm_itemid));
    echo 
sprintf(_MA_XMFDEMO_PERM_GROUP_COUNT$count);

}


Back to the XMF Example List
Design by: XOOPS UI/UX Team