|
|
@@ -1,26 +1,49 @@
|
|
|
<?php
|
|
|
|
|
|
-// Get all of the Opentalent structures from the directly Opentalent DB (API Platform is too slow with so many records),
|
|
|
-// compress the response, and send it to the client
|
|
|
+namespace Opentalent\OtCore\Http;
|
|
|
|
|
|
-if ($_SERVER['HTTP_HOST'] == 'typo3' | $_SERVER['HTTP_HOST'] == 'local.sub.opentalent.fr') {
|
|
|
- $db_host = 'db';
|
|
|
-} elseif ($_SERVER['HTTP_HOST'] == 'preprod.opentalent.fr') {
|
|
|
- $db_host = 'localhost';
|
|
|
-} else {
|
|
|
- $db_host = 'prod-back';
|
|
|
-}
|
|
|
+use PDO;
|
|
|
+use TYPO3\CMS\Core\Http\HtmlResponse;
|
|
|
+use TYPO3\CMS\Core\Http\JsonResponse;
|
|
|
+use TYPO3\CMS\Core\Http\Response;
|
|
|
+use TYPO3\CMS\Core\Http\ServerRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Actions for Http API calls
|
|
|
+ *
|
|
|
+ * @package Opentalent\OtCore\Http
|
|
|
+ */
|
|
|
+class ApiController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * -- Target of the route 'all' --
|
|
|
+ *
|
|
|
+ * Get all of the Opentalent structures directly
|
|
|
+ * from the Opentalent DB (API Platform is too slow with so many records)
|
|
|
+ *
|
|
|
+ * @param ServerRequest $request
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public function getAllStructures(ServerRequest $request)
|
|
|
+ {
|
|
|
+ if ($_SERVER['HTTP_HOST'] == 'typo3' | $_SERVER['HTTP_HOST'] == 'local.sub.opentalent.fr') {
|
|
|
+ $db_host = 'db';
|
|
|
+ } elseif ($_SERVER['HTTP_HOST'] == 'preprod.opentalent.fr') {
|
|
|
+ $db_host = 'localhost';
|
|
|
+ } else {
|
|
|
+ $db_host = 'prod-back';
|
|
|
+ }
|
|
|
|
|
|
-$cnn = new PDO(
|
|
|
- "mysql:host=" . $db_host . ";dbname=opentalent",
|
|
|
- 'dbcloner',
|
|
|
- 'wWZ4hYcrmHLW2mUK',
|
|
|
- array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')
|
|
|
-);
|
|
|
-$cnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
+ $cnn = new PDO(
|
|
|
+ "mysql:host=" . $db_host . ";dbname=opentalent",
|
|
|
+ 'dbcloner',
|
|
|
+ 'wWZ4hYcrmHLW2mUK',
|
|
|
+ array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')
|
|
|
+ );
|
|
|
+ $cnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
-$stmt = $cnn->prepare(
|
|
|
- "SELECT o.id, o.name, o.logo_id as logoId, o.principalType, p.otherWebsite as website, a.latitude, a.longitude,
|
|
|
+ $stmt = $cnn->prepare(
|
|
|
+ "SELECT o.id, o.name, o.logo_id as logoId, o.principalType, p.otherWebsite as website, a.latitude, a.longitude,
|
|
|
TRIM(BOTH ' ' FROM CONCAT(a.streetAddress, ' ', a.streetAddressSecond, ' ', a.streetAddressThird)) AS streetAddress,
|
|
|
a.postalCode, a.addressCity, c.name AS country,
|
|
|
(SELECT CONCAT('[',GROUP_CONCAT(DISTINCT CONCAT('\"',f.code,'\"')),']')
|
|
|
@@ -43,11 +66,10 @@ $stmt = $cnn->prepare(
|
|
|
LEFT JOIN (SELECT * FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n4 on n4.organization_id = n3.parent_id
|
|
|
LEFT JOIN (SELECT * FROM NetworkOrganization WHERE parent_id NOT IN (32366, 13) AND (endDate IS NULL OR endDate = '0000-00-00')) n5 on n5.organization_id = n4.parent_id
|
|
|
"
|
|
|
-);
|
|
|
-$stmt->execute();
|
|
|
-$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
|
-$data = json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
-
|
|
|
-$response = gzdeflate($data, -1, ZLIB_ENCODING_DEFLATE);
|
|
|
-header('Content-Encoding: deflate');
|
|
|
-echo $response;
|
|
|
+ );
|
|
|
+ $stmt->execute();
|
|
|
+ $stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
|
+ $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
+ return new JsonResponse($data);
|
|
|
+ }
|
|
|
+}
|