is there anybody who could help me with a code snippet?


#1

Hi.
I’m developing a new plugin, and I would need to retrieve a list of all registered users who have the permission to edit every submitted item/collection (their own and the one submitted by others).
As I’m not at all familiar with ZEND ACL, is there anybody who could help me with a code snippet?
Thanks.


#2

The ACL functionality defines what a specific user can do, but does not provide a mechanism for querying amongst a group of users who have a specific permission. You would have to first query all users, set up their ACL individually, and then check that they had permission you are looking for.

The easier alternative would be to query the Users table for the users with the roles that grant those permissions. There is a helper if you intend to use the list in a dropdown called get_table_options() which you may also want to look at the code for as an example: https://github.com/omeka/Omeka/blob/master/application/libraries/globals.php#L1615

The applySearchFilters() method in the User_Table class can give you an idea of what can be queried for Users via the $searchParams argument: https://github.com/omeka/Omeka/blob/master/application/models/Table/User.php#L42

The default in Omeka is for both 'super' and 'admin' users to have access to all items, so I think you could get a combined list like so:

$users_that_edit_everything = array_merge(
    get_table_options('User', null, array('role' => 'super')),
    get_table_options('User', null, array('role' => 'admin'))
);