Last active
March 15, 2017 09:52
-
-
Save jdpedrie/a9973a3835535e9cef13b2fa5b3c6f96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Google\Cloud\Datastore\DatastoreClient; | |
$datastore = new DatastoreClient([ | |
'projectId' => $projectId | |
]); | |
// I aliased $_POST, but you don't need to if you don't want to. | |
// This is where I'd perform all the validation and sanitation on the data that was given by the user. | |
$inputData = $_POST; | |
// Make sure you're setting $roomName somewhere. | |
$roomName = 'foo'; | |
$name = $roomName . $inputData['timestamp']; | |
// Create a key with a name. | |
$key = $datastore->key('RoomUsage', $name); | |
// We'll create our entity, give it the key we just created, then fill it with data from the form. | |
$roomUsage = $datastore->entity($key, [ | |
'Headcount' => ($inputData['countinput'] === '') | |
? $inputData['countslider'] | |
: $inputData['countinput'], | |
'Timestamp' => $inputData['timestamp'], | |
'EnteredBy' => $inputData['userid'], | |
'RoomID' => $inputData['roomid'], | |
'Activiy' => $inputData['activity'], | |
'Estimate' => $inputData['estimate'], | |
'NotAudited' => $inputData['notaudited'], | |
'Reason' => $inputData['reason'] | |
]); | |
// Finally, send the entity to Datastore. | |
$datastore->upsert($roomUsage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this. It is a thing of beauty.