Skip to content

Commit debe1d5

Browse files
committed
Add method for getting advisories and update advisory_count template
1 parent cbf3324 commit debe1d5

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

src/Entity/Site.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,25 @@ public function setType(string $type): self
200200
return $this;
201201
}
202202

203-
public function getAdvisoryCount(): int
203+
/**
204+
* @return Collection<int, Advisory>
205+
*/
206+
public function getAdvisories(): Collection
204207
{
205208
$advisories = new ArrayCollection();
206209
foreach ($this->installation->getPackageVersions() as $packageVersion) {
207210
foreach ($packageVersion->getAdvisories() as $advisory) {
208-
$advisories->add($advisory);
211+
if (!$advisories->contains($advisory)) {
212+
$advisories->add($advisory);
213+
}
209214
}
210215
}
211216

212-
return $advisories->count();
217+
return $advisories;
218+
}
219+
220+
public function getAdvisoryCount(): int
221+
{
222+
return $this->getAdvisories()->count();
213223
}
214224
}
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
22
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
33
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
4-
{% if field.formattedValue != 0 %}
4+
{% if ea().crud.currentAction == 'detail' %}
5+
{% set advisories = entity.instance.advisories %}
6+
{% if advisories|length > 0 %}
7+
<table class="table table-sm table-borderless">
8+
<thead>
9+
<tr>
10+
<th>Package</th>
11+
<th>CVE</th>
12+
<th>Title</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
{% for advisory in advisories %}
17+
{% set url = ea_url()
18+
.unsetAll()
19+
.setController('App\\Controller\\Admin\\AdvisoryCrudController')
20+
.setAction('detail')
21+
.setEntityId(advisory.id) %}
22+
<tr>
23+
<td>{{ advisory.package }}</td>
24+
<td><a href="{{ url }}">{{ advisory.cve ?? advisory.advisoryId }}</a></td>
25+
<td>{{ advisory.title }}</td>
26+
</tr>
27+
{% endfor %}
28+
</tbody>
29+
</table>
30+
{% endif %}
31+
{% elseif field.formattedValue != 0 %}
532
<span class="badge badge-danger">{{ field.formattedValue }}</span>
633
{% endif %}

0 commit comments

Comments
 (0)