diff --git a/app/Helpers/Document/WithTypeHelpers.php b/app/Helpers/Document/WithTypeHelpers.php new file mode 100644 index 000000000000..17609f017254 --- /dev/null +++ b/app/Helpers/Document/WithTypeHelpers.php @@ -0,0 +1,30 @@ +type, ['png', 'svg', 'jpeg', 'jpg', 'tiff', 'gif'])) { + return true; + } + + return false; + } +} diff --git a/app/Models/Document.php b/app/Models/Document.php index 70a5d8b8a5ff..20059e724ad2 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -11,6 +11,7 @@ namespace App\Models; +use App\Helpers\Document\WithTypeHelpers; use App\Models\Filterable; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Storage; @@ -19,6 +20,7 @@ class Document extends BaseModel { use SoftDeletes; use Filterable; + use WithTypeHelpers; const DOCUMENT_PREVIEW_SIZE = 300; // pixels diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index fd6335276e53..51be7e78d30b 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -756,6 +756,10 @@ html { $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr);'); foreach ($this->entity->documents as $document) { + if (!$document->isImage()) { + continue; + } + $image = $dom->createElement('img'); $image->setAttribute('src', $document->generateUrl()); diff --git a/tests/Unit/WithTypeHelpersTest.php b/tests/Unit/WithTypeHelpersTest.php new file mode 100644 index 000000000000..563aafed02af --- /dev/null +++ b/tests/Unit/WithTypeHelpersTest.php @@ -0,0 +1,45 @@ +create(); + + $company = Company::factory()->create([ + 'account_id' => $account->id, + ]); + + /** @var Document */ + $document = Document::factory()->create([ + 'company_id' => $company->id, + 'type' => 'jpeg', + ]); + + $this->assertTrue($document->isImage()); + + /** @var Document */ + $document = Document::factory()->create([ + 'company_id' => $company->id, + ]); + + $this->assertFalse($document->isImage()); + } +}