This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from Dino-Kupinic/develop
upload and parsing of xlsx file
- Loading branch information
Showing
25 changed files
with
9,826 additions
and
6,709 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# config/packages/lexik_jwt_authentication.yaml | ||
lexik_jwt_authentication: | ||
secret_key: '%env(resolve:JWT_SECRET_KEY)%' # required for token creation | ||
public_key: '%env(resolve:JWT_PUBLIC_KEY)%' # required for token verification | ||
pass_phrase: '%env(JWT_PASSPHRASE)%' # required for token creation | ||
token_ttl: 3600 # in seconds, default is 3600 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
nelmio_cors: | ||
defaults: | ||
origin_regex: true | ||
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%'] | ||
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE'] | ||
allow_headers: ['Content-Type', 'Authorization'] | ||
expose_headers: ['Link'] | ||
max_age: 3600 | ||
paths: | ||
'^/': null |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,4 @@ | |
'@hotwired/turbo' => [ | ||
'version' => '7.3.0', | ||
], | ||
'eslint-config-prettier' => [ | ||
'version' => '9.1.0', | ||
], | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Service\ImportService; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route("api/v1")] | ||
class ImportController extends AbstractController | ||
{ | ||
#[Route("/importXLSX", name: "app_import", methods: "POST")] | ||
public function index(ImportService $importService, Request $request): Response | ||
{ | ||
$uploadedFile = $request->files->get("file"); | ||
|
||
if (!$uploadedFile) { | ||
return new Response("No file provided", Response::HTTP_BAD_REQUEST); | ||
} | ||
|
||
$filePath = $uploadedFile->getPathname(); | ||
$data = $importService->parseFile($filePath); | ||
|
||
$header = $data[0]; | ||
if ($importService->isHeaderValid($header)) { | ||
unset($data[0]); | ||
$importService->persist($data); | ||
return new Response("Success", Response::HTTP_OK); | ||
} | ||
|
||
return new Response( | ||
"XLSX Header is invalid, did you provide the correct file?", | ||
Response::HTTP_BAD_REQUEST | ||
); | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use PHPUnit\Util\Exception; | ||
|
||
class AuthService | ||
{ | ||
public function authenticateUser($user, $password): bool | ||
{ | ||
$success = null; | ||
try { | ||
$ds = ldap_connect($_ENV["LDAP_URL"]) or throw new Exception("Could not connect to LDAP server."); | ||
if ($ds) { | ||
/** | ||
* LDAP-Request for school | ||
* | ||
* $r = ldap_bind($ds) or throw new Exception("Error trying to bind: " . ldap_error($ds)); | ||
* $sr = ldap_search($ds, $_ENV["SCHULE_BASE"], "cn=$user", array("dn")) or throw new LdapException ("Error in search query: " . ldap_error($ds)); | ||
* $res = ldap_get_entries($ds, $sr); | ||
* $userDN = $res[0]['dn']; | ||
*/ | ||
public function authenticateUser($user, $password): bool | ||
{ | ||
$success = null; | ||
try { | ||
$ds = ldap_connect($_ENV["LDAP_URL"]) or throw new Exception("Could not connect to LDAP server."); | ||
if ($ds) { | ||
/** | ||
* LDAP-Request for school | ||
* | ||
* $r = ldap_bind($ds) or throw new Exception("Error trying to bind: " . ldap_error($ds)); | ||
* $sr = ldap_search($ds, $_ENV["SCHULE_BASE"], "cn=$user", array("dn")) or throw new LdapException ("Error in search query: " . ldap_error($ds)); | ||
* $res = ldap_get_entries($ds, $sr); | ||
* $userDN = $res[0]['dn']; | ||
*/ | ||
|
||
/** | ||
* LDAP-Request for Test-Environment | ||
*/ | ||
$userDN = "cn=$user,ou=TestUsers," . $_ENV["LDAP_BASE"]; | ||
/** | ||
* LDAP-Request for Test-Environment | ||
*/ | ||
$userDN = "cn=$user,ou=TestUsers," . $_ENV["LDAP_BASE"]; | ||
|
||
$success = @ldap_bind($ds, $userDN, $password) or throw new Exception("Error trying to bind: " . ldap_error($ds)); | ||
$success = @ldap_bind($ds, $userDN, $password) or throw new Exception("Error trying to bind: " . ldap_error($ds)); | ||
|
||
ldap_close($ds); | ||
} | ||
} catch (Exception $e) { | ||
$success = false; | ||
} | ||
return $success; | ||
ldap_close($ds); | ||
} | ||
} catch (Exception $e) { | ||
$success = false; | ||
} | ||
return $success; | ||
} | ||
} | ||
|
||
?> | ||
?> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
|
||
class ImportService | ||
{ | ||
/** | ||
* @param string $filePath | ||
* @return array array containing the xlsx data (2D array for the rows and columns) | ||
*/ | ||
public function parseFile(string $filePath): array | ||
{ | ||
$spreadsheet = IOFactory::load($filePath); | ||
$worksheet = $spreadsheet->getActiveSheet(); | ||
|
||
$data = []; | ||
foreach ($worksheet->getRowIterator() as $row) { | ||
$rowData = []; | ||
foreach ($row->getCellIterator() as $cell) { | ||
$rowData[] = $cell->getValue(); | ||
} | ||
$data[] = $rowData; | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* checks partially if the header is correct | ||
* @param array $header first entry returned from `ImportService->parseFile()` | ||
* @return bool | ||
*/ | ||
public function isHeaderValid(array $header): bool | ||
{ | ||
// this header is partial because some fields are "dynamic", though this check should be deterministic enough. | ||
$correctHeader = ["BNR", "Kurztitel", "Titel", "Listtyp", "Schulform", "Gegenstand", "Jahrgang", "Lehrerexemplar", "Anmerkung", "VNR", "Verlag", "Hauptbuch"]; | ||
$intersect = array_intersect($correctHeader, $header); | ||
return count($intersect) === count($correctHeader); | ||
} | ||
|
||
public function persist(array $data) | ||
{ | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.