Tdt\Core\Formatters\KMLFormatter::getArray PHP Method

getArray() private static method

Create the geo graphical placemarks in kml Currently only properties that are not nested are picked up.
private static getArray ( $dataObj, $geo )
    private static function getArray($dataObj, $geo)
    {
        $body = "";
        $data = $dataObj->data;
        if (is_object($data)) {
            $data = (array) $data;
        }
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $entry = $value;
            } elseif (is_object($value)) {
                $entry = get_object_vars($value);
            }
            // We assume that if longitude exists, latitude does as well if the geometry is a single point
            // A point can either be a single column value, or split up in a latitude and longitude
            $geo_type = 'point';
            $is_point = count($geo) > 1 || !empty($geo['point']);
            if (!$is_point) {
                $geo_type = key($geo);
                $column_name = $geo[$geo_type];
            }
            if (!empty($entry)) {
                $name = htmlspecialchars($key);
                if (!empty($entry['name'])) {
                    $name = $entry['name'];
                }
                if (!empty(self::$map_property) && !empty($entry[self::$map_property])) {
                    $name = $entry[self::$map_property];
                }
                $extendeddata = self::getExtendedDataElement($entry);
                $description = "";
                if (!empty($key) && is_numeric($key)) {
                    $description = "<![CDATA[<a href='" . \URL::to($dataObj->definition['collection_uri'] . '/' . $dataObj->definition['resource_name']) . '/' . htmlspecialchars($key) . ".map'>" . \URL::to($dataObj->definition['collection_uri'] . '/' . $dataObj->definition['resource_name']) . '/' . htmlspecialchars($key) . "</a>]]>";
                }
                $body .= "<Placemark><name>" . $name . "</name><description>" . $description . "</description>";
                $body .= $extendeddata;
                if ($is_point) {
                    if (count($geo) == 2) {
                        $point = $entry[$geo['longitude']] . ',' . $entry[$geo['latitude']];
                    } elseif (count($geo) == 3) {
                        $point = $entry[$geo['longitude']] . ',' . $entry[$geo['latitude']] . ',' . $entry[$geo['elevation']];
                    } else {
                        $point = $entry[$geo['point']];
                    }
                    $body .= "<Point><coordinates>" . $point . "</coordinates></Point>";
                } else {
                    switch ($geo_type) {
                        case 'polylinez':
                            $body .= "<MultiGeometry>";
                            foreach (explode(';', $entry[$geo['polylinez']]) as $coord) {
                                $body .= "<LineString><coordinates>" . $coord . "</coordinates></LineString>";
                            }
                            $body .= "</MultiGeometry>";
                            break;
                        case 'polyline':
                            $body .= "<MultiGeometry>";
                            foreach (explode(';', $entry[$geo['polyline']]) as $coord) {
                                $body .= "<LineString><coordinates>" . $coord . "</coordinates></LineString>";
                            }
                            $body .= "</MultiGeometry>";
                            break;
                        case 'polygonz':
                            $body .= "<Polygon><outerBoundaryIs><LinearRing><coordinates>" . $entry[$geo['polygonz']] . "</coordinates></LinearRing></outerBoundaryIs></Polygon>";
                            break;
                        case 'polygon':
                            $body .= "<Polygon><outerBoundaryIs><LinearRing><coordinates>" . $entry[$geo['polygon']] . "</coordinates></LinearRing></outerBoundaryIs></Polygon>";
                            break;
                        case 'multipoinz':
                            $body .= "<MultiGeometry>";
                            foreach (explode(';', $entry[$geo['multipointz']]) as $point) {
                                $body .= '<Point><coordinates>' . $point . '</coordinates></Point>';
                            }
                            $body .= '</MultiGeometry>';
                            break;
                        case 'multipoint':
                            $body .= "<MultiGeometry>";
                            foreach (explode(';', $entry[$geo['multipoint']]) as $point) {
                                $body .= '<Point><coordinates>' . $point . '</coordinates></Point>';
                            }
                            $body .= '</MultiGeometry>';
                            break;
                        default:
                            \App::abort(500, "The geo type, {$geo_type}, is not supported. Make sure the (combined) geo type is correct. (e.g. latitude and longitude are given).");
                            break;
                    }
                }
                $body .= "</Placemark>";
            }
        }
        return $body;
    }