mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Filter images
This commit is contained in:
parent
c46ce9bc81
commit
9b383b525b
30
app/Helpers/Document/WithTypeHelpers.php
Normal file
30
app/Helpers/Document/WithTypeHelpers.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Helpers\Document;
|
||||
|
||||
trait WithTypeHelpers
|
||||
{
|
||||
/**
|
||||
* Returns boolean based on checks for image.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isImage(): bool
|
||||
{
|
||||
if (in_array($this->type, ['png', 'svg', 'jpeg', 'jpg', 'tiff', 'gif'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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());
|
||||
|
45
tests/Unit/WithTypeHelpersTest.php
Normal file
45
tests/Unit/WithTypeHelpersTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\Document;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WithTypeHelpersTest extends TestCase
|
||||
{
|
||||
public function testIsImageHelper(): void
|
||||
{
|
||||
$account = Account::factory()->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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user