php functions to Store data
This commit is contained in:
parent
403099ebd6
commit
a945fca764
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -125,8 +125,7 @@
|
|||
|
||||
actualTopic = JSON.parse(localStorage.getItem("actualTopic"))
|
||||
if(!actualTopic) {
|
||||
actualTopic = {}
|
||||
reset()
|
||||
initializeNewTopic()
|
||||
}
|
||||
document.getElementById("topicInput").value = actualTopic.name
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
function initializeNewTopic() {
|
||||
actualTopic = {"name": "", "id": randomId()}
|
||||
reset()
|
||||
document.getElementById("topicInput").value = actualTopic.name
|
||||
}
|
||||
|
||||
function reset() {
|
||||
actualTopic.watches = [{"actions": []}, {"actions": []}, {"actions": []}]
|
||||
saveActualTopicToLocalStorage()
|
||||
saveActualTopic()
|
||||
}
|
||||
|
||||
function resetButton() {
|
||||
|
@ -12,7 +18,7 @@ function resetButton() {
|
|||
function buttonDeleteAllClosedTopics() {
|
||||
if(confirm("Sollen alle abgeschlossenen Themen gelöscht werden?")) {
|
||||
closedTopics = []
|
||||
saveClosedTopicsToLocalStorage()
|
||||
saveClosedTopics()
|
||||
refreshClosedTopics()
|
||||
}
|
||||
}
|
||||
|
@ -43,17 +49,14 @@ function closeTopic() {
|
|||
}
|
||||
actualTopic.name = name
|
||||
closedTopics.push(actualTopic)
|
||||
actualTopic = {"name": ""}
|
||||
reset()
|
||||
document.getElementById("topicInput").value = actualTopic.name
|
||||
saveActualTopicToLocalStorage()
|
||||
saveClosedTopicsToLocalStorage()
|
||||
saveClosedTopics()
|
||||
refreshClosedTopics()
|
||||
initializeNewTopic()
|
||||
}
|
||||
|
||||
function deleteTopic(topicIndex) {
|
||||
closedTopics = closedTopics.slice(0, topicIndex).concat(closedTopics.slice(topicIndex+1))
|
||||
saveClosedTopicsToLocalStorage()
|
||||
saveClosedTopics()
|
||||
refreshClosedTopics()
|
||||
}
|
||||
|
||||
|
@ -64,14 +67,14 @@ function reopenTopic(topicIndex) {
|
|||
actualTopic = closedTopics[topicIndex]
|
||||
document.getElementById("topicInput").value = actualTopic.name
|
||||
deleteTopic(topicIndex)
|
||||
saveClosedTopicsToLocalStorage()
|
||||
saveActualTopicToLocalStorage()
|
||||
saveClosedTopics()
|
||||
saveActualTopic()
|
||||
}
|
||||
|
||||
function start(watchIndex) {
|
||||
stop()
|
||||
actualTopic.watches[watchIndex].actions.push({"type": "start", "time": new Date().getTime()})
|
||||
saveActualTopicToLocalStorage()
|
||||
saveActualTopic()
|
||||
}
|
||||
|
||||
function stop() {
|
||||
|
@ -82,7 +85,7 @@ function stop() {
|
|||
}
|
||||
}
|
||||
});
|
||||
saveActualTopicToLocalStorage()
|
||||
saveActualTopic()
|
||||
}
|
||||
|
||||
function calcPercForWatch(watchIndex, topic) {
|
||||
|
@ -181,14 +184,18 @@ function refreshClosedTopics() {
|
|||
|
||||
function saveActualTopicName() {
|
||||
actualTopic.name = document.getElementById("topicInput").value
|
||||
saveActualTopicToLocalStorage()
|
||||
saveActualTopic()
|
||||
}
|
||||
|
||||
function saveActualTopicToLocalStorage() {
|
||||
|
||||
|
||||
function saveActualTopic() {
|
||||
//save it to LocalStorage
|
||||
localStorage.setItem("actualTopic", JSON.stringify(actualTopic))
|
||||
}
|
||||
|
||||
function saveClosedTopicsToLocalStorage() {
|
||||
function saveClosedTopics() {
|
||||
//save it to LocalStorage
|
||||
localStorage.setItem("closedTopics", JSON.stringify(closedTopics))
|
||||
}
|
||||
|
||||
|
@ -205,3 +212,9 @@ function elt (type, attrs, ...children) {
|
|||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// random.ts
|
||||
function randomId() {
|
||||
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
||||
return uint32.toString(16);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
|
||||
function read_xls_file($filename){
|
||||
$fileContent = [];
|
||||
if ($xlsx = SimpleXLSX::parse($filename)) {
|
||||
$fileContent = ($xlsx->rows());
|
||||
} else {
|
||||
echo SimpleXLSX::parseError();
|
||||
}
|
||||
return $fileContent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function write_xlsxFile($filename, $data) {
|
||||
|
||||
foreach ($data as $row) {
|
||||
echo "new Row: <br>";
|
||||
foreach ($row as $cell) {
|
||||
echo $cell." ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$xlsx = \Shuchkin\SimpleXLSXGen::fromArray($data);
|
||||
$xlsx->saveAs($filename);
|
||||
}
|
Loading…
Reference in New Issue