Changeset 7631 for trunk/src/inc/KMLFile.class.php
- Timestamp:
- Mar 30, 2010, 8:51:44 PM (13 years ago)
- Location:
- trunk/src/inc
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/inc/KMLFile.class.php
r7628 r7631 7 7 8 8 class KMLFile { 9 final$template = '9 private $template = ' 10 10 <?xml version="1.0" encoding="UTF-8"?> 11 11 <kml xmlns="http://www.opengis.net/kml/2.2"> 12 12 %CONTENT% 13 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'); 14 16 15 17 private $KMLPlacemarks = array(); … … 20 22 * Function: Creating a new KMLFile 21 23 */ 22 function __construct() {24 public function __construct() { 23 25 } 24 26 25 function addPlacemark(KMLPlacemark $placemark) {27 public function addPlacemark(KMLPlacemark $placemark) { 26 28 $this->KMLPlacemarks[] = $placemark; 27 29 } 28 30 29 function addPlacemark(string $name, string $description, float $xcoordinate, float $ycoordinate) { 30 $placemark = new KMLPlacemark(); 31 $placemark->setName($name); 32 $placemark->setDescription($description); 33 $placemark->setXCoordinate($xcoordinate); 34 $placemark->setYCoordinate($ycoordinate); 35 36 $this->KMLPlacemarks[] = $placemark; 37 } 38 39 function toString() { 40 $toString = $template; 31 public function toString() { 32 $toString = $this->template; 41 33 42 34 $placemarkString = ''; 43 35 $placemarkCount = count($this->KMLPlacemarks); 44 36 for ($i = 0; $i < $placemarkCount; $i++) { 45 $placemarkString .= $this->KMLPlacemarks ->toString();37 $placemarkString .= $this->KMLPlacemarks[$i]->toString(); 46 38 } 47 39 48 $toString = preg_replace('%CONTENT%', $placemarkString, $toString);40 $toString = str_replace('%CONTENT%', $placemarkString, $toString); 49 41 50 42 return $toString; 51 43 } 52 44 53 function write(string$filename) {45 public function write($filename) { 54 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 } 55 68 } 56 69 }
Note:
See TracChangeset
for help on using the changeset viewer.