| 1 | <?
|
|---|
| 2 | /*
|
|---|
| 3 | * Project: NodeMap2.0
|
|---|
| 4 | * File: KMLHandler.class.php
|
|---|
| 5 | * Purpose: Creating of editing KML files
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | class KMLFile {
|
|---|
| 9 | private $template = '
|
|---|
| 10 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 11 | <kml xmlns="http://www.opengis.net/kml/2.2">
|
|---|
| 12 | %CONTENT%
|
|---|
| 13 | </kml>';
|
|---|
| 14 | private $fileFirst = 'type,host_name,has_been_checked,check_execution_time,current_state,last_hard_state,last_check,problem_has_been_acknowledged';
|
|---|
| 15 | private $fileContent = array('string', 'string', 'integer', 'double', 'integer', 'integer', 'integer', 'integer');
|
|---|
| 16 |
|
|---|
| 17 | private $KMLPlacemarks = array();
|
|---|
| 18 |
|
|---|
| 19 | /*
|
|---|
| 20 | * Function: __construct (constructor)
|
|---|
| 21 | * Parameters: -
|
|---|
| 22 | * Function: Creating a new KMLFile
|
|---|
| 23 | */
|
|---|
| 24 | public function __construct() {
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | public function addPlacemark(KMLPlacemark $placemark) {
|
|---|
| 28 | $this->KMLPlacemarks[] = $placemark;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | public function toString() {
|
|---|
| 32 | $toString = $this->template;
|
|---|
| 33 |
|
|---|
| 34 | $placemarkString = '';
|
|---|
| 35 | $placemarkCount = count($this->KMLPlacemarks);
|
|---|
| 36 | for ($i = 0; $i < $placemarkCount; $i++) {
|
|---|
| 37 | $placemarkString .= $this->KMLPlacemarks[$i]->toString();
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | $toString = str_replace('%CONTENT%', $placemarkString, $toString);
|
|---|
| 41 |
|
|---|
| 42 | return $toString;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | public function write($filename) {
|
|---|
| 46 | // TODO: Write KMLFile to a KML file
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | public function parseFile($file) {
|
|---|
| 50 | $fileContents = explode("\r\n", $nodeStatus->getFile());
|
|---|
| 51 |
|
|---|
| 52 | if ($fileContents[0] != $this->fileFirst) {
|
|---|
| 53 | // TODO: Better error description
|
|---|
| 54 | trigger_error();
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | $lines = count($fileContents);
|
|---|
| 58 | for ($i = 1; $i < count($lines); $i++) {
|
|---|
| 59 | $lineContent = explode(',', $fileContents[$i]);
|
|---|
| 60 |
|
|---|
| 61 | if (count($lineContent) != count($this->fileContent)) {
|
|---|
| 62 | // TODO: Better error description
|
|---|
| 63 | trigger_error();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // TODO: Process all lines and create KMLPlacemark objects we can add to a new KMLFile object
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | ?>
|
|---|