Method that prepares associated
Capabilities records to be created.
@param  mixed[]  $capabilities Capabilities to be created
@return mixed[]                Capability objects
14661
public function prepareCapabilities(array $capabilities = []): array
    {
        if (empty($capabilities)) {
            return [];
        }

        $result = [];
        foreach ($capabilities as $capName => $checked) {
            $checked = (bool)$checked;
            if (!$checked) {
                continue;
            }

            $capEntity = $this->Capabilities->newEntity();
            $capEntity->name = $capName;
            $result[] = $capEntity;
        }

        return $result;
    }
765818
public function getResources()
    {
        $keys = $this->capabilities->keys();
        $definitions = [];

        foreach ($keys as $key) {
            $definitions[$key] = $this->capabilities->get($key);
        }

        return $definitions;
    }
1100153
public function get_capabilities( $caps ) {

		$caps = array_merge(
			$caps, array(
				'edit_' . $this->capability_type,
				'read_' . $this->capability_type,
				'delete_' . $this->capability_type,
				'edit_' . $this->capability_type . 's',
				'edit_others_' . $this->capability_type . 's',
				'publish_' . $this->capability_type . 's',
				'read_private_' . $this->capability_type . 's',
				'edit_' . $this->capability_type . 's',
			)
		);

		return $caps;
	}
439
public function serialize(Ability $ability, array $options = [])
    {
        $serialized = [
            'id' => $ability->getUuid(),
            'name' => $ability->getName(),
            'minResourceCount' => $ability->getMinResourceCount(),
            'minEvaluatedResourceCount' => $ability->getMinEvaluatedResourceCount(),
        ];

        return $serialized;
    }
119759
protected static function hasTypeAccessBelongs(array $capabilities, array $user, array $url): bool
    {
        $entity = static::getEntityFromUrl($url);

        $userGroups = static::getUserGroups($user);

        foreach ($capabilities as $capability) {
            if (!static::hasAccessInCapabilities($capability->getName(), $user['id'])) {
                continue;
            }

            // if url does not include an id and user has belongs to capability
            // access, to current module action, allow him access. (index action)
            if (empty($entity)) {
                return true;
            }

            // if url includes an id, check capability's field value from the entity
            // against current user id and if they match allow him access. (view, edit actions etc)
            $field = $capability->getField();

            foreach (array_keys($userGroups) as $id) {
                if ($entity->get($field) === $id) {
                    return true;
                }
            }
        }

        return false;
    }
324392
public function getAllCapabilities()
    {
        $capabilities = array();
        foreach (array_reverse($this->modelDevices) as $modelDevice) {
            /* @var Device\ModelDeviceInterface $modelDevice */
            $capabilities = array_merge($capabilities, $modelDevice->getCapabilities());
        }

        $capabilities = array_diff_key($capabilities, array_flip(VirtualCapabilityProvider::getControlCapabilities()));

        return $capabilities;
    }
44241
public function serialize(CompetencyAbility $competencyAbility, array $options = [])
    {
        $serialized = [
            'id' => $competencyAbility->getUuid(),
            'level' => $this->levelSerializer->serialize($competencyAbility->getLevel(), [Options::SERIALIZE_MINIMAL]),
            'competency' => [
                'id' => $competencyAbility->getCompetency()->getUuid(),
            ],
            'ability' => $this->abilitySerializer->serialize($competencyAbility->getAbility(), [Options::SERIALIZE_MINIMAL]),
        ];

        return $serialized;
    }
921199
protected function createMissingAbilities($existing, array $abilities, $attributes = [])
    {
        $missing = array_diff($abilities, $existing->pluck('name')->all());

        return array_map(function ($ability) use ($attributes) {
            return Models::ability()->create($attributes + ['name' => $ability]);
        }, $missing);
    }
587748
protected function parseAbilityAndArguments($ability, $arguments)
    {
        if (is_string($ability) && (strpos($ability, '\\') === false)) {
            return array($ability, $arguments);
        }

        list(,, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);

        return array($this->normalizeGuessedAbilityName($caller['function']), $ability);
    }
577225
public function getDesiredCapabilities()
	{
		$capabilities = parent::getDesiredCapabilities();

		if ( !isset($capabilities['platform']) ) {
			$capabilities['platform'] = 'Windows 7';
		}

		if ( !isset($capabilities['version']) ) {
			$capabilities['version'] = '';
		}

		return $capabilities;
	}
611062
public function get_capabilities() {
        global $DB, $CFG;

        $sort = 'ORDER BY contextlevel,component,name';   // To group them sensibly for display

        $cm = $DB->get_record('course_modules', array('id'=>$this->_instanceid));
        $module = $DB->get_record('modules', array('id'=>$cm->module));

        $subcaps = array();
        $subpluginsfile = "$CFG->dirroot/mod/$module->name/db/subplugins.php";
        if (file_exists($subpluginsfile)) {
            $subplugins = array();  // should be redefined in the file
            include($subpluginsfile);
            if (!empty($subplugins)) {
                foreach (array_keys($subplugins) as $subplugintype) {
                    foreach (array_keys(core_component::get_plugin_list($subplugintype)) as $subpluginname) {
                        $subcaps = array_merge($subcaps, array_keys(load_capability_def($subplugintype.'_'.$subpluginname)));
                    }
                }
            }
        }

        $modfile = "$CFG->dirroot/mod/$module->name/lib.php";
        $extracaps = array();
        if (file_exists($modfile)) {
            include_once($modfile);
            $modfunction = $module->name.'_get_extra_capabilities';
            if (function_exists($modfunction)) {
                $extracaps = $modfunction();
            }
        }

        $extracaps = array_merge($subcaps, $extracaps);
        $extra = '';
        list($extra, $params) = $DB->get_in_or_equal(
            $extracaps, SQL_PARAMS_NAMED, 'cap0', true, '');
        if (!empty($extra)) {
            $extra = "OR name $extra";
        }

        // Fetch the list of modules, and remove this one.
        $components = \core_component::get_component_list();
        $componentnames = $components['mod'];
        unset($componentnames["mod_{$module->name}"]);
        $componentnames = array_keys($componentnames);

        // Exclude all other modules.
        list($notcompsql, $notcompparams) = $DB->get_in_or_equal($componentnames, SQL_PARAMS_NAMED, 'notcomp', false);
        $params = array_merge($params, $notcompparams);


        // Exclude other component submodules.
        $i = 0;
        $ignorecomponents = [];
        foreach ($componentnames as $mod) {
            if ($subplugins = \core_component::get_subplugins($mod)) {
                foreach (array_keys($subplugins) as $subplugintype) {
                    $paramname = "notlike{$i}";
                    $ignorecomponents[] = $DB->sql_like('component', ":{$paramname}", true, true, true);
                    $params[$paramname] = "{$subplugintype}_%";
                    $i++;
                }
            }
        }
        $notlikesql = "(" . implode(' AND ', $ignorecomponents) . ")";

        $sql = "SELECT *
                  FROM {capabilities}
                 WHERE (contextlevel = ".CONTEXT_MODULE."
                   AND component {$notcompsql}
                   AND {$notlikesql})
                       $extra";

        return $DB->get_records_sql($sql.' '.$sort, $params);
    }
372547
public function getGroupIdCapabilitiesMap()
    {
        $groupIdCapabilitiesMap = array();
        foreach ($this->groupIdCapabilitiesNameMap as $groupId => $capabilitiesName) {
            foreach ($capabilitiesName as $capabilityName) {
                $groupIdCapabilitiesMap[$groupId][$capabilityName] = $this->capabilities[$capabilityName];
            }
        }

        return $groupIdCapabilitiesMap;
    }
1299561
public function to($abilities, $entity = null, array $attributes = [])
    {
        if (call_user_func_array([$this, 'shouldConductLazy'], func_get_args())) {
            return $this->conductLazy($abilities);
        }

        if ($ids = $this->getAbilityIds($abilities, $entity, $attributes)) {
            $this->disassociateAbilities($this->getAuthority(), $ids);
        }

        return true;
    }
1306283
public function transform(Ability $ability)
    {
        return [
            'actions' => $ability->actions,
            'conditions' => $ability->conditions,
            'id' => $ability->id,
            'subject' => $ability->subject,
        ];
    }
451993
public static function getRequiredCapabilities()
    {
        $caps = array();
        
        foreach (self::$virtual_capabilities as $cap_name => $vc_name) {
            if (strpos($vc_name, '.') !== false) {
                // Group of capabilities
                list($group, $property) = explode('.', $vc_name);
                $class = "WURFL_VirtualCapability_{$group}Group";
            } else {
                // Individual capability
                $class = "WURFL_VirtualCapability_$vc_name";
            }
            
            $model = new $class();
            $caps = array_unique(array_merge($caps, $model->getRequiredCapabilities()));
            unset($model);
        }
        
        return $caps;
    }
1155870
protected function prepareArray(array $conditions)
    {
        switch (count($conditions)) {
            case 1:
                $result = $conditions[0];
                break;
            case 2:
                if (is_array($conditions[1])) {
                    $result = $conditions[0].' IN ('.implode(',', $conditions[1]).')';
                } elseif (is_null($conditions[1])) {
                    $result = $conditions[0].' IS NULL';
                } elseif ($conditions[1] instanceof \pwf\components\querybuilder\interfaces\SelectBuilder) {
                    $result = $conditions[0].' IN ('.$conditions[1]->generate().')';
                    $this->setParams(array_merge($this->getParams(),
                            $conditions[1]->getParams()));
                } else {
                    $result = $conditions[0].'=?';//.$conditions[0];
                    $this->addParam($conditions[0], $conditions[1]);
                }
                break;
            case 3:
                $left   = is_array($conditions[1]) ? $this->prepareConditions($conditions[1])
                        : $conditions[1];
                $right  = is_array($conditions[2]) ? $this->prepareConditions($conditions[2])
                        : $conditions[2];
                $result = '(('.$left.') '.$conditions[0].' ('.$right.'))';
                break;
            default:
                throw new \Exception('Wrong condition configuration');
        }

        return $result;
    }
505374
public function user_can( $capability = null ) {
		if ( ! isset( $capability ) ) {
			$capability = $this->app->get_config( 'capability', 'default_user', 'manage_options' );
		}
		if ( false === $capability ) {
			return true;
		}
		if ( '' === $capability ) {
			return false;
		}

		return $this->has_cap( $capability ) || in_array( $capability, $this->user_roles );
	}