/** * Test set/get weight */ public function testSetGetWeight() { $expected = 10; $object = new Line(); $object->setWeight($expected); $this->assertEquals($expected, $object->getWeight()); }
public static function cloneLine($line_id, $ignore_clone_name = FALSE, $graph_id = NULL) { $line_to_clone = new Line($line_id); if (empty($graph_id)) { $graph_id = $line_to_clone->getGraphId(); } $line = new Line(); if ($ignore_clone_name) { $clone_alias = $line_to_clone->getAlias(); } else { $clone_alias = 'Clone of ' . $line_to_clone->getAlias(); // If it's too long, we truncate if (strlen($clone_alias) > 255) { $clone_alias = substr($clone_alias, 0, 255); } } $line->setAlias($clone_alias); $line->setTarget($line_to_clone->getTarget()); $line->setColor($line_to_clone->getColor()); $line->setGraphId($graph_id); $line->setWeight($line_to_clone->getWeight()); $line->store(); }
// In this case the user has used the drag and drop functionnality $array_of_weights = explode(",", $drag_order); $lines_in_graph = array(); foreach ($array_of_weights as $new_weight) { $expl = explode(":", $new_weight); $current_line = new Line($expl[0]); if (empty($graph_id)) { $graph_id = $current_line->getGraphId(); } else { // Check if all the lines are in the same graph if ($graph_id != $current_line->getGraphId()) { $error = true; break; } } $current_line->setWeight($expl[1]); $lines_in_graph[] = $current_line; } } if (!$error) { foreach ($lines_in_graph as $line_to_store) { $line_to_store->store(); } $graph = new Graph($graph_id); $url_redirect = Graph::makeURL('edit', $graph); fMessaging::create("success", "/graphs.php", "The lines have been successfully reordered"); } else { $url_redirect = Dashboard::makeURL('list'); fMessaging::create("success", "/dashboard.php", "An error occured and the lines couldn't be reordered"); } fURL::redirect($url_redirect);