diff --git a/build/api/module/message.php b/build/api/module/message.php index e937631..71131f4 100644 --- a/build/api/module/message.php +++ b/build/api/module/message.php @@ -119,20 +119,35 @@ class message public function PUT_emergency($argv){ extract($argv); + /* (1) Create emergenct + ---------------------------------------------------------*/ + /* (1) Try to create entry */ + $updated = Repo::request('emergency', 'update', $id, $message); + + /* (2) If cannot create -> dispatch error */ + if( $updated === false ) + return ['error' => new Error(Err::RepoError)]; + + + + /* (2) Send to WebSocket + ---------------------------------------------------------*/ + /* (1) Create socket */ $wsi = new wsinterop("localhost",9998); + /* (2) Send data */ $wsi->send([ - "operation" => "UpdMessage", - "id" => $id, - "message" => $message, + "operation" => "UpdMessage", + "id" => "$id", + "message" => $message, "channelType" => "Emergency", - "channelName" => is_null($URL_0) ? "" : "$URL_0" + "channelName" => "$URL_0" ]); + /* (3) Close socket */ $wsi->close(); - return ["sent" => true]; - //TODO: tout poster dans la BDD + return ['updated' => true]; } public function POST_event($argv){