/** * Returns entities based upon private settings. Also accepts all * options available to elgg_get_entities(). Supports * the singular option shortcut. * * @see elgg_get_entities * * @param array $options Array in format: * * private_setting_names => NULL|ARR private setting names * * private_setting_values => NULL|ARR metadata values * * private_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". * * private_setting_name_value_pairs_operator => NULL|STR The operator to use for combining * (name = value) OPERATOR (name = value); default AND * * private_setting_name_prefix => STR A prefix to apply to all private settings. Used to * namespace plugin user settings or by plugins to namespace * their own settings. * * * @return mixed int If count, int. If not count, array. false on errors. * @since 1.8.0 */ function elgg_get_entities_from_private_settings(array $options = array()) { $defaults = array('private_setting_names' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_values' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_name_value_pairs' => ELGG_ENTITIES_ANY_VALUE, 'private_setting_name_value_pairs_operator' => 'AND', 'private_setting_name_prefix' => ''); $options = array_merge($defaults, $options); $singulars = array('private_setting_name', 'private_setting_value', 'private_setting_name_value_pair'); $options = elgg_normalise_plural_options_array($options, $singulars); $clauses = elgg_get_entity_private_settings_where_sql('e', $options['private_setting_names'], $options['private_setting_values'], $options['private_setting_name_value_pairs'], $options['private_setting_name_value_pairs_operator'], $options['private_setting_name_prefix']); if ($clauses) { // merge wheres to pass to get_entities() if (isset($options['wheres']) && !is_array($options['wheres'])) { $options['wheres'] = array($options['wheres']); } elseif (!isset($options['wheres'])) { $options['wheres'] = array(); } $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']); // merge joins to pass to get_entities() if (isset($options['joins']) && !is_array($options['joins'])) { $options['joins'] = array($options['joins']); } elseif (!isset($options['joins'])) { $options['joins'] = array(); } $options['joins'] = array_merge($options['joins'], $clauses['joins']); } return elgg_get_entities($options); }
function pleio_api_users_with_access_device_token($river) { $list = array(); $subject = get_entity($river->subject_guid); $object = get_entity($river->object_guid); $wheres = array(); $joins = array(); // don't return same object or subject $wheres[] = sprintf("e.guid NOT IN (%d, %d, %d, %d)", $object->guid, $object->owner_guid, $subject->guid, $subject->owner_guid); $site_guid = $object->site_guid; // override site_guid if object is site_guid if ($object instanceof Subsite || $object instanceof ElggSite) { $site_guid = $object->guid; } // add access_id specific wheres to determine possible receivers $more = false; switch ($object->access_id) { case ACCESS_DEFAULT: case ACCESS_LOGGED_IN: case ACCESS_PUBLIC: if ($object->type == "user") { //only friends $object->guid $more = elgg_get_entity_relationship_where_sql('e.guid', 'friend', $object->guid, 1); } elseif ($object && $object->container_guid && $object->container_guid != $object->owner_guid && ($container = get_entity($object->container_guid) && $container instanceof ElggGroup)) { // only group $object->container_guid $more = elgg_get_entity_relationship_where_sql('e.guid', 'member', $object->container_guid, 1); } elseif ($site_guid > 1) { //only subsite $site_guid $more = elgg_get_entity_relationship_where_sql('e.guid', 'member_of_site', $site_guid, 1); } else { // pleio has too many users to update everyone, so only friends $object->owner_guid $more = elgg_get_entity_relationship_where_sql('e.guid', 'friend', $object->owner_guid, 1); } break; case ACCESS_FRIENDS: //only friends $object->owner_guid $more = elgg_get_entity_relationship_where_sql('e.guid', 'friend', $object->owner_guid, 1); break; case ACCESS_PRIVATE: return array(); default: $users = get_members_of_access_collection($object->access_id, 1); $wheres[] = "e.guid IN (" . implode(", ", $users) . ")"; } if ($more) { $wheres = array_merge($wheres, $more["wheres"]); $joins = array_merge($joins, $more["joins"]); } // only select users that have a device_token $more = elgg_get_entity_private_settings_where_sql('e', array(), array(), array(array('name' => 'device_token', 'value' => 1, 'operand' => 'IS NOT NULL AND 1 = '))); $wheres = array_merge($wheres, $more["wheres"]); $joins = array_merge($joins, $more["joins"]); $options = array('type' => 'user', 'limit' => 100, 'wheres' => $wheres, 'joins' => $joins, 'site_guid' => ELGG_ENTITIES_ANY_VALUE); $users = elgg_get_entities($options); foreach ($users as $user) { $list[$user->guid] = array("device_token" => $user->getPrivateSetting('device_token'), "device" => $user->getPrivateSetting('device')); } return $list; }