php functions to Store data
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$fileName = $_SERVER['DOCUMENT_ROOT'] . '/data/data.xlsx';
|
||||
function objectToArray($object, $fullJSON) {
|
||||
return [$object -> id,
|
||||
$object -> lastSave,
|
||||
$fullJSON,
|
||||
$object -> timeWatchM,
|
||||
$object -> timeWatchW,
|
||||
$object -> timeWatchD,
|
||||
$object -> countWatchM,
|
||||
$object -> countWatchW,
|
||||
$object -> countWatchD];
|
||||
}
|
||||
|
||||
function findRowIndex($id, $data) {
|
||||
$rowCounter = -1;
|
||||
foreach ($data as $row) {
|
||||
$rowCounter ++;
|
||||
if($row[0] == $id) {
|
||||
return $rowCounter;
|
||||
}
|
||||
}
|
||||
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 = file_get_contents('php://input');
|
||||
}
|
||||
|
||||
$entityBodyObject = json_decode($entityBody);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user