From 48b2e618f7c5729a3aab85a600c3e133f8a62faa Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 12 Feb 2011 02:33:55 +0000 Subject: Added elgg_get_entities_from_plugin_user_settings(). Added a name_prefix option to elgg_get_entities_from_private_settings(). git-svn-id: http://code.elgg.org/elgg/trunk@8136 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/plugins.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'engine/lib/plugins.php') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 2ac49e8df..b8fd321a8 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -978,6 +978,76 @@ function elgg_unset_all_plugin_settings($plugin_id = null) { return $plugin->unsetAllSettings(); } +/** + * Returns entities based upon plugin settings. + * Takes all the options for {@see elgg_get_entities_from_private_settings()} + * in addition to the ones below. + * + * @param array $options Array in the format: + * + * plugin_name => NULL|STR The plugin name. Defaults to calling plugin + * + * plugin_user_setting_names => NULL|ARR private setting names + * + * plugin_user_setting_values => NULL|ARR metadata values + * + * plugin_user_setting_name_value_pairs => NULL|ARR ( + * name => 'name', + * value => 'value', + * 'operand' => '=', + * ) + * Currently if multiple values are sent via + * an array (value => array('value1', 'value2') + * the pair's operand will be forced to "IN". + * + * plugin_user_setting_name_value_pairs_operator => NULL|STR The operator to use for combining + * (name = value) OPERATOR (name = value); default AND + * + * @return mixed + */ +function elgg_get_entities_from_plugin_user_settings(array $options = array()) { + // if they're passing it don't bother + if (!isset($options['plugin_name'])) { + $options['plugin_name'] = elgg_get_calling_plugin_id(); + } + + $singulars = array('plugin_user_setting_name', 'plugin_user_setting_value', + 'plugin_user_setting_name_value_pair'); + + $options = elgg_normalise_plural_options_array($options, $singulars); + + // rewrite plugin_user_setting_name_* to the right PS ones. + $map = array( + 'plugin_user_setting_names' => 'private_setting_names', + 'plugin_user_setting_values' => 'private_setting_values', + 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', + 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator' + ); + + foreach ($map as $plugin => $private) { + if (!isset($options[$plugin])) { + continue; + } + + if (isset($options[$private])) { + if (!is_array($options[$private])) { + $options[$private] = array($options[$private]); + } + + $options[$private] = array_merge($options[$private], $options[$plugin]); + } else { + $options[$private] = $options[$plugin]; + } + } + + + $plugin_id = $options['plugin_name']; + $prefix = elgg_namespace_plugin_private_setting('user_setting', '', $plugin_id); + $options['private_setting_name_prefix'] = $prefix; + + return elgg_get_entities_from_private_settings($options); +} + /** * Register object, plugin entities as ElggPlugin classes * -- cgit v1.2.3