From 6f368445a5a8f752dcdbafe229921b5723dc805f Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 27 Oct 2009 02:32:46 +0000 Subject: Created elgg_get_entities_from_metadata() and made get_entities_from_metadata(). Made elgg_get_entities() accept extra joins and wheres in the options. Created a helper function elgg_normalise_plural_options_array() to rewrite shortcut singular options to plurals. git-svn-id: http://code.elgg.org/elgg/trunk@3584 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 351750b0b..2eecfefb6 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2123,6 +2123,37 @@ function is_not_null($string) { return true; } + +/** + * Normalise the singular keys in an options array + * to the plural keys. + * + * @param $options + * @param $singulars + * @return array + */ +function elgg_normalise_plural_options_array($options, $singulars) { + foreach ($singulars as $singular) { + $plural = $singular . 's'; + + // normalize the singular to plural + if (isset($options[$singular]) && $options[$singular] !== NULL && $options[$singular] !== FALSE) { + if (isset($options[$plural])) { + if (is_array($options[$plural])) { + $options[$plural][] = $options[$singlar]; + } else { + $options[$plural] = array($options[$plural], $options[$singular]); + } + } else { + $options[$plural] = array($options[$singular]); + } + } + $options[$singular] = NULL; + } + + return $options; +} + /** * Get the full URL of the current page. * -- cgit v1.2.3