Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix client photo path #124

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions shared/homeless/src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function downloadAction(Request $request): Response
}

if (!($object instanceof DownloadableInterface)) {
throw new \InvalidArgumentException('App\Service\DownloadableInterface expected, '.$object::class.' given');
throw new \InvalidArgumentException(DownloadableInterface::class.' expected, '.$object::class.' given');
}

$html = '';
switch ($object::class) {
case Certificate::class:
switch (true) {
case $object instanceof Certificate:
if ($request->get('document')) {
$document = $this->documentRepository->find($request->get('document'));
$object->setDocument($document);
Expand All @@ -81,11 +81,11 @@ public function downloadAction(Request $request): Response
$this->entityManager->flush();
break;

case GeneratedDocument::class:
case $object instanceof GeneratedDocument:
$html = $this->renderService->renderGeneratedDocument($object);
break;

case Contract::class:
case $object instanceof Contract:
$client = $object->getClient();
$this->entityManager->initializeObject($client);
$html = $this->renderService->renderContract($object, $client, $this->getUser());
Expand Down
6 changes: 3 additions & 3 deletions shared/homeless/src/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function getPhotoPathWeb(): string

public function getPhotoPath(): string
{
return __DIR__.'/../../../public/'.$this->getPhotoPathWeb();
return __DIR__.'/../../public/'.$this->getPhotoPathWeb();
}

public function getPhotoSize(int $width, int $height): array
Expand All @@ -226,10 +226,10 @@ public function getPhotoSize(int $width, int $height): array
return [$width, $height];
}

public function getPhotoFileBase64(): ?string
public function getPhotoFileBase64(): string
{
if (!$this->isImage()) {
return null;
return '';
}

return 'data:image/png;base64,'.base64_encode(file_get_contents($this->getPhotoPath()));
Expand Down
8 changes: 2 additions & 6 deletions shared/homeless/src/Service/RenderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ public function renderCertificate(Certificate $certificate, Client $client): ?st
return null;
}

$image = '';
[$width, $height] = [0, 0];
if (file_exists($client->getPhotoPath())) {
$image = $client->getPhotoFileBase64();
[$width, $height] = $client->getPhotoSize(300, 350);
}
$image = $client->getPhotoFileBase64();
[$width, $height] = $client->getPhotoSize(300, 350);

return $this->twig->render('/pdf/certificate/layout.html.twig', [
'contentHeaderLeft' => empty($type->getContentHeaderLeft()) ? '' : $this->twig->createTemplate($type->getContentHeaderLeft())->render(['certificate' => $certificate]),
Expand Down