Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions backend/app/DomainObjects/QuestionAndAnswerViewDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ class QuestionAndAnswerViewDomainObject extends AbstractDomainObject
private ?string $product_title;
private int $question_id;
private ?int $order_id;
private ?string $order_first_name;
private ?string $order_last_name;
private ?string $order_email;
private ?string $order_public_id;
private string $title;
private bool $question_required;
private ?string $question_description = null;
private ?int $attendee_id = null;
private ?string $attendee_public_id = null;
private ?string $first_name = null;
private ?string $last_name = null;
private ?string $attendee_email = null;
private array|string $answer;
private string $belongs_to;
private ?int $attendee_id = null;
private ?string $attendee_public_id = null;
private string $question_type;
private int $event_id;
private int $question_answer_id;
Expand Down Expand Up @@ -248,6 +253,66 @@ public function setAttendeePublicId(?string $attendee_public_id): QuestionAndAns
return $this;
}

public function getOrderFirstName(): ?string
{
return $this->order_first_name;
}

public function setOrderFirstName(?string $order_first_name): QuestionAndAnswerViewDomainObject
{
$this->order_first_name = $order_first_name;

return $this;
}

public function getOrderLastName(): ?string
{
return $this->order_last_name;
}

public function setOrderLastName(?string $order_last_name): QuestionAndAnswerViewDomainObject
{
$this->order_last_name = $order_last_name;

return $this;
}

public function getOrderEmail(): ?string
{
return $this->order_email;
}

public function setOrderEmail(?string $order_email): QuestionAndAnswerViewDomainObject
{
$this->order_email = $order_email;

return $this;
}

public function getOrderPublicId(): ?string
{
return $this->order_public_id;
}

public function setOrderPublicId(?string $order_public_id): QuestionAndAnswerViewDomainObject
{
$this->order_public_id = $order_public_id;

return $this;
}

public function getAttendeeEmail(): ?string
{
return $this->attendee_email;
}

public function setAttendeeEmail(?string $attendee_email): QuestionAndAnswerViewDomainObject
{
$this->attendee_email = $attendee_email;

return $this;
}

public function toArray(): array
{
return [
Expand All @@ -268,6 +333,11 @@ public function toArray(): array
'product_title' => $this->product_title ?? null,
'question_answer_id' => $this->question_answer_id ?? null,
'question_options' => $this->question_options ?? null,
'attendee_email' => $this->attendee_email ?? null,
'order_first_name' => $this->order_first_name ?? null,
'order_last_name' => $this->order_last_name ?? null,
'order_email' => $this->order_email ?? null,
'order_public_id' => $this->order_public_id ?? null,
];
}
}
130 changes: 130 additions & 0 deletions backend/app/Exports/AnswerExportSheets/AttendeeAnswersSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace HiEvents\Exports\AnswerExportSheets;

use HiEvents\DomainObjects\Enums\QuestionTypeEnum;
use HiEvents\DomainObjects\QuestionAndAnswerViewDomainObject;
use HiEvents\Helper\Url;
use HiEvents\Services\Domain\Question\QuestionAnswerFormatter;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class AttendeeAnswersSheet implements
FromCollection,
WithHeadings,
WithMapping,
WithStyles,
WithTitle,
WithColumnWidths,
ShouldAutoSize
{
public function __construct(
private readonly Collection $answers,
private readonly QuestionAnswerFormatter $questionAnswerFormatter,
)
{
}

public function collection(): Collection
{
return $this->answers;
}

public function headings(): array
{
return [
__('Question'),
__('Answer'),
__('Order ID'),
__('Order Email'),
__('Attendee Name'),
__('Attendee Email'),
__('Product'),
__('Order URL'),
];
}

/**
* @param QuestionAndAnswerViewDomainObject $row
*/
public function map($row): array
{
$orderUrl = sprintf(
Url::getFrontEndUrlFromConfig(Url::ORGANIZER_ORDER_SUMMARY),
$row->getEventId(),
$row->getOrderId(),
);

$linkText = __('View Order');
$hyperlink = '=HYPERLINK("' . $orderUrl . '","' . $linkText . '")';

return [
$row->getTitle(),
$this->questionAnswerFormatter->getAnswerAsText(
$row->getAnswer(),
QuestionTypeEnum::fromName($row->getQuestionType())
),
$row->getOrderPublicId() ?? '',
$row->getOrderEmail() ?? '',
trim($row->getFirstName() . ' ' . $row->getLastName()),
$row->getAttendeeEmail() ?? '',
$row->getProductTitle() ?? '',
$hyperlink,
];
}

public function styles(Worksheet $sheet): array
{
$sheet->getStyle('A1:H1')->applyFromArray([
'font' => ['bold' => true],
]);

$highestRow = $sheet->getHighestRow();

if ($highestRow > 1) {
$sheet->getStyle('H2:H' . $highestRow)->applyFromArray([
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
],
'font' => [
'bold' => true,
'color' => ['rgb' => '0563C1'],
],
]);
}

return [
1 => ['font' => ['bold' => true]],
];
}

public function columnWidths(): array
{
return [
'A' => 30, // Question
'B' => 40, // Answer
'C' => 15, // Order ID
'D' => 25, // Order Email
'E' => 25, // Attendee Name
'F' => 25, // Attendee Email
'G' => 25, // Product
'H' => 15, // Order URL
];
}

/**
* @return string
*/
public function title(): string
{
return __('Attendee Answers');
}
}
122 changes: 122 additions & 0 deletions backend/app/Exports/AnswerExportSheets/OrderAnswersSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace HiEvents\Exports\AnswerExportSheets;

use HiEvents\DomainObjects\Enums\QuestionTypeEnum;
use HiEvents\DomainObjects\QuestionAndAnswerViewDomainObject;
use HiEvents\Helper\Url;
use HiEvents\Services\Domain\Question\QuestionAnswerFormatter;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class OrderAnswersSheet implements
FromCollection,
WithHeadings,
WithMapping,
WithStyles,
WithTitle,
WithColumnWidths,
ShouldAutoSize
{
public function __construct(
private readonly Collection $answers,
private readonly QuestionAnswerFormatter $questionAnswerFormatter,
)
{
}

public function collection(): Collection
{
return $this->answers;
}

public function headings(): array
{
return [
__('Question'),
__('Answer'),
__('Order ID'),
__('Order Name'),
__('Order Email'),
__('Order URL'),
];
}

/**
* @param QuestionAndAnswerViewDomainObject $row
*/
public function map($row): array
{
$orderUrl = sprintf(
Url::getFrontEndUrlFromConfig(Url::ORGANIZER_ORDER_SUMMARY),
$row->getEventId(),
$row->getOrderId(),
);

$linkText = __('View Order');
$hyperlink = '=HYPERLINK("' . $orderUrl . '","' . $linkText . '")';

return [
$row->getTitle(),
$this->questionAnswerFormatter->getAnswerAsText(
$row->getAnswer(),
QuestionTypeEnum::fromName($row->getQuestionType())
),
$row->getOrderPublicId() ?? '',
trim($row->getOrderFirstName() . ' ' . $row->getOrderLastName()),
$row->getOrderEmail() ?? '',
$hyperlink,
];
}

public function styles(Worksheet $sheet): array
{
$sheet->getStyle('A1:F1')->applyFromArray([
'font' => ['bold' => true],
]);

$highestRow = $sheet->getHighestRow();

// Style the URL column cells but exclude the header row
if ($highestRow > 1) {
$sheet->getStyle('F2:F' . $highestRow)->applyFromArray([
'alignment' => [
'horizontal' => Alignment::HORIZONTAL_CENTER,
],
'font' => [
'bold' => true,
'color' => ['rgb' => '0563C1'],
],
]);
}

return [
1 => ['font' => ['bold' => true]],
];
}

public function columnWidths(): array
{
return [
'A' => 30, // Question
'B' => 40, // Answer
'C' => 15, // Order ID
'D' => 25, // Order Name
'E' => 25, // Order Email
'F' => 15, // Order URL
];
}

public function title(): string
{
return __('Order Answers');
}
}
Loading
Loading