// In this case the user has used the drag and drop functionnality $array_of_weights = explode(",", $drag_order); $graphs_in_dashboard = array(); foreach ($array_of_weights as $new_weight) { $expl = explode(":", $new_weight); $current_graph = new Graph($expl[0]); if (!isset($dashboard_id)) { $dashboard_id = $current_graph->getDashboardId(); } else { // Check if all the graphs are in the same dashboard if ($dashboard_id != $current_graph->getDashboardId()) { $error = true; break; } } $current_graph->setWeight($expl[1]); $graphs_in_dashboard[] = $current_graph; } } if (!$error) { foreach ($graphs_in_dashboard as $graph_to_store) { $graph_to_store->store(); } $dashboard = new Dashboard($dashboard_id); $url_redirect = Dashboard::makeURL('edit', $dashboard); fMessaging::create("success", "/dashboard.php", "The graphs have been successfully reordered"); } else { $url_redirect = Dashboard::makeURL('list'); fMessaging::create("success", "/dashboard.php", "An error occured and the graphs couldn't be reordered"); } fURL::redirect($url_redirect);
public static function cloneGraph($graph_id, $dashboard_id = NULL) { $graph_to_clone = new Graph($graph_id); if (empty($dashboard_id)) { $dashboard_id = $graph_to_clone->getDashboardId(); } $graph = new Graph(); $clone_name = 'Clone of ' . $graph_to_clone->getName(); // If it's too long, we truncate if (strlen($clone_name) > 255) { $clone_name = substr($clone_name, 0, 255); } $graph->setName($clone_name); $graph->setArea($graph_to_clone->getArea()); $graph->setVtitle($graph_to_clone->getVtitle()); $graph->setDescription($graph_to_clone->getDescription()); $graph->setDashboardId($dashboard_id); $graph->setWeight($graph_to_clone->getWeight()); $graph->setTimeValue($graph_to_clone->getTimeValue()); $graph->setUnit($graph_to_clone->getUnit()); $graph->setCustomOpts($graph_to_clone->getCustomOpts()); $graph->setStartsAtMidnight($graph_to_clone->getStartsAtMidnight()); $graph->store(); // Clone of the lines $lines = Line::findAll($graph_id); foreach ($lines as $line_to_clone) { Line::cloneLine($line_to_clone->getLineId(), TRUE, $graph->getGraphId()); } }