Files
api/services/nginx/app/classes/wash_certificate_store.php
T
Jepp9350 ca52d3b248 Update API endpoints, add wash certificate handling
Replaced legacy 'nnks.truckwash.dk' endpoint with 'api.truckwash.dk' across the codebase for consistency. Implemented a feature to handle certificate downloads, including file serving and validation. Updated PHP configuration to support additional dependencies like PHPMailer, and introduced necessary route and configuration changes for wash certificate processing.
2025-01-31 09:25:18 +01:00

49 lines
1.2 KiB
PHP

<?php
namespace classes;
use interfaces\minio_wash_certificates_i;
use traits\minio_t;
class wash_certificate_store implements minio_wash_certificates_i
{
use minio_t;
public function __construct()
{
self::setBucket('truckwashdev'); // Change this to washcertificates when in production
}
/**
* @inheritDoc
*/
public function washCertificateExists(string $certificate_id): bool
{
// Check if the file exists
$objects = self::getS3Client()->listObjects([
'Bucket' => self::getBucket(),
'Prefix' => 'wash_certificate_' . $certificate_id . '.pdf'
]);
return count($objects['Contents'] ?? []) > 0;
}
public function getWashCertificateDownload(int $id): string
{
return self::getPresignedUrl('wash_certificate_' . $id . '.pdf');
}
/**
* @param string $file
* @return string The path to the downloaded file
*/
public function download(string $file): string
{
$path = '/tmp/' . $file;
$result = self::getS3Client()->getObject([
'Bucket' => self::getBucket(),
'Key' => $file,
'SaveAs' => $path
]);
return $path;
}
}