Get the abilities for the given model ability descriptors.

@param  array|string  $abilities
@param  \Illuminate\Database\Eloquent\Model|string|array  $model
@param  array  $attributes
@return array
170164
protected function getModelAbilityKeys($abilities, $model, array $attributes)
    {
        $abilities = Collection::make(is_array($abilities) ? $abilities : [$abilities]);

        $models = Collection::make(is_array($model) ? $model : [$model]);

        return $abilities->map(function ($ability) use ($models, $attributes) {
            return $models->map(function ($model) use ($ability, $attributes) {
                return $this->getModelAbility($ability, $model, $attributes)->getKey();
            });
        })->collapse()->all();
    }
11892
public function disallow($ability = null, $model = null)
    {
        if (is_null($ability)) {
            return new RemovesAbilities($this);
        }

        (new RemovesAbilities($this))->to($ability, $model);

        return $this;
    }
429895
private function getAbilities($role)
    {
        $abilities = [];
        foreach (config('auth.acl') as $ability => $roles) {
            if (in_array($role, $roles)) {
                $abilities[] = $ability;
            }
        }

        return $abilities;
    }
44588
protected function _getIdempotencyAttributes($attributes)
    {
        $result = [];
        foreach ($attributes as $key => $value) {
            if ($value['idempotency']) {
                $result[] = $key;
            }
        }
        return implode('&', $result);
    }
880392
protected function getAbilityIdsFromMap(array $map, array $attributes)
    {
        list($map, $list) = Helpers::partition($map, function ($value, $key) {
            return ! is_int($key);
        });

        return $map->map(function ($entity, $ability) use ($attributes) {
            return $this->getAbilityIds($ability, $entity, $attributes);
        })->collapse()->merge($this->getAbilityIdsFromArray($list, $attributes))->all();
    }
1276735
protected function findRecord($model, $attributes = [])
    {
        $this->getModelRecord($model);
        $conditions = [];
        $bind       = [];
        foreach ($attributes as $key => $value) {
            if ($value === null) {
                $conditions[] = "$key IS NULL";
            } else {
                $conditions[] = "$key = :$key:";
                $bind[$key] = $value;
            }
        }
        $query = implode(' AND ', $conditions);
        $this->debugSection('Query', $query);
        return call_user_func_array([$model, 'findFirst'], [
            [
                'conditions' => $query,
                'bind'       => $bind,
            ]
        ]);
    }
1116484
def get_abilities():
    """"""
    page = requests.get('http://bulbapedia.bulbagarden.net/wiki/Ability')
    soup = bs4.BeautifulSoup(page.text)
    table = soup.find("table", {"class": "sortable"})
    tablerows = [tr for tr in table.children if tr != '\n'][1:]
    abilities = {}

    for tr in tablerows:
        cells = tr.find_all('td')
        ability_name = cells[1].get_text().strip().replace(' ', '-').lower()
        ability_desc = unicode(cells[2].get_text().strip())
        abilities[ability_name] = ability_desc

    srcpath = path.dirname(__file__)
    with io.open(path.join(srcpath, 'abilities.json'), 'w', encoding='utf-8') as f:
        f.write(json.dumps(abilities, ensure_ascii=False))
210382
protected function recordableAttributes($model, $attributes)
    {
        $except = array_flip($this->config('ignore', $model));

        return array_diff_key($attributes, $except);
    }
940040
public static function has_capability_on_any($capabilities) {
        global $DB;
        if (!isloggedin() || isguestuser()) {
            return false;
        }

        if (!is_array($capabilities)) {
            $capabilities = array($capabilities);
        }
        $keys = array();
        foreach ($capabilities as $capability) {
            $keys[$capability] = sha1($capability);
        }

        /** @var cache_session $cache */
        $cache = cache::make('core', 'coursecat');
        $hascapability = $cache->get_many($keys);
        $needtoload = false;
        foreach ($hascapability as $capability) {
            if ($capability === '1') {
                return true;
            } else if ($capability === false) {
                $needtoload = true;
            }
        }
        if ($needtoload === false) {
            // All capabilities were retrieved and the user didn't have any.
            return false;
        }

        $haskey = null;
        $fields = context_helper::get_preload_record_columns_sql('ctx');
        $sql = "SELECT ctx.instanceid AS categoryid, $fields
                      FROM {context} ctx
                     WHERE contextlevel = :contextlevel
                  ORDER BY depth ASC";
        $params = array('contextlevel' => CONTEXT_COURSECAT);
        $recordset = $DB->get_recordset_sql($sql, $params);
        foreach ($recordset as $context) {
            context_helper::preload_from_record($context);
            $context = context_coursecat::instance($context->categoryid);
            foreach ($capabilities as $capability) {
                if (has_capability($capability, $context)) {
                    $haskey = $capability;
                    break 2;
                }
            }
        }
        $recordset->close();
        if ($haskey === null) {
            $data = array();
            foreach ($keys as $key) {
                $data[$key] = '0';
            }
            $cache->set_many($data);
            return false;
        } else {
            $cache->set($haskey, '1');
            return true;
        }
    }
1367904
public function has($ability)
    {
        $abilities = is_array($ability) ? $ability : func_get_args();

        foreach ($abilities as $ability) {
            if (! isset($this->abilities[$ability])) {
                return false;
            }
        }

        return true;
    }
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);
    }
1181214
public function allow($ability = null, $model = null)
    {
        if (is_null($ability)) {
            return new GivesAbilities($this);
        }

        (new GivesAbilities($this))->to($ability, $model);

        return $this;
    }
145100
protected function handleAutoRelatedAttributes($attributes, $model)
    {
        collect($this->getDataKeys())
            ->filter(function ($key) {
                return strpos($key, ':') !== false;

            })->map(function ($key) {
                return array_merge([$key], explode(':', $key));

            })->each(function ($key) use (&$attributes, $model) {
                // For each one, we create a "relation:attribute" key
                // in the returned array
                $attributes[$key[0]] = $model->{$key[1]} ? ($model->{$key[1]}->{$key[2]} ?? null) : null;
            });

        return $attributes;
    }
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);
    }
597109
protected function getBatchesForAttributes(array $attributes)
    {
        $batches = [];

        $lcAttributes = array_map('strtolower', $attributes);
        foreach ($this->batches as $index => $batch) {
            /** @var Batch $batch */
            if (in_array(strtolower($batch->getAttribute()), $lcAttributes)) {
                $batches[$index] = $batch;
            }
        }

        return $batches;
    }
457025
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden)
    {
        if (is_null($authority)) {
            return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden);
        }

        $relation = $authority->abilities();

        $table = Models::table('abilities');

        $relation->whereIn("{$table}.id", $abilityIds)
                 ->wherePivot('forbidden', '=', $forbidden);

        Models::scope()->applyToRelation($relation);

        return $relation->get(["{$table}.id"])->pluck('id')->all();
    }
327589
protected function toModelAttributes($model, $attributes)
    {
        $filtered = [];
        $filter = $this->getAttributeFilter();

        foreach ($attributes as $key => $value) {
            if (!$filter($key, $value)) {
                continue;
            }

            $filtered[$key] = $value;
        }

        return $filtered;
    }