Skip to content

Commit

Permalink
Split participant export between participants and instructors
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Sep 29, 2023
1 parent 2f22ca6 commit 312aa4c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Model\Cashbook\ReadModel\Queries\CampParticipantListQuery;
use Model\DTO\Participant\NonMemberParticipant;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;
use Model\Event\Commands\Camp\ActivateAutocomputedParticipants;
use Model\Event\SkautisCampId;
Expand Down Expand Up @@ -100,8 +101,10 @@ public function handleActivateAutocomputedParticipants(int $aid): void
$this->redirect('this');
}

public function actionExportExcel(int $aid): void
public function actionExportExcel(int $aid, string $exportType): void
{
assert($exportType === ParticipatingPerson::PARTICIPANT);

try {
$participantsDTO = $this->campParticipants();
$spreadsheet = $this->excelService->getCampParticipants($participantsDTO);
Expand Down Expand Up @@ -164,8 +167,10 @@ protected function createComponentParticipantList(): ParticipantList
return $control;
}

public function actionExport(int $aid): void
public function actionExport(int $aid, string $exportType): void
{
assert($exportType === ParticipatingPerson::PARTICIPANT);

try {
$template = $this->exportService->getParticipants($aid, EventType::CAMP);
$this->pdf->render($template, 'seznam-ucastniku.pdf', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __construct(
protected bool $isAllowParticipantDelete,
protected bool $isAllowShowUnits,
protected string $title,
protected string $exportType,
) {
}

Expand Down Expand Up @@ -95,6 +96,7 @@ public function render(): void
'isAllowParticipantUpdate' => $this->isAllowParticipantUpdate,
'isAllowParticipantDelete' => $this->isAllowParticipantDelete,
'isAllowAnyAction' => $this->isAllowParticipantUpdate || $this->isAllowParticipantDelete,
'exportType' => $this->exportType,
]);

$this->template->render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ $showUnits bool - zobrazovat číslo jednotky
<i class="fas fa-arrow-down"></i> Exportovat&hellip;
</button>
<div class="dropdown-menu" aria-labelledby="exportParticipantsButton">
<a class="dropdown-item" href="{plink export $aid}">
<a class="dropdown-item" href="{plink export $aid, $exportType}">
<span class="mr-1"><i class="far fa-file-pdf"></i></span> PDF
</a>
<a class="dropdown-item" href="{plink exportExcel $aid}">
<a class="dropdown-item" href="{plink exportExcel $aid, $exportType}">
<span class="mr-1"><i class="far fa-file-excel"></i></span>
Excel
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Model\Cashbook\ReadModel\Queries\EducationParticipantListQuery;
use Model\DTO\Instructor\Instructor;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;
use Model\ExcelService;
use Model\ExportService;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function renderDefault(int $aid): void
$this->redrawControl('contentSnip');
}

public function actionExportExcel(int $aid): void
public function actionExportExcel(int $aid, string $exportType): void
{
if ($this->event->getStartDate() === null) {
$this->flashMessage('Bez vyplněného počátku akce nelze exportovat seznam účastníků, protože nelze dopočítat věk v době akce.', 'danger');
Expand Down Expand Up @@ -108,6 +109,7 @@ protected function createComponentInstructorList(): ParticipantList
false,
false,
'Seznam instruktorů',
ParticipatingPerson::INSTRUCTOR,
);

$control->onUpdate[] = function (array $updates): void {
Expand Down Expand Up @@ -152,10 +154,10 @@ protected function createComponentParticipantList(): ParticipantList
return $control;
}

public function actionExport(int $aid): void
public function actionExport(int $aid, string $exportType): void
{
try {
$template = $this->exportService->getParticipants($aid, EventType::EDUCATION);
$template = $this->exportService->getParticipants($aid, EventType::EDUCATION, $exportType);
$this->pdf->render($template, 'seznam-ucastniku.pdf', false);
} catch (PermissionException $ex) {
$this->flashMessage('Nemáte oprávnění k záznamu osoby! (' . $ex->getMessage() . ')', 'danger');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Model\Cashbook\ReadModel\Queries\EventParticipantListQuery;
use Model\DTO\Participant\NonMemberParticipant;
use Model\DTO\Participant\Participant;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\UpdateParticipant;
use Model\ExcelService;
use Model\ExportService;
Expand Down Expand Up @@ -89,8 +90,10 @@ public function renderDefault(int $aid): void
$this->redrawControl('contentSnip');
}

public function actionExportExcel(int $aid): void
public function actionExportExcel(int $aid, string $exportType): void
{
assert($exportType === ParticipatingPerson::PARTICIPANT);

try {
$participantsDTO = $this->eventParticipants();
$spreadsheet = $this->excelService->getGeneralParticipants($participantsDTO, $this->event->getStartDate());
Expand Down Expand Up @@ -154,8 +157,10 @@ protected function createComponentParticipantList(): ParticipantList
return $control;
}

public function actionExport(int $aid): void
public function actionExport(int $aid, string $exportType): void
{
assert($exportType === ParticipatingPerson::PARTICIPANT);

try {
$template = $this->exportService->getParticipants($aid, EventType::GENERAL);
$this->pdf->render($template, 'seznam-ucastniku.pdf', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public function create(
bool $isAllowParticipantDelete,
bool $isAllowShowUnits = true,
string $title = 'Seznam účastníků',
string $exportType = ParticipatingPerson::PARTICIPANT,
): ParticipantList;
}
3 changes: 3 additions & 0 deletions app/model/DTO/Participant/ParticipatingPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class ParticipatingPerson
{
use SmartObject;

public const PARTICIPANT = 'participant';
public const INSTRUCTOR = 'instructor';

private Payment $paymentObj;

public function __construct(
Expand Down
8 changes: 6 additions & 2 deletions app/model/Export/ExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Model\Cashbook\ReadModel\Queries\CategoriesSummaryQuery;
use Model\Cashbook\ReadModel\Queries\ChitListQuery;
use Model\Cashbook\ReadModel\Queries\EducationCashbookIdQuery;
use Model\Cashbook\ReadModel\Queries\EducationInstructorListQuery;
use Model\Cashbook\ReadModel\Queries\EducationParticipantListQuery;
use Model\Cashbook\ReadModel\Queries\EventCashbookIdQuery;
use Model\Cashbook\ReadModel\Queries\EventParticipantListQuery;
Expand All @@ -26,6 +27,7 @@
use Model\DTO\Cashbook\Cashbook;
use Model\DTO\Cashbook\CategorySummary;
use Model\DTO\Cashbook\Chit;
use Model\DTO\Participant\ParticipatingPerson;
use Model\DTO\Participant\Statistics;
use Model\Event\Camp;
use Model\Event\Education;
Expand Down Expand Up @@ -71,7 +73,7 @@ public function getNewPage(): string
return '<pagebreak type="NEXT-ODD" resetpagenum="1" pagenumstyle="i" suppress="off" />';
}

public function getParticipants(int $aid, string $type = EventType::GENERAL): string
public function getParticipants(int $aid, string $type = EventType::GENERAL, string $participantType = ParticipatingPerson::PARTICIPANT): string
{
if ($type === EventType::CAMP) {
$templateFile = __DIR__ . '/templates/participantCamp.latte';
Expand All @@ -86,7 +88,9 @@ public function getParticipants(int $aid, string $type = EventType::GENERAL): st
assert($education instanceof Education);
$displayName = $education->getDisplayName();
$unitId = $education->getUnitId();
$list = $this->queryBus->handle(new EducationParticipantListQuery($education->getId()));
$list = $participantType === ParticipatingPerson::INSTRUCTOR
? $this->queryBus->handle(new EducationInstructorListQuery($education->getId()))
: $this->queryBus->handle(new EducationParticipantListQuery($education->getId()));
} else {
$templateFile = __DIR__ . '/templates/participant.latte';
$event = $this->queryBus->handle(new EventQuery(new SkautisEventId($aid)));
Expand Down
4 changes: 2 additions & 2 deletions app/model/Export/templates/participantEducation.latte
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ td {
<tr n:foreach="$list as $p">
<td class="cnt">{$iterator->counter}</td>
<td>{$p->displayName}</td>
<td>{if $p->street != ""}{$p->street}{else}&nbsp;{/if}{if $p->city != ""}, {$p->city}{/if}{if $p->postcode != ""}, {(string)$p->postcode|postCode}{/if}</td>
<td style="text-align: right;">{if $p->birthday !== null}{$p->birthday->format("d.m.Y")}{else}&nbsp;{/if}</td>
<td>{if property_exists($p, "street") && $p->street != ""}{$p->street}{else}&nbsp;{/if}{if property_exists($p, "city") && $p->city != ""}, {$p->city}{/if}{if property_exists($p, "postcode") && $p->postcode != ""}, {(string)$p->postcode|postCode}{/if}</td>
<td style="text-align: right;">{if property_exists($p, "birthday") && $p->birthday !== null}{$p->birthday->format("d.m.Y")}{else}&nbsp;{/if}</td>
<td style="text-align: right;">{$p->payment|price:false} Kč</td>
</tr>
</table>
Expand Down

0 comments on commit 312aa4c

Please sign in to comment.