Ejemplo n.º 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;
}
Ejemplo n.º 2
0
/**
    @deprecated?
*/
function loadFromArray($array)
{
    $markers = array();
    $id = "";
    foreach ($array as $marker_array) {
        $marker = new Marker($marker_array[0]['lat'], $marker_array[0]['lng'], $marker_array[0]['id'], $marker_array[0]['name']);
        $id = $marker_array[0]['id'];
        echo "functions.load: processing {$id}<br/>\n";
        $count = count($marker_array);
        for ($i = 1; $i < $count; $i++) {
            $line_array = $marker_array[$i];
            $line = new Line($line_array[0]['img'], $marker_array[0]['url'], $marker_array[0]['name']);
            $count1 = count($line_array);
            for ($j = 1; $j < $count1; $j++) {
                $connection_array = $line_array[$j];
                $connection = new Connection($connection_array[0]['id'], $connection_array[0]['type'], $connection_array[0]['start'], $connection_array[0]['end'], $connection_array[0]['duration']);
                $line->addConnection($connection);
            }
            $marker->addLine($line);
        }
        $markers[$id] = $marker;
    }
    return $markers;
}
Ejemplo n.º 3
0
/**
    Retrieves the markers from the DB and loads them into an array. It creates full
    Marker objects with Line and Connection objects.
    
    @return an array of Markers
*/
function retrieveMarkers()
{
    $debug = false;
    $markers = array();
    $query = 'SELECT * FROM markers';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {
        $id = $line['id'];
        $lat = $line['lat'];
        $lng = $line['lng'];
        $name = $line['name'];
        $url = $line['url'];
        if ($debug) {
            echo "building marker: {$name} ({$id})<br/>";
        }
        $marker = new Marker($lat, $lng, $id, $name);
        $marker->setURL($url);
        // grab all connections
        $conn_query = "SELECT * FROM connections WHERE id='" . $id . "'";
        $conn_result = mysql_query($conn_query) or die('Query failed: ' . mysql_error());
        $lines = array();
        $line_names = array();
        while ($conn = mysql_fetch_array($conn_result, MYSQL_BOTH)) {
            // grab all variables from DB
            $marker_id = $conn['marker_id'];
            $day = $conn['day'];
            $duration = $conn['duration'];
            $line = $conn['line'];
            $type = $conn['type'];
            $start = $conn['start'];
            $end = $conn['end'];
            if ($debug) {
                echo "-&gt;found connection: {$marker_id}<br/>";
            }
            // create a new connection
            $connection = new Connection($marker_id, $type, $start, $end, $day, $duration);
            $marker_line = $lines["{$line}"];
            if (is_null($marker_line)) {
                $marker_line = array();
            }
            $marker_line[] = $connection;
            // add it to an array. we need it later.
            if ($debug) {
                echo "-&gt;found line: {$line}<br/>";
            }
            $lines["{$line}"] = $marker_line;
            if (!in_array($line, $line_names)) {
                if ($debug) {
                    echo "adding {$line} to line_names<br/>";
                }
                $line_names[] = $line;
            }
        }
        // connection loop
        if ($debug) {
            echo "line_names count: " . count($line_names) . "<br/>";
        }
        // retrieved all connections and set them in their appropriate lines.
        // now we need to create the lines
        foreach ($line_names as $line_name) {
            if ($debug) {
                echo "-&gt;looking at line: {$line_name}<br/>";
            }
            // for each line, grab the data from the database
            $line_query = "SELECT * FROM `lines` WHERE name='" . $line_name . "'";
            $line_result = mysql_query($line_query) or die('Query failed: ' . mysql_error());
            // the line_name is the unique key for that table, so we only need to get the first one
            $line_array = mysql_fetch_array($line_result, MYSQL_BOTH);
            $lname = $line_array['name'];
            $lurl = $line_array['url'];
            $limg = $line_array['img'];
            $line = new Line($limg, $lurl, $lname);
            if ($debug) {
                echo "--&gt;found line: " . $lname . "<br/>";
            }
            // now add all the connections
            $connections = $lines["{$line_name}"];
            foreach ($connections as $connection) {
                // each one is a connection object from above. add it
                $line->addConnection($connection);
                if ($debug) {
                    echo "---&gt;adding " . $connection->id . " to {$line_name}<br/>";
                }
            }
            // now add the line to the marker
            $marker->addLine($line);
            if ($debug) {
                echo "--&gt;adding {$line_name} to {$name}<br/>";
            }
        }
        // line loop
        // the marker object is created and populated. add to the markers array.
        $markers["{$id}"] = $marker;
        if ($debug) {
            echo "adding {$id} to markers<br/>";
        }
    }
    // marker loop
    return $markers;
}