Skip to content

Commit 69597f1

Browse files
committed
feat: import export bundle
1 parent 5e841d5 commit 69597f1

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

components/ImportExportBundle/src/bundle/Controller/Admin/JobController.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,18 @@ public function view(Job $job): Response
128128
public function displayLogs(Job $job, RequestStack $requestStack): Response
129129
{
130130
$summary = [];
131-
// foreach ($job->getRecords() as $record) {
132-
// $recordInfos = $record->getRecord();
133-
// if (!isset($summary[$recordInfos['level_name']])) {
134-
// $summary[$recordInfos['level_name']] = 0;
135-
// }
136-
// ++$summary[$recordInfos['level_name']];
137-
// }
138-
139-
$logsQuery = $requestStack->getMainRequest()->get('logs', ['page' => 1, 'type' => 'all']);
140-
$pager = new Pagerfanta(new CollectionAdapter($job->getRecords()));
131+
132+
$logsQuery = $requestStack->getMainRequest()->get('logs', []) + ['page' => 1, 'level' => 'all'];
133+
$records = 'all' !== $logsQuery['level'] ? $job->getRecordsForLevel((int) $logsQuery['level']) : $job->getRecords();
134+
$pager = new Pagerfanta(new CollectionAdapter($records));
141135
$pager->setMaxPerPage(50);
142136
$pager->setCurrentPage($logsQuery['page']);
143137

144138
return $this->render('@ibexadesign/import_export/job/logs.html.twig', [
145139
'job' => $job,
146140
'logs' => $pager,
147141
'summary' => $summary,
142+
'request_query' => $requestStack->getMainRequest()->query->all(),
148143
]);
149144
}
150145

components/ImportExportBundle/src/bundle/Resources/views/themes/admin/import_export/job/logs.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
body_rows,
5151
} %}
5252
{% endembed %}
53-
{{ pagerfanta(logs, 'ibexa', {'routeName': 'import_export.job.view', 'routeParams': {'id': job.id}, 'pageParameter': '[logs][page]'}) }}
53+
{{ pagerfanta(logs, 'ibexa', {'routeName': 'import_export.job.view', 'routeParams': {'id': job.id}|merge(request_query), 'pageParameter': '[logs][page]'}) }}
5454
</section>

components/ImportExportBundle/src/lib/Job/Job.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use DateTimeImmutable;
1010
use Doctrine\Common\Collections\ArrayCollection;
1111
use Doctrine\Common\Collections\Collection;
12+
use Doctrine\Common\Collections\Criteria;
13+
use Doctrine\Common\Collections\Expr\Comparison;
1214
use Doctrine\ORM\Mapping as ORM;
1315

1416
/**
@@ -210,6 +212,14 @@ public function getRecords(): Collection
210212
return $this->records;
211213
}
212214

215+
public function getRecordsForLevel(int $level): Collection
216+
{
217+
$criteria = new Criteria();
218+
$criteria->where(new Comparison('level', '=', $level));
219+
220+
return $this->records->matching($criteria);
221+
}
222+
213223
/**
214224
* @param array<JobRecord> $records
215225
*/

components/ImportExportBundle/src/lib/Job/JobRecord.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class JobRecord
3232
*/
3333
protected array $record;
3434

35+
/**
36+
* @ORM\Column
37+
*/
38+
protected int $level;
39+
3540
/**
3641
* @ORM\ManyToOne(targetEntity=Job::class, inversedBy="records")
3742
* @ORM\JoinColumn(name="job_id", referencedColumnName="id")
@@ -43,6 +48,7 @@ public function __construct(Ulid $id, array $record)
4348
$this->id = $id;
4449
$this->identifier = $id->toRfc4122();
4550
$this->record = $record;
51+
$this->level = $record['level'];
4652
}
4753

4854
public function getId(): Ulid
@@ -90,4 +96,14 @@ public function setJob(Job $job): void
9096
{
9197
$this->job = $job;
9298
}
99+
100+
public function getLevel(): int
101+
{
102+
return $this->level;
103+
}
104+
105+
public function setLevel(int $level): void
106+
{
107+
$this->level = $level;
108+
}
93109
}

0 commit comments

Comments
 (0)