59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Apps;
|
|
use App\Entity\Organizations;
|
|
use App\Service\AwsService;
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
|
|
|
class OrganizationsService
|
|
{
|
|
private string $logoDirectory;
|
|
|
|
public function __construct(
|
|
string $logoDirectory, private readonly AwsService $awsService
|
|
)
|
|
{
|
|
$this->logoDirectory = $logoDirectory;
|
|
}
|
|
|
|
public function handleLogo(Organizations $organization, $logoFile): void
|
|
{
|
|
$extension = $logoFile->guessExtension();
|
|
|
|
$customFilename = $organization->getName() . '_' . date('dmyHis') . "." . $extension;
|
|
|
|
try {
|
|
$this->awsService->PutDocObj($_ENV['S3_PORTAL_BUCKET'], $logoFile, $customFilename, $extension, 'logo/');
|
|
$organization->setLogoUrl('logo/' . $customFilename);
|
|
} catch (FileException $e) {
|
|
throw new FileException('Failed to upload logo to S3: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Merge all apps with org apps and add a "hasAccess" flag.
|
|
*
|
|
* @param array $appsAll
|
|
* @param array $apps
|
|
* @return array
|
|
*/
|
|
public function appsAccess(array $appsAll, array $apps): array
|
|
{
|
|
// Build a quick lookup of app IDs the org has access to
|
|
$orgAppIds = array_map(static fn(Apps $app) => $app->getId(), $apps);
|
|
|
|
$result = [];
|
|
foreach ($appsAll as $app) {
|
|
$result[] = [
|
|
'entity' => $app, // Keep the full entity for Twig
|
|
'hasAccess' => in_array($app->getId(), $orgAppIds, true),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|