private function CommerceLicenseRole::revokeRole in Commerce License 7
Revokes the users role if there are no other active licenses.
Parameters
$owner object: The Drupal user object.
$role integer: The numeric role value.
1 call to CommerceLicenseRole::revokeRole()
- CommerceLicenseRole::save in modules/
commerce_license_role/ plugins/ license_type/ CommerceLicenseRole.class.php - Overrides Entity::save().
File
- modules/
commerce_license_role/ plugins/ license_type/ CommerceLicenseRole.class.php, line 68
Class
- CommerceLicenseRole
- Role license type.
Code
private function revokeRole($owner, $role) {
$revoke = TRUE;
// Load all of the users active licenses that have yet to expire.
$efq = new EntityFieldQuery();
$results = $efq
->entityCondition('entity_type', 'commerce_license')
->propertyCondition('type', 'role')
->propertyCondition('uid', $owner->uid)
->propertyCondition('status', COMMERCE_LICENSE_ACTIVE)
->propertyCondition('license_id', $this->license_id, '!=')
->execute();
// Loop through all of the users active licenses to see if they have another
// active license with the same role.
if (!empty($results)) {
$licenses = entity_load('commerce_license', array_keys($results['commerce_license']));
foreach ($licenses as $license) {
$license_wrapper = entity_metadata_wrapper('commerce_license', $license);
try {
$license_role = $license_wrapper->product->commerce_license_role
->value();
} catch (EntityMetadataWrapperException $ex) {
$license_role = FALSE;
}
// Set the revoke flag to false if there is a match so the user keeps their role.
if ($license_role == $role) {
$revoke = FALSE;
}
}
}
// Revoke the user role if it exists and there isn't another license for the same user
// and role.
if ($revoke && isset($owner->roles[$role])) {
unset($owner->roles[$role]);
}
}