Skip to content
Snippets Groups Projects
Commit 3389d546 authored by Addin Munawwar's avatar Addin Munawwar
Browse files

feat: integrate php-soap page

parent 5d8c8e96
No related merge requests found
...@@ -12,9 +12,9 @@ class SoapConsumer { ...@@ -12,9 +12,9 @@ class SoapConsumer {
'exceptions' => true, // Enables exceptions for HTTP errors 'exceptions' => true, // Enables exceptions for HTTP errors
"encoding" => "UTF-8", "encoding" => "UTF-8",
"stream_context" => stream_context_create([ "stream_context" => stream_context_create([
'http' => [ 'http' => array(
'ApiKey' => $_ENV['SOAP_API_KEY'] 'header' => 'ApiKey: ' . $_ENV['SOAP_API_KEY'],
] ),
]) ])
]; ];
...@@ -22,43 +22,6 @@ class SoapConsumer { ...@@ -22,43 +22,6 @@ class SoapConsumer {
$this->requestClient = new SoapClient($_ENV['SOAP_URL'] . "request?wsdl", $options); $this->requestClient = new SoapClient($_ENV['SOAP_URL'] . "request?wsdl", $options);
$this->apiKey = $_ENV['SOAP_API_KEY']; $this->apiKey = $_ENV['SOAP_API_KEY'];
$headerBody = new SoapVar($this->apiKey, XSD_STRING, null, null, 'ApiKey', 'http://ws.soap.com/');
$header = new SoapHeader('http://ws.soap.com/', 'ApiKey', $headerBody);
$this->subscriptionClient->__setSoapHeaders(array(
new SoapHeader(
'http://ws.soap.com/',
'ApiKey',
$this->apiKey,
false
),
new SoapHeader(
'ns2',
'ApiKey',
$this->apiKey,
false
),
new SoapHeader(
'ns1',
'ApiKey',
$this->apiKey,
false
),
$header
));
$this->subscriptionClient->__setSoapHeaders($header);
$this->requestClient->__setSoapHeaders(
new SoapHeader(
'http://ws.soap.com/',
'ApiKey',
$this->apiKey,
false
)
);
} }
public function makeRequest($requestBy, $to, $requesterEmail) { public function makeRequest($requestBy, $to, $requesterEmail) {
...@@ -68,121 +31,22 @@ class SoapConsumer { ...@@ -68,121 +31,22 @@ class SoapConsumer {
'RequesterEmail' => $requesterEmail, 'RequesterEmail' => $requesterEmail,
]); ]);
$soapData = json_encode($response);
$soapData = json_decode($soapData, true);
return $response;
// $apiKey = $this->apiKey;
// // Construct SOAP request XML
// $requestXml = <<<XML
// <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
// <Header>
// <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey>
// </Header>
// <Body>
// <MakeRequest xmlns="http://ws.soap.com/">
// <RequestBy xmlns="">$requestBy</RequestBy>
// <To xmlns="">$to</To>
// <RequesterEmail xmlns="">$requesterEmail</RequesterEmail>
// </MakeRequest>
// </Body>
// </Envelope>
// XML;
// $endpoint = $_ENV['SOAP_URL'] . "request";
// $headers = [
// 'Content-Type: text/xml; charset=utf-8',
// 'Content-Length: ' . strlen($requestXml),
// 'SOAPAction: http://ws.soap.com/MakeRequest',
// ];
// $ch = curl_init($endpoint);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// // Send SOAP request return $soapData;
// $responseXml = curl_exec($ch);
// curl_close($ch);
// return $responseXml;
} }
public function getSubscriptionOf($requester) { public function getSubscriptionOf($requester) {
// Define the SOAP request parameters
$requestParams = array(
'ApiKey' => $this->apiKey,
'GetSubscriptionOf' => array(
'Username' => $requester,
),
);
$res = $this->subscriptionClient->__soapCall('GetSubscriptionOf', array($requestParams));
// Process the result
var_dump($res);
// $response = $this->subscriptionClient->GetSubscriptionOf([ $response = $this->subscriptionClient->GetSubscriptionOf([
// 'Username' => $requester, 'Username' => $requester,
// ]); ]);
// echo htmlentities( $this->subscriptionClient->__getLastRequest());
// return $response;
// $apiKey = $this->apiKey;
// // Construct SOAP request XML
// $requestXml = <<<XML
// <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
// <Header>
// <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey>
// </Header>
// <Body>
// <GetSubscriptionOf xmlns="http://ws.soap.com/">
// <Username xmlns="">$requester</Username>
// </GetSubscriptionOf>
// </Body>
// </Envelope>
// XML;
// $endpoint = $_ENV['SOAP_URL'] . "subscription";
// $headers = [
// 'Content-Type: text/xml; charset=utf-8',
// 'Content-Length: ' . strlen($requestXml),
// 'SOAPAction: http://ws.soap.com/GetSubscriptionOf',
// ];
// $ch = curl_init($endpoint);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// // Send SOAP request $soapData = json_encode($response);
// $dataString = curl_exec($ch); $soapData = json_decode($soapData, true);
// curl_close($ch);
// // Use regular expression to extract usernames
// preg_match_all('/\+07:00(.*?)true/', $dataString, $matches);
// // Extract the usernames from the matches array return $soapData;
// $usernames = $matches[1];
// for ($i = 0; $i < count($usernames); $i++) {
// // if the username started with 2023
// if (substr($usernames[$i], 0, 4) == "2023") {
// $usernames[$i] = substr($usernames[$i], 29);
// }
// }
// // Print the result
// echo "usernames = [" . implode(', ', $usernames) . "]\n";
// return $dataString;
} }
} }
?> ?>
\ No newline at end of file
...@@ -25,11 +25,30 @@ class UserController extends Controller implements ControllerInterface ...@@ -25,11 +25,30 @@ class UserController extends Controller implements ControllerInterface
} }
switch ($_SERVER['REQUEST_METHOD']) { switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
require_once __DIR__ . '/../clients/SOAPConsumer.php';
$soap = new SoapConsumer();
$user = $this->model->getUserByUsername($_SESSION['username']);
$userEmail = $user['email'];
$soapData = $soap->makeRequest($_SESSION['username'], $_POST['curator'], $userEmail);
echo $soapData["Response"]["message"];
case 'GET': case 'GET':
// show the login page // show the login page
require_once __DIR__ . '/../clients/SOAPConsumer.php';
$soap = new SoapConsumer();
$soapData = $soap->getSubscriptionOf($_SESSION['username']);
$subData = $soapData["Response"]["data"];
$data = [ $data = [
'username' => $_SESSION['username'] 'username' => $_SESSION['username'],
'subscription' => $subData
]; ];
$mySubscriptionView = $this->view('user', 'MySubscriptionView', $data); $mySubscriptionView = $this->view('user', 'MySubscriptionView', $data);
$mySubscriptionView->render(); $mySubscriptionView->render();
break; break;
......
...@@ -21,26 +21,41 @@ ...@@ -21,26 +21,41 @@
<!-- Navigation bar --> <!-- Navigation bar -->
<?php include(dirname(__DIR__) . '../../components/Navbar.php') ?> <?php include(dirname(__DIR__) . '../../components/Navbar.php') ?>
<div class="content"> <div class="content">
<h1><?php $this->data['username']?>'s Subscription</h1> <h1><?php echo $this->data['username']?>'s Subscription</h1>
<!-- Todo Routing --> <!-- Todo Routing -->
<a href="/premium">++ Add Subscription</a> <a href="/premium">+ Add Subscription</a>
<table border="1" class="styled-table"> <?php
<thead> if (count($this->data['subscription']) > 0) {
<tr> echo "<table border=\"1\" class=\"styled-table\">";
<th>Curator Name</th> echo "<thead>";
<th>Action</th>
</tr>
</thead>
<?php
$authors = $this->data['authors'];
foreach ($authors as $author) {
echo "<tr>"; echo "<tr>";
echo "<td>" . $author['full_name'] . "</td>"; echo "<th>Curator Name</th>";
echo '<td><a href="/author/update/' . $author['author_id'] .'">Pending/Details</a></td>'; echo "<th>Action</th>";
echo "</tr>"; echo "</tr>";
echo "</thead>";
} else {
echo "<h2>You have no subscription</h2>";
}
?>
<?php
if (count($this->data['subscription']) > 0) {
$subs = $this->data['subscription']['item'];
foreach ($subs as $sub) {
$raw_data = file_get_contents('http://host.docker.internal:8040/api/curator/' . $sub['curator']);
$data = json_decode($raw_data, true);
echo var_dump($data);
$colId = $data['collectionId'];
echo "<tr>";
echo "<td>" . $sub['curator'] . "</td>";
echo '<td><a href="/premium/detail/' . $colId . '">Details</a></td>';
echo "</tr>";
}
} }
?> ?>
</table> </table>
</div> </div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment