diff --git a/include/memberlistdownload.php b/include/memberlistdownload.php index d8aaae0..8048330 100644 --- a/include/memberlistdownload.php +++ b/include/memberlistdownload.php @@ -7,7 +7,7 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx; class Memberlistdownload extends Renderer { public function render(): void { - $members = $this->loadMembers(); + $members = $this->getMemberList(); $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $columnHeaders = ['Nachname', 'Vorname', 'Straße', 'Plz', 'Ort', 'Geburtsdatum', 'Telefon', 'Email', @@ -22,45 +22,4 @@ class Memberlistdownload extends Renderer { header('Cache-Control: max-age=0'); $writer->save('php://output'); } - - private function loadMembers(): array { - $query = <<dbConnection, $query); - $entries = []; - while ($row = mysqli_fetch_assoc($result)) { - $entries[] = [ - 'first_name' => $this->decode($row['first_name'], $row['salt']), - 'last_name' => $this->decode($row['last_name'], $row['salt']), - 'street' => $this->decode($row['street'], $row['salt']), - 'zip' => $this->decode($row['zip'], $row['salt']), - 'town' => $this->decode($row['town'], $row['salt']), - 'birthdate' => $this->decode($row['birthdate'], $row['salt']), - 'phone' => $this->decode($row['phone'], $row['salt']), - 'email' => $this->decode($row['email'], $row['salt']), -// 'child_name' => $this->decode($row['child_name'], $row['salt']), -// 'child_street' => $this->decode($row['child_street'], $row['salt']), - 'subscription' => $this->decode($row['subscription'], $row['salt']), - 'bank_name' => $this->decode($row['bank_name'], $row['salt']), - 'iban' => $this->decode($row['iban'], $row['salt']), - 'bic' => $this->decode($row['bic'], $row['salt']), - 'account_member_name' => $this->decode($row['account_member_name'], $row['salt']), - 'status_text' => $row['status_text'], - 'membership_start' => $row['membership_start'], - 'last_payment' => $row['last_payment'], - 'description' => $row['description'], - ]; - } - return $entries; - } } diff --git a/include/members.php b/include/members.php index a6eafad..c8bfda2 100644 --- a/include/members.php +++ b/include/members.php @@ -4,19 +4,12 @@ include 'renderer.php'; class Members extends Renderer { public function __construct(?string $templateName = null) { parent::__construct($templateName); - $result = mysqli_query($this->dbConnection, - 'SELECT c.*, cs.`status_text`, (SELECT ph.`payment_date` FROM `paying_history` ph WHERE ph.`clubmember_id` = c.`id` ORDER BY `payment_date` DESC LIMIT 1) as last_payment ' - . 'FROM `clubmember` c ' - . 'JOIN `clubmember_status` cs ' - . ' ON cs.`id` = c.`membership_status` ' - . 'WHERE cs.`status_text` NOT IN ("Mitgliedschaft abgelehnt", "Mitgliedschaft gekündigt") ' - . 'ORDER BY c.`last_name`, c.`first_name`'); + $members = $this->getMemberList(); $tableBody = ''; - while ($row = mysqli_fetch_assoc($result)) { + foreach ($members as $row) { $tableBody .= '' - . '' . $row['id'] . '' - . '' . $this->decode($row['last_name'], $row['salt']) . ', ' . $this->decode($row['first_name'], $row['salt']) . '' - . '' . $this->decode($row['email'], $row['salt']) . '' + . '' . $row['last_name'] . ', ' . $row['first_name'] . '' + . '' . $row['email'] . '' . '' . $row['last_payment'] . '' . '' . $row['membership_start'] . '' . '' . $row['status_text'] . '' diff --git a/include/renderer.php b/include/renderer.php index 1e4d244..a5f19c8 100644 --- a/include/renderer.php +++ b/include/renderer.php @@ -537,4 +537,52 @@ class Renderer { return $decoded; } + protected function getMemberList(): array { + $query = <<dbConnection, $query); + $entries = []; + while ($row = mysqli_fetch_assoc($result)) { + $entries[] = [ + 'last_name' => $this->decode($row['last_name'], $row['salt']), + 'first_name' => $this->decode($row['first_name'], $row['salt']), + 'street' => $this->decode($row['street'], $row['salt']), + 'zip' => $this->decode($row['zip'], $row['salt']), + 'town' => $this->decode($row['town'], $row['salt']), + 'birthdate' => $this->decode($row['birthdate'], $row['salt']), + 'phone' => $this->decode($row['phone'], $row['salt']), + 'email' => $this->decode($row['email'], $row['salt']), +// 'child_name' => $this->decode($row['child_name'], $row['salt']), +// 'child_street' => $this->decode($row['child_street'], $row['salt']), + 'subscription' => $this->decode($row['subscription'], $row['salt']), + 'bank_name' => $this->decode($row['bank_name'], $row['salt']), + 'iban' => $this->decode($row['iban'], $row['salt']), + 'bic' => $this->decode($row['bic'], $row['salt']), + 'account_member_name' => $this->decode($row['account_member_name'], $row['salt']), + 'status_text' => $row['status_text'], + 'membership_start' => $row['membership_start'], + 'last_payment' => $row['last_payment'], + 'description' => $row['description'], + ]; + } + return $this->sortUserList($entries); + } + + protected function sortUserList($userList): array { + usort($userList, function($a, $b) { + $nameComparison = strcmp($a['last_name'], $b['last_name']); + return ($nameComparison !== 0) ? $nameComparison : strcmp($a['first_name'], $b['first_name']); + }); + return $userList; + } }