本文整理汇总了PHP中metadata_array_to_values函数的典型用法代码示例。如果您正苦于以下问题:PHP metadata_array_to_values函数的具体用法?PHP metadata_array_to_values怎么用?PHP metadata_array_to_values使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了metadata_array_to_values函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: group_tools_get_suggested_groups
/**
* Returns suggested groups
*
* @param ElggUser $user (optional) the user to get the groups for, defaults to the current user
* @param int $limit (optional) the number of suggested groups to return, default = 10
*
* @return ElggGroup[] all the suggested groups
*/
function group_tools_get_suggested_groups($user = null, $limit = null)
{
$result = array();
if (!elgg_instanceof($user, "user")) {
$user = elgg_get_logged_in_user_entity();
}
if (is_null($limit)) {
$limit = get_input("limit", 10);
}
$limit = sanitize_int($limit, false);
if ($user && $limit > 0) {
$dbprefix = elgg_get_config("dbprefix");
$group_membership_where = "e.guid NOT IN (SELECT er.guid_two FROM {$dbprefix}entity_relationships er where er.guid_one = {$user->getGUID()} and er.relationship IN ('member', 'membership_request'))";
if (elgg_get_plugin_setting("auto_suggest_groups", "group_tools") !== "no") {
$tag_names = elgg_get_registered_tag_metadata_names();
if (!empty($tag_names)) {
$user_metadata_options = array("guid" => $user->getGUID(), "limit" => false, "metadata_names" => $tag_names);
// get metadata
$user_values = elgg_get_metadata($user_metadata_options);
if (!empty($user_values)) {
// transform to values
$user_values = metadata_array_to_values($user_values);
// find group with these metadatavalues
$group_options = array("type" => "group", "metadata_names" => $tag_names, "metadata_values" => $user_values, "wheres" => $group_membership_where, "group_by" => "e.guid", "order_by" => "count(msn.id) DESC", "limit" => $limit);
$groups = elgg_get_entities_from_metadata($group_options);
if (!empty($groups)) {
foreach ($groups as $group) {
$result[$group->getGUID()] = $group;
$limit--;
}
}
}
}
}
// get admin defined suggested groups
$group_guids = string_to_tag_array(elgg_get_plugin_setting("suggested_groups", "group_tools"));
if (!empty($group_guids) && $limit > 0) {
$group_options = array("guids" => $group_guids, "type" => "group", "wheres" => array($group_membership_where), "limit" => $limit);
if (!empty($result)) {
$suggested_guids = array_keys($result);
$group_options["wheres"][] = "e.guid NOT IN (" . implode(",", $suggested_guids) . ")";
}
$groups = elgg_get_entities($group_options);
if (!empty($groups)) {
foreach ($groups as $group) {
$result[$group->getGUID()] = $group;
}
}
}
}
return $result;
}
示例2: getMetadata
/**
* Return the value of a piece of metadata.
*
* @param string $name Name
*
* @return mixed The value, or null if not found.
*/
public function getMetadata($name)
{
$guid = $this->getGUID();
if (!$guid) {
if (isset($this->temp_metadata[$name])) {
// md is returned as an array only if more than 1 entry
if (count($this->temp_metadata[$name]) == 1) {
return $this->temp_metadata[$name][0];
} else {
return $this->temp_metadata[$name];
}
} else {
return null;
}
}
// upon first cache miss, just load/cache all the metadata and retry.
// if this works, the rest of this function may not be needed!
$cache = _elgg_services()->metadataCache;
if ($cache->isLoaded($guid)) {
return $cache->getSingle($guid, $name);
} else {
$cache->populateFromEntities(array($guid));
// in case ignore_access was on, we have to check again...
if ($cache->isLoaded($guid)) {
return $cache->getSingle($guid, $name);
}
}
$md = elgg_get_metadata(array('guid' => $guid, 'metadata_name' => $name, 'limit' => 0, 'distinct' => false));
$value = null;
if ($md && !is_array($md)) {
$value = $md->value;
} elseif (count($md) == 1) {
$value = $md[0]->value;
} else {
if ($md && is_array($md)) {
$value = metadata_array_to_values($md);
}
}
return $value;
}
示例3: getMetaData
/**
* Return the value of a piece of metadata.
*
* @param string $name Name
*
* @return mixed The value, or NULL if not found.
*/
public function getMetaData($name)
{
if ((int) $this->guid > 0) {
$md = elgg_get_metadata(array('guid' => $this->getGUID(), 'metadata_name' => $name, 'limit' => 0));
} else {
if (isset($this->temp_metadata[$name])) {
return $this->temp_metadata[$name];
}
}
if ($md && !is_array($md)) {
return $md->value;
} elseif (count($md) == 1) {
return $md[0]->value;
} else {
if ($md && is_array($md)) {
return metadata_array_to_values($md);
}
}
return null;
}
示例4: foreach
// because they are entities, but their dirs were removed.
// don't delete the entities because they hold settings.
foreach ($known_plugins as $plugin) {
if ($plugin->isActive()) {
$plugin->deactivate();
}
// remove the priority.
$name = elgg_namespace_plugin_private_setting('internal', 'priority');
remove_private_setting($plugin->guid, $name);
$plugin->disable();
}
// get old enabled plugins
$enabled_plugin_options["guids"] = array($subsite->getGUID());
$old_enabled_plugins = elgg_get_metadata($enabled_plugin_options);
if (!empty($old_enabled_plugins)) {
$old_enabled_plugins = metadata_array_to_values($old_enabled_plugins);
$old_enabled_plugins = array_unique($old_enabled_plugins);
foreach ($old_enabled_plugins as $plugin_id) {
if ($plugin = elgg_get_plugin_from_id($plugin_id)) {
if (!check_entity_relationship($plugin->getGUID(), 'active_plugin', $subsite->getGUID())) {
add_entity_relationship($plugin->getGUID(), 'active_plugin', $subsite->getGUID());
}
}
}
}
// remove old metadata
remove_metadata($subsite->getGUID(), 'pluginorder');
remove_metadata($subsite->getGUID(), 'enabled_plugins');
elgg_set_config("site", $site);
elgg_set_config("site_guid", $old_site_guid);
datalist_set("plugins_done_" . $subsite->getGUID(), true);
示例5: getMetaData
/**
* Get a given piece of metadata.
*
* @param string $name
*/
public function getMetaData($name)
{
if ((int) $this->guid > 0) {
$md = get_metadata_byname($this->getGUID(), $name);
} else {
if (isset($this->temp_metadata[$name])) {
return $this->temp_metadata[$name];
}
}
if ($md && !is_array($md)) {
return $md->value;
} else {
if ($md && is_array($md)) {
return metadata_array_to_values($md);
}
}
return null;
}
示例6: user_support_find_unique_help_context
/**
* Get a list of all the unique help contexts
*
* @return bool|array
*/
function user_support_find_unique_help_context()
{
static $result;
if (!isset($result)) {
$result = false;
// get all metadata values of help_context
$options = array("metadata_name" => "help_context", "type" => "object", "subtypes" => array(UserSupportFAQ::SUBTYPE, UserSupportHelp::SUBTYPE, UserSupportTicket::SUBTYPE), "limit" => false);
$metadata = elgg_get_metadata($options);
if (!empty($metadata)) {
// make it into an array
$filtered = metadata_array_to_values($metadata);
if (!empty($filtered)) {
//get unique values
$result = array_unique($filtered);
natcasesort($result);
}
}
}
return $result;
}
示例7: elgg_echo
$form_body .= "</tr><tr>";
$form_body .= "<td><label>" . elgg_echo("event_manager:edit:form:location") . "</label></td>";
$form_body .= "<td>" . elgg_view('input/text', array('name' => 'location', 'value' => $location)) . "</td>";
$form_body .= "</tr><tr>";
$form_body .= "<td><label>" . elgg_echo("event_manager:edit:form:max_attendees") . "</label></td>";
$form_body .= "<td>" . elgg_view('input/text', array('name' => 'max_attendees', 'value' => $max_attendees)) . "</td>";
$form_body .= "</tr><tr>";
$form_body .= "<td><label>" . elgg_echo("description") . "</label></td>";
$form_body .= "<td>" . elgg_view('input/plaintext', array('name' => 'description', 'value' => $description)) . "</td>";
$form_body .= "</tr><tr>";
$form_body .= "<td><label>" . elgg_echo("event_manager:edit:form:slot_set") . "</label></td>";
$form_body .= "<td>";
$form_body .= elgg_view("input/radio", array("name" => "slot_set", "options" => array(elgg_echo("event_manager:edit:form:slot_set:empty") => 0), "value" => $slot_set));
// unique set names for this event
$metadata = elgg_get_metadata(array("type" => "object", "subtype" => EventSlot::SUBTYPE, "container_guids" => array($entity->container_guid), "metadata_names" => array("slot_set"), "limit" => false));
$metadata_values = metadata_array_to_values($metadata);
if (!empty($metadata_values)) {
$metadata_values = array_unique($metadata_values);
foreach ($metadata_values as $value) {
$form_body .= elgg_view("input/radio", array("name" => "slot_set", "options" => array($value => $value), "value" => $slot_set));
}
}
// optionally add a new set
$form_body .= elgg_view("input/text", array("id" => "event-manager-new-slot-set-name"));
$form_body .= elgg_view("input/button", array("id" => "event-manager-new-slot-set-name-button", "value" => elgg_echo("event_manager:edit:form:slot_set:add"), "class" => "elgg-button-action"));
$form_body .= "<div class='elgg-subtext'>" . elgg_echo("event_manager:edit:form:slot_set:description") . "</div>";
$form_body .= "</td>";
$form_body .= "</tr></table>";
$form_body .= elgg_view('input/submit', array('value' => elgg_echo('submit')));
$form = elgg_view('input/form', array('id' => 'event_manager_form_program_slot', 'name' => 'event_manager_form_program_slot', 'action' => 'javascript:event_manager_program_add_slot($(\'#event_manager_form_program_slot\'))', 'body' => $form_body));
echo elgg_view_module("info", elgg_echo("event_manager:form:program:slot"), $form, array("id" => "event-manager-program-slot-lightbox"));
示例8: getMetaData
/**
* Return the value of a piece of metadata.
*
* @param string $name Name
*
* @return mixed The value, or NULL if not found.
*/
public function getMetaData($name)
{
if ((int) $this->guid == 0) {
if (isset($this->temp_metadata[$name])) {
// md is returned as an array only if more than 1 entry
if (count($this->temp_metadata[$name]) == 1) {
return $this->temp_metadata[$name][0];
} else {
return $this->temp_metadata[$name];
}
} else {
return null;
}
}
$md = elgg_get_metadata(array('guid' => $this->getGUID(), 'metadata_name' => $name, 'limit' => 0));
if ($md && !is_array($md)) {
return $md->value;
} elseif (count($md) == 1) {
return $md[0]->value;
} else {
if ($md && is_array($md)) {
return metadata_array_to_values($md);
}
}
return null;
}
示例9: group_tools_get_suggested_groups
/**
* Returns suggested groups
*
* @param ElggUser $user (optional) the user to get the groups for, defaults to the current user
* @param int $limit (optional) the number of suggested groups to return, default = 10
*
* @return ElggGroup[]
*/
function group_tools_get_suggested_groups($user = null, $limit = null)
{
if (!$user instanceof ElggUser) {
$user = elgg_get_logged_in_user_entity();
}
if (is_null($limit)) {
$limit = (int) get_input('limit', 10);
}
$limit = sanitize_int($limit, false);
if (empty($user) || $limit < 1) {
return [];
}
$result = [];
$dbprefix = elgg_get_config('dbprefix');
$group_membership_where = "e.guid NOT IN (\n\t\tSELECT er.guid_two FROM {$dbprefix}entity_relationships er\n\t\tWHERE er.guid_one = {$user->getGUID()}\n\t\tAND er.relationship IN (\n\t\t\t'member',\n\t\t\t'membership_request'\n\t\t)\n\t)";
if (elgg_get_plugin_setting('auto_suggest_groups', 'group_tools') !== 'no') {
$tag_names = elgg_get_registered_tag_metadata_names();
if (!empty($tag_names)) {
$user_metadata_options = ['guid' => $user->getGUID(), 'limit' => false, 'metadata_names' => $tag_names];
// get metadata
$user_values = elgg_get_metadata($user_metadata_options);
if (!empty($user_values)) {
// transform to values
$user_values = metadata_array_to_values($user_values);
// find group with these metadatavalues
$group_options = ['type' => 'group', 'metadata_names' => $tag_names, 'metadata_values' => $user_values, 'wheres' => $group_membership_where, 'group_by' => 'e.guid', 'order_by' => 'count(msn.id) DESC', 'limit' => $limit];
$groups = elgg_get_entities_from_metadata($group_options);
if (!empty($groups)) {
foreach ($groups as $group) {
$result[$group->getGUID()] = $group;
$limit--;
}
}
}
}
}
// get admin defined suggested groups
if ($limit > 0) {
$group_guids = string_to_tag_array(elgg_get_plugin_setting('suggested_groups', 'group_tools'));
if (!empty($group_guids)) {
$group_options = ['guids' => $group_guids, 'type' => 'group', 'wheres' => [$group_membership_where], 'limit' => $limit];
if (!empty($result)) {
$suggested_guids = array_keys($result);
$group_options['wheres'][] = 'e.guid NOT IN (' . implode(',', $suggested_guids) . ')';
}
$groups = elgg_get_entities($group_options);
if (!empty($groups)) {
foreach ($groups as $group) {
$result[$group->getGUID()] = $group;
}
}
}
}
return $result;
}