} catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } include VIEW_PATH . '/add_edit_graph.php'; // --------------------------------- // } elseif ('add' == $action) { $graph = new Graph(); $dashboard = new Dashboard($dashboard_id); if (fRequest::isPost()) { try { $graph->populate(); $graph->setStartsAtMidnight(isset($_POST['starts_at_midnight']) ? $_POST['starts_at_midnight'] : false); fRequest::validateCSRFToken(fRequest::get('token')); $graphs_in_dashboard = Graph::findAll($dashboard_id); $graph->setWeight($graphs_in_dashboard->count(TRUE)); $graph->store(); fMessaging::create('affected', $manage_url, $graph->getName()); fMessaging::create('success', $manage_url, 'The Graph ' . $graph->getName() . ' was successfully created'); fURL::redirect(Graph::makeUrl('edit', $graph)); } catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } } include VIEW_PATH . '/add_edit_graph.php'; } elseif ('delete' == $action) { $class_name = 'Graph'; try { $obj = new Graph($graph_id); $dashboard = new Dashboard($obj->getDashboardId()); $delete_text = 'Are you sure you want to delete the graph : <strong>' . $obj->getName() . '</strong>?'; if (fRequest::isPost()) {
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()); } }