Yii Framework Forum: [Snippet] Using Yii´s authManager to fill a asmselectex-box - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Snippet] Using Yii´s authManager to fill a asmselectex-box Rate Topic: -----

#1 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 11 January 2009 - 04:48 AM


<?php

$auth        = Yii::app()->authManager;
$RoleName    = $_GET['role']; // string(rolename)
$arrTypeMap  = array("0"=>"Operation", "1"=>"Task", "2"=>"Role");
$arrOptGroups = array();
$arrSelected  = array();

// get all authItems and push it to a optgroup depending on its type.
$authItems = $auth->getAuthItems();
array_multisort($authItems);
foreach($authItems as $authItem)
{
if($authItem->name != $RoleName)
$arrOptGroups[$arrTypeMap[$authItem->type]][$authItem->name]=$authItem->description;
}

// get all assigned authItems for the current role.
$childs = $auth->getItemChildren($RoleName);
foreach($childs as $child)
array_push($arrSelected, $child->name);

// and now we hand the obtained informations to a asmselectex instance
$this->widget('application.extensions.asmselectex.EasmSelectEx',array(
'name'=>'assignmentList',
'values'=>$arrOptGroups,
'selected'=>$arrSelected,
'attributes'=>array('title'=>"Select a Authorization Item to assign."),
'scriptOptions'=>"addItemTarget: 'bottom', animate: true, highlight: true,
  sortable: false, removeLabel: 'revoke', highlightAddedLabel: 'Assigned: ',
  highlightRemovedLabel: 'Revoked: '"
));

?>


Your result could look like this: http://ironic.tnzr.n...mselectex/demo/

The only thing, I´m missing is a way to get the "TypeMap" dynamiclly...
(but never searched through the docs... so maybe there is one)


greets ironic
0

#2 User is offline   Bethrezen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 76
  • Joined: 24-December 08
  • Location:Tambov, Russia

Posted 11 January 2009 - 04:52 AM

Great! But maybe it's better to use Yii features to get $_GET?
0

#3 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 11 January 2009 - 05:14 AM

Quote

Great! But maybe it's better to use Yii features to get $_GET?


yeah, sure!
It should just be an example for asmselectex+authManager. :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users