diff --git a/dataCollector/dataCollector.php b/dataCollector/dataCollector.php index 3bdd00a..566417b 100644 --- a/dataCollector/dataCollector.php +++ b/dataCollector/dataCollector.php @@ -1,4 +1,5 @@ id, @@ -23,22 +24,32 @@ function findRowIndex($id, $data) { return $rowCounter + 1; } -$entityBody = '{"lastSave": 0, "timeWatchM": 23, "timeWatchW": 89, "timeWatchD": 34, "countWatchM": 65, "countWatchW": 56, "countWatchD": 9, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}'; -if ($_SERVER['REQUEST_METHOD'] === 'PUT') { +$entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}'; +if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $entityBody = file_get_contents('php://input'); -} + $entityBodyObject = json_decode($entityBody); -$entityBodyObject = json_decode($entityBody); + echo "POST Request received.
"; + if(property_exists($entityBodyObject, "id")) { + $data = read_xls_file($fileName); -require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/read_write_xlsx.php'; -if(property_exists($entityBodyObject, "id")) { - $data = read_xls_file($fileName); - $rowIndex = findRowIndex($entityBodyObject->id, $data); - $data[$rowIndex] = objectToArray($entityBodyObject, $entityBody); - write_xlsxFile($fileName, $data); + foreach ($data as $row) { + echo "new Row:
"; + foreach ($row as $cell) { + echo $cell." "; + } + } + + $rowIndex = findRowIndex($entityBodyObject->id, $data); + $data[$rowIndex] = objectToArray($entityBodyObject, $entityBody); + write_xlsxFile($fileName, $data); + echo "
Data saved.
"; + } } + + diff --git a/spreadSheetReader/read_write_xlsx.php b/spreadSheetReader/read_write_xlsx.php index 82f87cb..1421736 100644 --- a/spreadSheetReader/read_write_xlsx.php +++ b/spreadSheetReader/read_write_xlsx.php @@ -14,15 +14,6 @@ function read_xls_file($filename){ function write_xlsxFile($filename, $data) { - - foreach ($data as $row) { - echo "new Row:
"; - foreach ($row as $cell) { - echo $cell." "; - } - } - - $xlsx = SimpleXLSXGen::fromArray($data); $xlsx->saveAs($filename); } \ No newline at end of file