function getUnreadMessages()
{
    $userId = get_loggedin_userid();
    $limit = 5;
    // Get the user's inbox, this will be all messages where the 'toId' field matches their guid
    $messages = get_entities_from_metadata_multi(array("toId" => $userId, "readYet" => 0), "object", "messages", $userId, $limit, 0);
    return $messages;
}
function form_get_latest_public_profile_form($profile_type = 1, $profile_category = '')
{
    $conditions = array('profile' => $profile_type, 'profile_category' => $profile_category);
    $form_array = get_entities_from_metadata_multi($conditions, 'object', 'form:form');
    if (!$form_array) {
        if ($profile_category) {
            // try again, this time with an empty (default) profile category
            $profile_category = '';
            $conditions = array('profile' => $profile_type, 'profile_category' => '');
            $form_array = get_entities_from_metadata_multi($conditions, 'object', 'form:form');
        }
    }
    if ($form_array) {
        // return the first public form
        // need to check for profile_category because sadly
        // get_entities_from_metadata_multi does not work properly for empty strings
        foreach ($form_array as $form) {
            if (!$profile_category && !$form->profile_category || $form->profile_category == $profile_category) {
                return $form;
            }
        }
    }
    return null;
}
Example #3
0
/**
 * When given a widget entity and a new requested location, saves the new location
 * and also provides a sensible ordering for all widgets in that column
 *
 * @param ElggObject $widget The widget entity
 * @param int        $order  The order within the column
 * @param int        $column The column (1, 2 or 3)
 *
 * @return bool Depending on success
 * @deprecated 1.8 use ElggWidget::move()
 */
function save_widget_location(ElggObject $widget, $order, $column)
{
    elgg_deprecated_notice('save_widget_location() is deprecated', 1.8);
    if ($widget instanceof ElggObject) {
        if ($widget->subtype == "widget") {
            // If you can't move the widget, don't save a new location
            if (!$widget->draggable) {
                return false;
            }
            // Sanitise the column value
            if ($column != 1 || $column != 2 || $column != 3) {
                $column = 1;
            }
            $widget->column = (int) $column;
            $ordertmp = array();
            $params = array('context' => $widget->context, 'column' => $column);
            if ($entities = get_entities_from_metadata_multi($params, 'object', 'widget')) {
                foreach ($entities as $entity) {
                    $entityorder = $entity->order;
                    if ($entityorder < $order) {
                        $ordertmp[$entityorder] = $entity;
                    }
                    if ($entityorder >= $order) {
                        $ordertmp[$entityorder + 10000] = $entity;
                    }
                }
            }
            $ordertmp[$order] = $widget;
            ksort($ordertmp);
            $orderticker = 10;
            foreach ($ordertmp as $orderval => $entity) {
                $entity->order = $orderticker;
                $orderticker += 10;
            }
            return true;
        } else {
            register_error($widget->subtype);
        }
    }
    return false;
}
function count_unread_messages()
{
    //get the users inbox messages
    //$num_messages = get_entities_from_metadata("toId", $_SESSION['user']->getGUID(), "object", "messages", 0, 10, 0, "", 0, false);
    $num_messages = get_entities_from_metadata_multi(array('toId' => $_SESSION['user']->guid, 'readYet' => 0, 'msg' => 1), "object", "messages", $_SESSION['user']->guid, 9999, 0, "", 0, false);
    if (is_array($num_messages)) {
        $counter = sizeof($num_messages);
    } else {
        $counter = 0;
    }
    return $counter;
}
/**
 * Get user objects by an array of metadata
 *
 * @param int $user_guid The GUID of the owning user
 * @param string $subtype Optionally, the subtype of objects
 * @paran array $metadata An array of metadata
 * @param int $limit The number of results to return (default 10)
 * @param int $offset Indexing offset, if any
 * @return false|array An array of ElggObjects or false, depending on success
 * @return unknown
 */
function get_user_objects_by_metadata($user_guid, $subtype = "", $metadata = array(), $limit = 0, $offset = 0)
{
    return get_entities_from_metadata_multi($metadata, "object", $subtype, $user_guid, $limit, $offset);
}
/**
 * function to check if custom fields on register have been filled (if required)
 * 
 * @param $hook_name
 * @param $entity_type
 * @param $return_value
 * @param $parameters
 * @return unknown_type
 */
function profile_manager_register_precheck($hook_name, $entity_type, $return_value, $parameters)
{
    // validate mandatory profile fields
    $count = get_entities_from_metadata_multi(array("show_on_register" => "yes", "mandatory" => "yes"), "object", CUSTOM_PROFILE_FIELDS_PROFILE_SUBTYPE, $CONFIG->site_guid, null, null, null, null, true);
    $profile_icon = get_plugin_setting("profile_icon_on_register");
    if ($count > 0 || $profile_icon == "yes") {
        $entities = get_entities_from_metadata_multi(array("show_on_register" => "yes", "mandatory" => "yes"), "object", CUSTOM_PROFILE_FIELDS_PROFILE_SUBTYPE, $CONFIG->site_guid, $count);
        $custom_profile_fields = array();
        foreach ($_POST as $key => $value) {
            if (strpos($key, "custom_profile_fields_") == 0) {
                $key = substr($key, 22);
                $custom_profile_fields[$key] = $value;
            }
        }
        foreach ($entities as $entity) {
            if ($entity->admin_only != "yes") {
                $passed_value = $custom_profile_fields[$entity->metadata_name];
                if (empty($passed_value)) {
                    register_error(sprintf(elgg_echo("profile_manager:register_pre_check:missing"), $entity->getTitle()));
                    forward_precheck_error($custom_profile_fields);
                }
            }
        }
        if ($profile_icon == "yes") {
            $profile_icon = $_FILES["profile_icon"];
            $error = false;
            if (empty($profile_icon["name"])) {
                register_error(sprintf(elgg_echo("profile_manager:register_pre_check:missing"), "profile_icon"));
                $error = true;
            } elseif ($profile_icon["error"] != 0) {
                register_error(elgg_echo("profile_manager:register_pre_check:profile_icon:error"));
                $error = true;
            } elseif (!in_array(strtolower(substr($profile_icon["name"], -3)), array("jpg", "png", "gif"))) {
                register_error(elgg_echo("profile_manager:register_pre_check:profile_icon:nosupportedimage"));
                $error = true;
            }
            if ($error) {
                forward_precheck_error($custom_profile_fields);
            }
        }
    }
}
Example #7
0
/**
 * Returns a viewable list of entities based on the given search criteria.
 *
 * @see elgg_view_entity_list
 * 
 * @param array $meta_array Array of 'name' => 'value' pairs
 * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
 * @param string $entity_subtype The subtype of the entity.
 * @param int $limit 
 * @param int $offset
 * @param string $order_by Optional ordering.
 * @param true|false $fullview Whether or not to display the full view (default: true)
 * @param true|false $viewtypetoggle Whether or not to allow users to toggle to the gallery view. Default: true
 * @param true|false $pagination Display pagination? Default: true
 * @return string List of ElggEntities suitable for display
 */
function list_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true)
{
    $offset = (int) get_input('offset');
    $limit = (int) $limit;
    $count = get_entities_from_metadata_multi($meta_array, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", $site_guid, true);
    $entities = get_entities_from_metadata_multi($meta_array, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", $site_guid, false);
    return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
}
function form_get_data_with_search_conditions_simple($conditions, $type, $form_id, $limit, $offset)
{
    global $CONFIG;
    if ($type == 'user') {
        // this is a user profile form, so get the data from users
        $entities = get_entities_from_metadata_multi($conditions, 'user', '', 0, $limit, $offset);
        $count = get_entities_from_metadata_multi($conditions, 'user', '', 0, $limit, $offset, "", 0, true);
    } else {
        if ($type == 'group') {
            // this is a user profile form, so get the data from groups
            $entities = get_entities_from_metadata_multi($conditions, 'group', '', 0, $limit, $offset);
            $count = get_entities_from_metadata_multi($conditions, 'group', '', 0, $limit, $offset, "", 0, true);
        } else {
            if (!$conditions) {
                $conditions = array();
            }
            $conditions['form_id'] = $form_id;
            $conditions['_language'] = $CONFIG->language;
            $entities = get_entities_from_metadata_multi($conditions, 'object', 'form_data', 0, $limit, $offset);
            $count = get_entities_from_metadata_multi($conditions, 'object', 'form_data', 0, $limit, $offset, "", 0, true);
        }
    }
    return array($count, $entities);
}