diff --git a/dataCollector/dataCollector.php b/dataCollector/dataCollector.php index 26c3c12..8963c64 100644 --- a/dataCollector/dataCollector.php +++ b/dataCollector/dataCollector.php @@ -13,15 +13,22 @@ function objectToArray($object, $fullJSON) { $object -> countWatchD]; } -function findRowIndex($id, $data) { - $rowCounter = -1; - foreach ($data as $row) { - $rowCounter ++; - if($row[0] == $id) { - return $rowCounter; - } - } - return $rowCounter + 1; +$databaseAddress = "127.0.0.1"; +$databasePort = "3306"; +$databaseName = "u517357132_genderwatchpro"; +$databaseUser = "u517357132_genderwatchpro"; +$databasePassword = "zU!7gRHA6x"; +$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName); + + +$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName); + +function saveToDatabase($contentArray, $mysqli) { + $mysqli->query("INSERT INTO `u517357132_genderwatchpro` (`id`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ($contentArray[0], $contentArray[2], $contentArray[3], $contentArray[4], $contentArray[5], $contentArray[6], $contentArray[7], $contentArray[8]) ON DUPLICATE KEY UPDATE `id` = $contentArray[0]"); +} + +function getFromDatabase() { + } $entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}'; @@ -32,20 +39,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo "POST Request received.
"; if(property_exists($entityBodyObject, "id")) { - $data = read_xls_file($fileName); - - 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); + saveToDatabase(objectToArray($entityBodyObject, $entityBody), $mysqli); echo "
Data saved.
"; } +} elseif($_SERVER['REQUEST_METHOD'] === 'GET') { + download_xlsxFile(getFromDatabase()); } else { echo "invalid Request.
Type: ".$_SERVER['REQUEST_METHOD']; } diff --git a/spreadSheetReader/read_write_xlsx.php b/spreadSheetReader/read_write_xlsx.php index 1421736..577dfd7 100644 --- a/spreadSheetReader/read_write_xlsx.php +++ b/spreadSheetReader/read_write_xlsx.php @@ -1,19 +1,9 @@ rows()); - } else { - echo SimpleXLSX::parseError(); - } - return $fileContent; -} - -function write_xlsxFile($filename, $data) { +function download_xlsxFile($data) { $xlsx = SimpleXLSXGen::fromArray($data); - $xlsx->saveAs($filename); + $xlsx->downloadAs("data.xlsx"); } \ No newline at end of file