Skip to content

Commit

Permalink
Merge pull request #124 from nochlezhka/cert-photo
Browse files Browse the repository at this point in the history
Fix client photo path
  • Loading branch information
a-menshchikov authored Nov 14, 2023
2 parents 5368e42 + 3868ce0 commit 8ba7b5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
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

0 comments on commit 8ba7b5e

Please sign in to comment.