Returns an array of Preferences
@param $preferenceNames array of preference names
@return array
@ignore
165853
public function getAllUsersPreferences(array $preferenceNames)
    {
        Piwik::checkUserHasSuperUserAccess();

        $userPreferences = array();
        foreach($preferenceNames as $preferenceName) {
            $optionNameMatchAllUsers = $this->getPreferenceId('%', $preferenceName);
            $preferences = Option::getLike($optionNameMatchAllUsers);

            foreach($preferences as $optionName => $optionValue) {
                $lastUnderscore = strrpos($optionName, self::OPTION_NAME_PREFERENCE_SEPARATOR);
                $userName = substr($optionName, 0, $lastUnderscore);
                $preference = substr($optionName, $lastUnderscore + 1);
                $userPreferences[$userName][$preference] = $optionValue;
            }
        }
        return $userPreferences;
    }
510102
private function createOptions()
    {
        $options = [];

        if (isset($this->options['readPreference'])) {
            $options['readPreference'] = $this->options['readPreference'];
        }

        if (isset($this->options['session'])) {
            $options['session'] = $this->options['session'];
        }

        return $options;
    }
243048
private function getDiscriminatorValuesFor($classNames)
    {
        $discriminatorValues = [];
        $tables              = [];

        foreach ($classNames as $className) {
            $class                 = $this->dm->getClassMetadata($className);
            $discriminatorValues[] = $class->discriminatorValue;
            $table                 = $class->getTableName();
            $tables[$table]        = $table;
        }

        if (count($tables) > 1) {
            throw new \InvalidArgumentException('Documents involved are not all mapped to the same DynamoDB table.');
        }

        //If a discriminatorDefaultValue is set and it is among the discriminators
        //being queried, add NULL to the list
        if ($class->discriminatorDefaultValue !== null &&
            array_search($class->discriminatorDefaultValue, $discriminatorValues) !== false
        ) {
            $discriminatorValues[] = null;
        }

        return $discriminatorValues;
    }
431571
public function getPreferences()
    {
        $url = $this->getApiEndpoint() . "/v2/preferences";

        $response = $this->setUrl($url)
            ->setVerb('GET')
            ->execute();

        if (isset($response->message)) {
            $this->helper->log('GET PREFERENCES: ' . $response->message);
        }

        return $response;
    }
65725
public function getRepositories(array $entityNames)
    {
        $repositoryCollection = new EntityRepositoryCollection($this);
        foreach ($entityNames as $entityName) {
            $repositoryCollection->addRepository($this->getRepository($entityName));
        }
        return $repositoryCollection;
    }
599793
private function getMatchingIndexes(array $matchingList, PreferenceInterface $clientPref)
    {
        $matchingIndexList = array();

        foreach ($matchingList as $key => $matching) {
            if ($clientPref->getPrecedence() > $matching->getClientPreference()->getPrecedence()) {
                $matchingIndexList[] = $key;
            }
        }

        return $matchingIndexList;
    }
174224
protected function sanitize($preferences = null) : Collection
	{
		if (is_null($preferences) && $this->auth->check()) {
			return Collection::make($this->auth->user()->preferences);
		}

		if (is_null($preferences) && ! $this->auth->check()) {
			return $this->allowed;
		}

		if (is_string($preferences)) {
			$preferences = json_decode($preferences, true);
		}

		return Collection::make($preferences)->filter(function($item, $key) {
			return $this->allowed->has($key);
		});
	}
748017
public static function orderByPreference($widgets)
    {
        $preference = collect(['laralum', 'dashboard', 'users', 'roles', 'permissions']);

        $ordered_widgets = [];
        $final_ordered_widgets = [];

        $widgets = collect($widgets)->groupBy('package')->toArray();

        foreach (Packages::all() as $package) {
            if (!in_array($package, $preference->toArray())) {
                $preference->push($package);
            }
        }

        $ordered_widgets = $preference->map(function ($p) use ($widgets) {
            return array_key_exists($p, $widgets) ? $widgets[$p] : null;
        })->filter();

        foreach ($ordered_widgets as $widget) {
            foreach ($widget as $w) {
                array_push($final_ordered_widgets, $w);
            }
        }

        return $final_ordered_widgets;
    }
642922
public function slugs(array $basenames): array
    {
        $slugs = []; // Initialize.

        foreach ($basenames as $_basename) {
            if (($_slug = $this->slug((string) $_basename))) {
                $slugs[$_basename] = $_slug;
            }
        } // unset($_basename); // Housekeeping.

        return $slugs;
    }
1186750
public function getKeysByName($names)
    {
        if (empty($names)) {
            return [];
        }

        return $this->whereIn('name', $names)
                    ->select($this->getKeyName())->get()
                    ->pluck($this->getKeyName())->all();
    }
657733
public function findUserIdsInRoles($roleNames)
    {
        $qb = $this->createQueryBuilder('user')
            ->select('user.id')
            ->leftJoin('user.roles', 'roles')
            ->andWhere('roles.name IN (:roleNames)')
            ->andWhere('user.isEnabled = true')
            ->setParameter('roleNames', $roleNames);
        $query = $qb->getQuery();

        return $query->getArrayResult();
    }
35976
protected function filter($packageNames, $filters)
    {
        if (empty($filters)) {
            return $packageNames;
        }

        $packages = [];
        foreach ($packageNames as $packageName) {
            if (count($package = $this->repository->findPackages($packageName)) > 0) {
                foreach ($filters as $filter) {
                    $package = array_filter($package, $filter);
                }
                if ($package = current($package)) {
                    $packages[$packageName] = $package;
                }
            }
        }

        return array_map(
            function ($package) {
                /** @var PackageInterface $package */
                return $package->getName();
            },
            $packages
        );
    }
874035
public function findConsumptionPreferenceCategoryName($preference)
    {
        // No Preferences defined yet.
        if (is_null($this->consumption_preferences)) {
            return null;
        }

        // Traverse and Return.
        return $this->traverseNodesAndFindBy('name', $preference, $this->consumption_preferences);
    }
669094
public function prefers( $contentTypes )
	{
		$accepts = $this->getAcceptableContentTypes();

		$contentTypes = (array) $contentTypes;

		foreach ( $accepts as $accept )
		{
			if ( in_array( $accept, ['*/*', '*'] ) )
				return $contentTypes[0];

			foreach ( $contentTypes as $contentType )
			{
				$type = $contentType;

				if ( !is_null( $mimeType = $this->getMimeType( $contentType ) ) )
					$type = $mimeType;

				if ( $this->matchesType( $type, $accept ) || $accept === strtok( $type, '/' ) . '/*' )
					return $contentType;
			}
		}
	}
166391
private function getDiscriminatorValues($classNames) : array
    {
        $discriminatorValues = [];
        $collections         = [];
        foreach ($classNames as $className) {
            $class                 = $this->dm->getClassMetadata($className);
            $discriminatorValues[] = $class->discriminatorValue;
            $key                   = $this->dm->getDocumentDatabase($className)->getDatabaseName() . '.' . $class->getCollection();
            $collections[$key]     = $key;
        }
        if (count($collections) > 1) {
            throw new InvalidArgumentException('Documents involved are not all mapped to the same database collection.');
        }
        return $discriminatorValues;
    }
993981
protected function getSelectedChoices($choiceViews, array $values)
    {
        $selectedChoices = [];

        foreach ($choiceViews as $index => $choiceView) {
            if ($choiceView instanceof ChoiceGroupView) {
                $selectedChoices = array_merge($selectedChoices, $this->getSelectedChoices($choiceView->choices, $values));
            } elseif ($choiceView instanceof ChoiceView) {
                if (\in_array($choiceView->value, $values)) {
                    $selectedChoices[] = $choiceView;
                }
            }
        }

        return $selectedChoices;
    }
876929
public function getIndicesForChoices(array $choices)
    {
        $indices = array();

        foreach ($choices as $i => $givenChoice) {
            foreach ($this->choices as $j => $choice) {
                if ($choice === $givenChoice) {
                    $indices[$i] = $j;
                    unset($choices[$i]);

                    if (0 === count($choices)) {
                        break 2;
                    }
                }
            }
        }

        return $indices;
    }