Ejemplo n.º 1
0
/**
 * Calculate all of the graphs that would be created for a given user,
 * with a given graph calculation strategy.
 * @param $strategy 'auto', 'managed' or '' (use user-defined)
 * @param $managed an array of categories or use, or empty to use user-defined
 */
function calculate_user_graphs($user, $strategy = false, $categories = array())
{
    if ($strategy === false) {
        if (!$user['graph_managed_type']) {
            throw new ManagedGraphException("User has no managed graph type, so cannot select user-defined strategy");
        }
        return calculate_user_graphs($user, $user['graph_managed_type'], $categories);
    }
    $managed = calculate_all_managed_graphs($user);
    // merge them all together based on user preferences
    if ($strategy == "managed") {
        if (!$categories) {
            $q = db()->prepare("SELECT * FROM managed_graphs WHERE user_id=?");
            $q->execute(array($user['id']));
            while ($m = $q->fetch()) {
                $categories[] = $m['preference'];
            }
        }
    } else {
        // default categories for auto
        $categories = get_auto_managed_graph_categories();
    }
    // merge all graphs based on categories
    $result = array();
    foreach ($categories as $key) {
        if (isset($managed[$key])) {
            foreach ($managed[$key] as $graph_key => $graph) {
                // remove any graphs that are not free priorities for non-premium users
                if ($user['is_premium'] || isset($graph['free']) && $graph['free']) {
                    $result[$graph_key] = $graph;
                }
            }
        }
    }
    // limit to the maximum number of graphs that we can support, if necessary
    // sort by priority
    uasort($result, '_sort_by_priority_key');
    if (count($result) > get_premium_value($user, 'graphs_per_page')) {
        $result = array_slice($result, 0, get_premium_value($user, 'graphs_per_page'));
    }
    // sort by order
    uasort($result, '_sort_by_order_key');
    return $result;
}
Ejemplo n.º 2
0
echo htmlspecialchars(get_site_config('site_name'));
?>
.
</p>

<p>
Three options of managed graphs are available on your <a href="<?php 
echo htmlspecialchars(url_for('wizard_reports'));
?>
">report preferences</a> page:
</p>

<dl>
	<dt>Automatic</dt>
	<dd>Graphs are selected from the <?php 
$graphs = get_auto_managed_graph_categories();
$categories = get_managed_graph_categories();
$result = array();
foreach ($graphs as $key) {
    $result[] = "\"" . $categories[$key] . "\"";
}
echo implode_english($result);
?>
 portfolio preferences categories. The managed graph page will be reset and updated automatically (see below).</dd>

	<dt>Managed based on my portfolio preferences</dt>
	<dd>By selecting a number of portfolio preferences, you may define which categories of portfolio graphs you are interested in.
	The managed graph page will be updated automatically, but will not change the layout or properties of graphs modified individually (see below).</dd>

	<dt>Self-managed</dt>
	<dd>Recommended for experts: Your graphs will never be automatically updated.</dd>