Mage_Adminhtml_Block_Api_Tab_Rolesedit Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Api_Tab_Rolesedit:

Mage_Adminhtml_Block_Widget_Form Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 getEverythingAllowed ()
 getResTreeJson ()

Protected Member Functions

 _sortTree ($a, $b)
 _getNodeJson ($node, $level=0)


Detailed Description

Definition at line 27 of file Rolesedit.php.


Constructor & Destructor Documentation

__construct (  ) 

Class constructor

Reimplemented from Mage_Adminhtml_Block_Widget_Form.

Definition at line 29 of file Rolesedit.php.

00029                                   {
00030         parent::__construct();
00031 
00032         $rid = Mage::app()->getRequest()->getParam('rid', false);
00033 
00034         $resources = Mage::getModel('api/roles')->getResourcesList();
00035 
00036         $rules_set = Mage::getResourceModel('api/rules_collection')->getByRoles($rid)->load();
00037 
00038         $selrids = array();
00039 
00040         foreach ($rules_set->getItems() as $item) {
00041             if (array_key_exists(strtolower($item->getResource_id()), $resources) && $item->getPermission() == 'allow') {
00042                 $resources[$item->getResource_id()]['checked'] = true;
00043                 array_push($selrids, $item->getResource_id());
00044             }
00045         }
00046 
00047         $this->setSelectedResources($selrids);
00048 
00049         $this->setTemplate('api/rolesedit.phtml');
00050         //->assign('resources', $resources);
00051         //->assign('checkedResources', join(',', $selrids));
00052     }


Member Function Documentation

_getNodeJson ( node,
level = 0 
) [protected]

Definition at line 77 of file Rolesedit.php.

00078     {
00079         $item = array();
00080         $selres = $this->getSelectedResources();
00081 
00082         if ($level != 0) {
00083             $item['text']= (string)$node->title;
00084             $item['sort_order']= isset($node->sort_order) ? (string)$node->sort_order : 0;
00085             $item['id']  = (string)$node->attributes()->aclpath;
00086 
00087             if (in_array($item['id'], $selres))
00088                 $item['checked'] = true;
00089         }
00090         if (isset($node->children)) {
00091             $children = $node->children->children();
00092         } else {
00093             $children = $node->children();
00094         }
00095         if (empty($children)) {
00096             return $item;
00097         }
00098 
00099         if ($children) {
00100             $item['children'] = array();
00101             //$item['cls'] = 'fiche-node';
00102             foreach ($children as $child) {
00103                 if ($child->getName()!='title' && $child->getName()!='sort_order' && $child->attributes()->module) {
00104                     if ($level != 0) {
00105                         $item['children'][] = $this->_getNodeJson($child, $level+1);
00106                     } else {
00107                         $item = $this->_getNodeJson($child, $level+1);
00108                     }
00109                 }
00110             }
00111             if (!empty($item['children'])) {
00112                 usort($item['children'], array($this, '_sortTree'));
00113             }
00114         }
00115         return $item;
00116     }

_sortTree ( a,
b 
) [protected]

Definition at line 71 of file Rolesedit.php.

00072     {
00073         return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
00074     }

getEverythingAllowed (  ) 

Definition at line 54 of file Rolesedit.php.

00055     {
00056         return in_array('all', $this->getSelectedResources());
00057     }

getResTreeJson (  ) 

Definition at line 59 of file Rolesedit.php.

00060     {
00061         $rid = Mage::app()->getRequest()->getParam('rid', false);
00062         $resources = Mage::getModel('api/roles')->getResourcesTree();
00063 
00064         $rootArray = $this->_getNodeJson($resources,1);
00065 
00066         $json = Zend_Json::encode(isset($rootArray['children']) ? $rootArray['children'] : array());
00067 
00068         return $json;
00069     }


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

Generated on Sat Jul 4 17:22:42 2009 for Magento by  doxygen 1.5.8