public function RestfulExampleRoleResource::getQueryForList in RESTful 7
Overrides \RestfulEntityBase::getQueryForList().
Overrides RestfulDataProviderEFQ::getQueryForList
File
- modules/
restful_example/ plugins/ restful/ node/ per_role_content/ 1.0/ RestfulExampleRoleResource.class.php, line 41 - Contains RestfulExampleRoleResource.
Class
- RestfulExampleRoleResource
- @file Contains RestfulExampleRoleResource.
Code
public function getQueryForList() {
$query = parent::getQueryForList();
// Get the configured roles.
if (!($options = $this
->getPluginKey('options'))) {
return $query;
}
// Get a list of role ids for the configured roles.
$roles_list = user_roles();
$selected_rids = array();
foreach ($roles_list as $rid => $role) {
if (in_array($role, $options['roles'])) {
$selected_rids[] = $rid;
}
}
if (empty($selected_rids)) {
return $query;
}
// Get the list of user ids belonging to the selected roles.
$uids = db_query('SELECT uid FROM {users_roles} WHERE rid IN (:rids)', array(
':rids' => $selected_rids,
))
->fetchAllAssoc('uid');
// Restrict the list of entities to the nodes authored by any user on the
// list of users with the administrator role.
if (!empty($uids)) {
$query
->propertyCondition('uid', array_keys($uids), 'IN');
}
return $query;
}