Get a constraint for the detach query for the given parameters.

@param  mixed  $roleId
@param  mixed  $authorityId
@param  string  $morphType
@return \Closure
324465
protected function getDetachQueryConstraint($roleId, $authorityId, $morphType)
    {
        return function ($query) use ($roleId, $authorityId, $morphType) {
            $query->where(Models::scope()->getAttachAttributes() + [
                'role_id' => $roleId,
                'entity_id' => $authorityId,
                'entity_type' => $morphType,
            ]);
        };
    }
1157796
public function updateDocumentAction($documentId, $parentType)
    {
        if (null !== $response = $this->checkAuth($this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT), array(), AccessManager::UPDATE)) {
            return $response;
        }

        $documentInstance = $this->updateFileAction($documentId, $parentType, 'document', TheliaEvents::DOCUMENT_UPDATE);

        if ($documentInstance instanceof \Symfony\Component\HttpFoundation\Response) {
            return $documentInstance;
        } else {
            return $this->render('document-edit', array(
                'documentId' => $documentId,
                'documentType' => $parentType,
                'redirectUrl' => $documentInstance->getRedirectionUrl(),
                'formId' => $documentInstance->getUpdateFormId()
            ));
        }
    }
1103726
public function addPolicy($roleId, Policy $policy)
    {
        try {
            return $this->innerGateway->addPolicy($roleId, $policy);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1186420
static function fetch( $roleID, $version = 0 )
    {
        if ( $version != 0 )
        {
            return eZPersistentObject::fetchObject( eZRole::definition(),
                                                    null, array( 'version' => $version ), true );
        }
        return eZPersistentObject::fetchObject( eZRole::definition(),
                                                null, array('id' => $roleID ), true );
    }
1222324
public function loadRoleAssignment($roleAssignmentId)
    {
        try {
            return $this->innerGateway->loadRoleAssignment($roleAssignmentId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
938763
protected function morphEagerTo($name, $type, $id)
    {
        return new MorphTo(
            $this->newQuery()->setEagerLoads([]), $this, $id, null, $type, $name
        );
    }
1355562
public function loadRoleDraftByRoleId($roleId)
    {
        try {
            return $this->innerGateway->loadRoleDraftByRoleId($roleId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
729819
public function deleteRole($roleId, $status = Role::STATUS_DEFINED)
    {
        $role = $this->loadRole($roleId, $status);

        foreach ($role->policies as $policy) {
            $this->roleGateway->removePolicy($policy->id);
        }

        $this->roleGateway->deleteRole($role->id, $status);
    }
110343
public static function role_assignment_changed($roleid, $context) {
        global $CFG, $DB;

        if ($context->contextlevel > CONTEXT_COURSE) {
            // No changes to course contacts if role was assigned on the module/block level.
            return;
        }

        // Trigger a purge for all caches listening for changes to category enrolment.
        cache_helper::purge_by_event('changesincategoryenrolment');

        if (!$CFG->coursecontact || !in_array($roleid, explode(',', $CFG->coursecontact))) {
            // The role is not one of course contact roles.
            return;
        }

        // Remove from cache course contacts of all affected courses.
        $cache = cache::make('core', 'coursecontacts');
        if ($context->contextlevel == CONTEXT_COURSE) {
            $cache->delete($context->instanceid);
        } else if ($context->contextlevel == CONTEXT_SYSTEM) {
            $cache->purge();
        } else {
            $sql = "SELECT ctx.instanceid
                    FROM {context} ctx
                    WHERE ctx.path LIKE ? AND ctx.contextlevel = ?";
            $params = array($context->path . '/%', CONTEXT_COURSE);
            if ($courses = $DB->get_fieldset_sql($sql, $params)) {
                $cache->delete_many($courses);
            }
        }
    }
458321
public function restore_role_assignment($instance, $roleid, $userid, $contextid) {
        role_assign($roleid, $userid, $contextid, 'enrol_'.$instance->enrol, $instance->id);
    }
1096271
public static function innerAuthRule($roleId,$uid,$where=[])
    {

        return AuthAccess::alias('AuthAccess')
            ->join('__MENU__ Menu','AuthAccess.menu_id = Menu.id')
            ->where($where)
            ->where('(AuthAccess.type="admin_url" and AuthAccess.role_id in(:roleId))or(AuthAccess.type="admin" and AuthAccess.role_id =:uid)', [
                'roleId'    => $roleId,
                'uid'       => $uid
            ])
            ->column('*','menu_id');

    }
89223
public function deletePolicy($roleId, $policyId, Request $request)
    {
        try {
            // First try to treat $roleId as a role draft ID.
            $roleDraft = $this->roleService->loadRoleDraft($roleId);

            $policy = null;
            foreach ($roleDraft->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->removePolicyByRoleDraft($roleDraft, $policy);

                return new Values\NoContent();
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);

            $policy = null;
            foreach ($role->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }

            if ($policy !== null) {
                $this->roleService->deletePolicy($policy);

                return new Values\NoContent();
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
1108462
public function morphsMany($entity, callable $callable = null, $alias = null)
    {
        return $this->returnRelation(MorphsMany::class, $entity, $callable, $alias);
    }
743083
public function loadRoleDraftByRoleId($roleId)
    {
        $query = $this->handler->createSelectQuery();
        $query->select(
            $this->handler->aliasedColumn($query, 'id', 'ezrole'),
            $this->handler->aliasedColumn($query, 'name', 'ezrole'),
            $this->handler->aliasedColumn($query, 'version', 'ezrole'),
            $this->handler->aliasedColumn($query, 'id', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'function_name', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'module_name', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'original_id', 'ezpolicy'),
            $this->handler->aliasedColumn($query, 'identifier', 'ezpolicy_limitation'),
            $this->handler->aliasedColumn($query, 'value', 'ezpolicy_limitation_value')
        )->from(
            $this->handler->quoteTable('ezrole')
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy'),
            $query->expr->eq(
                $this->handler->quoteColumn('role_id', 'ezpolicy'),
                $this->handler->quoteColumn('id', 'ezrole')
            )
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy_limitation'),
            $query->expr->eq(
                $this->handler->quoteColumn('policy_id', 'ezpolicy_limitation'),
                $this->handler->quoteColumn('id', 'ezpolicy')
            )
        )->leftJoin(
            $this->handler->quoteTable('ezpolicy_limitation_value'),
            $query->expr->eq(
                $this->handler->quoteColumn('limitation_id', 'ezpolicy_limitation_value'),
                $this->handler->quoteColumn('id', 'ezpolicy_limitation')
            )
        )->where(
            $query->expr->eq(
                // Column name "version" is misleading as it stores originalId when creating a draft from an existing role.
                // But hey, this is legacy! :-)
                $this->handler->quoteColumn('version', 'ezrole'),
                $query->bindValue($roleId, null, \PDO::PARAM_STR)
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
898006
public function deleteRole($projectId, $roleId)
    {
        return $this->apiClient->callEndpoint(
            sprintf('%s/%s/role/%s', self::ENDPOINT, $projectId, $roleId),
            array(),
            null,
            HttpMethod::REQUEST_DELETE
        );
    }
1089213
public function restore_role_assignment($instance, $roleid, $userid, $contextid) {
        global $DB;

        if ($this->get_config('unenrolaction') == ENROL_EXT_REMOVED_UNENROL or $this->get_config('unenrolaction') == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
            // Skip any roles restore, they should be already synced automatically.
            return;
        }

        // Just restore every role.
        if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
            role_assign($roleid, $userid, $contextid, 'enrol_'.$instance->enrol, $instance->id);
        }
    }
995808
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
    {
        $instance = $this->newRelatedInstance($related);

        // Here we will gather up the morph type and ID for the relationship so that we
        // can properly query the intermediate table of a relation. Finally, we will
        // get the table and create the relationship instances for the developers.
        [$type, $id] = $this->getMorphs($name, $type, $id);

        $table = $instance->getTable();

        $localKey = $localKey ?: $this->getKeyName();

        return $this->newMorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
    }