示例#1
0
/**
    Builds the marker from data in the database and returns it.
    @param id<String> the marker id
    @return <Marker> a Marker object
*/
function retrieveMarker($id)
{
    $query = "SELECT * FROM markers WHERE id='{$id}'";
    $result = mysql_query($query) or die("Unable to retrieve marker of {$id} from the database.");
    if (count($result) > 1) {
        // error! there should only be one result
        echo "algorithm.getMarker() returned more than one result.<br/>\n";
    }
    $query_array = mysql_fetch_array($result, MYSQL_BOTH);
    $marker = new Marker($query_array['lat'], $query_array['lng'], $query_array['id'], $query_array['name']);
    $query = "SELECT * FROM connections WHERE marker_id='{$id}'";
    $result = mysql_query($query) or die("Unable to retrieve connections for {$id} from the database.");
    while ($c_array = mysql_fetch_array($result, MYSQL_BOTH)) {
        $connection = new Connection($c_array['id'], $c_array['type'], $c_array['start'], $c_array['end'], $c_array['day'], $c_array['duration']);
        $line = $marker->getLine($c_array['line']);
        if ($line == null) {
            // line doesn't exist yet, so create it
            $line_query = "SELECT * FROM lines WHERE name='" . $c_array['line'] . "'";
            $line_result = mysql_query($line_query) or die("Unable to retrieve line information for " . $c_array['line'] . " from the database.");
            if (count($line_result) > 1) {
                echo "algorithm.getMarker() returned more than one result when retrieving line " . $c_array['line'];
            }
            $line_array = mysql_fetch_array($line_result, MYSQL_BOTH);
            $line = new Line($line_array['img'], $line_array['url'], $line_array['name']);
            // add the line to the marker
            $marker->addLine($line);
        }
        // add the connection to the line
        $line->addConnection($connection);
    }
    // connection loop
    // done, return marker
    return $marker;
}