If you carefully look at how magento stores the roles of the administrator and users, you would understand this better.
Assuming you create a staff role, magento saves this role in the admin_role table. When you create a new user, the user data is stored in the admin_user table, which has no relation to the admin_role table at admin_role . But by assigning the staff role to this user, this assignment will again create a new administrator role. In fact, the user himself is seen as an administrator.
This should work fine:
$output = []; // just an array to hold all the users, you may not need this // instance of the admin_role $model = Mage::getModel('admin/role'); // fetch all roles with name of 'Staff', but get only the first item since two roles cannot have same name $role = $model->getCollection() ->addFieldToFilter('role_name', ['eq' => 'Staff']) ->getFirstItem(); // check to make sure the role exists if ($roleId = $role->getId()) { // get a collection of all the user roles having the Staff role id as a parent_id $staffUsers = $model->getCollection() ->addFieldToFilter('parent_id', ['eq' => $roleId]); // ensure the collection has size if ($staffUsers->getSize()) { // loop through each object and get the user_id values foreach ($staffUsers as $staffUser) { // you can still check to make sure the user_id field is not null if ($staffUser->getUserId()) { // get the user object and do anything with it $user = Mage::getModel('admin/user')->load($staffUser->getUserId()); $output[$user->getId()] = $user->getFirstname() . " " . $user->getLastname(); } } } } var_dump($output); die;
Hope this helps.
source share