Example #1
0
/**
 * Get an array of the last visited bug ids.  We intentionally don't check
 * if the ids still exists to avoid performance degradation.
 *
 * @param integer $p_user_id The user id to get the last visited issues for, or null for current logged in user.
 * @return array An array of issue ids or an empty array if none found.
 * @access public
 */
function last_visited_get_array($p_user_id = null)
{
    if (!last_visited_enabled()) {
        return array();
    }
    $t_value = token_get_value(TOKEN_LAST_VISITED, $p_user_id);
    if (is_null($t_value)) {
        return array();
    }
    # we don't slice the array here to optimise for performance.  If the user reduces the number of recently
    # visited to track, then he/she will get the extra entries until visiting an issue.
    $t_ids = explode(',', $t_value);
    bug_cache_array_rows($t_ids);
    return $t_ids;
}
/**
 * This method should be called from view, update, print pages for issues,
 * mantisconnect.
 *
 * @param integer $p_issue_id The issue id that was just visited.
 * @param integer $p_user_id  The user id that visited the issue, or null for current logged in user.
 * @access public
 * @return void
 */
function last_visited_issue($p_issue_id, $p_user_id = null)
{
    if (!last_visited_enabled()) {
        return;
    }
    $t_value = token_get_value(TOKEN_LAST_VISITED, $p_user_id);
    if (is_null($t_value)) {
        $t_value = $p_issue_id;
    } else {
        $t_ids = explode(',', $p_issue_id . ',' . $t_value);
        $t_ids = array_unique($t_ids);
        $t_ids = array_slice($t_ids, 0, config_get('recently_visited_count'));
        $t_value = implode(',', $t_ids);
    }
    token_set(TOKEN_LAST_VISITED, $t_value, TOKEN_EXPIRY_LAST_VISITED, $p_user_id);
}
Example #3
0
function print_recently_visited()
{
    if (!last_visited_enabled()) {
        return;
    }
    $t_ids = last_visited_get_array();
    if (count($t_ids) == 0) {
        return;
    }
    echo '<div class="recently-visited">' . lang_get('recently_visited') . ': ';
    $t_first = true;
    foreach ($t_ids as $t_id) {
        if (!$t_first) {
            echo ', ';
        } else {
            $t_first = false;
        }
        echo string_get_bug_view_link($t_id);
    }
    echo '</div>';
}