Added api: POST message/emergency (with db)

This commit is contained in:
xdrm-brackets 2017-12-08 03:18:29 +01:00
parent ec59cde080
commit 8e78142119
1 changed files with 49 additions and 11 deletions

View File

@ -26,23 +26,61 @@ class message
public function POST_emergency($argv){ public function POST_emergency($argv){
extract($argv); extract($argv);
$wsi = new wsinterop("localhost",9998); /* (1) Get ID_USER if connected
---------------------------------------------------------*/
$id_user = null;
$name = null;
if( count($_SESSSION['ADMIN']) > 0 )
$id_user = $_SESSION['ADMIN']['id'];
elseif( count($_SESSSION['USER']) > 0 )
$id_user = $_SESSION['USER']['id'];
else
$name = $_SESSION['NAME'];
/* (2) Create emergenct
---------------------------------------------------------*/
/* (1) Try to create entry */
$id_created = Repo::request('emergency', 'create',
$id_user,
$name,
time(),
$message,
0,
$location[0],
is_null($URL_0) ? '' : $URL_0
);
/* (2) If cannot create -> dispatch error */
if( $id_created === false )
return ['error' => new Error(Err::RepoError)];
/* (3) Send to WebSocket
---------------------------------------------------------*/
/* (1) Open socket */
$wsi = new wsinterop('localhost', 9998);
/* (2) Send data */
$wsi->send([ $wsi->send([
"operation" => "PostMessage", 'operation' => 'PostMessage',
"message" => $message, 'message' => $message,
"username" => $_SESSION['NAME'], 'username' => $_SESSION['NAME'],
"location" => $location, 'location' => $location,
//TODO implémenter la récupération d'id depuis la bdd 'id' => $id_created,
"id" => uniqid(), 'channelType' => 'Emergency',
"channelType" => "Emergency", 'channelName' => is_null($URL_0) ? '' : $URL_0
"channelName" => is_null($URL_0) ? "" : "$URL_0"
]); ]);
/* (3) Close socket */
$wsi->close(); $wsi->close();
return ["sent" => true];
//TODO: tout poster dans la BDD return ['sent' => true];
} }
public function DELETE_emergency($argv){ public function DELETE_emergency($argv){