Example #1
0
/**
 * Check if the user did see the last update for an entity based on
 * the last view time annotation and the updated time for the elgg entity
 * 
 * @param $entity_guid
 * @param $user_guid
 */
function did_see_last_update($entity_guid, $user_guid)
{
    $entity = get_entity($entity_guid);
    if ($entity) {
        $user = get_entity($user_guid);
        if (!$user) {
            $user = elgg_get_logged_in_user_entity();
        }
        $last_view_time = get_last_view_time($entity->guid, $user->guid);
        $last_view_time = $last_view_time ? $last_view_time : 0;
        if ($entity->time_updated > $last_view_time) {
            return true;
        } else {
            return false;
        }
    }
    return null;
}
Example #2
0
/**
 * Hook that allow other plugins to get the last view time for an entity
 * 
 * @param $hook
 * @param $type
 * @param $returnvalue
 * @param $params
 */
function get_last_view_time_hook($hook, $type, $returnvalue, $params)
{
    if ($params['entity']) {
        // We get the entity as a hook params instead of the entity_guid just for follow the elgg pattern of pass the entity instead of the entity_guid
        $user_guid = isset($params['user_guid']) ? $params['user_guid'] : 0;
        return get_last_view_time($params['entity']->guid, $user_guid);
    }
}