Sorted member lists
This commit is contained in:
@@ -7,7 +7,7 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|||||||
|
|
||||||
class Memberlistdownload extends Renderer {
|
class Memberlistdownload extends Renderer {
|
||||||
public function render(): void {
|
public function render(): void {
|
||||||
$members = $this->loadMembers();
|
$members = $this->getMemberList();
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
$columnHeaders = ['Nachname', 'Vorname', 'Straße', 'Plz', 'Ort', 'Geburtsdatum', 'Telefon', 'Email',
|
$columnHeaders = ['Nachname', 'Vorname', 'Straße', 'Plz', 'Ort', 'Geburtsdatum', 'Telefon', 'Email',
|
||||||
@@ -22,45 +22,4 @@ class Memberlistdownload extends Renderer {
|
|||||||
header('Cache-Control: max-age=0');
|
header('Cache-Control: max-age=0');
|
||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadMembers(): array {
|
|
||||||
$query = <<<queryend
|
|
||||||
SELECT c.first_name, c.last_name , c.street , c.zip , c.town, c.birthdate, c.phone, c.email, c.child_name,
|
|
||||||
c.child_street, c.subscription, c.bank_name, c.iban, c.bic, c.account_member_name, c.membership_status, c.salt, c.membership_start,
|
|
||||||
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,
|
|
||||||
cp.description
|
|
||||||
FROM `clubmember` c
|
|
||||||
JOIN `clubmember_status` cs
|
|
||||||
ON cs.`id` = c.`membership_status`
|
|
||||||
LEFT JOIN `clubmember_position` cp
|
|
||||||
ON cp.id = c.position_id
|
|
||||||
WHERE cs.`status_text` NOT IN ("Mitgliedschaft abgelehnt", "Mitgliedschaft gekündigt")
|
|
||||||
queryend;
|
|
||||||
$result = mysqli_query($this->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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,12 @@ include 'renderer.php';
|
|||||||
class Members extends Renderer {
|
class Members extends Renderer {
|
||||||
public function __construct(?string $templateName = null) {
|
public function __construct(?string $templateName = null) {
|
||||||
parent::__construct($templateName);
|
parent::__construct($templateName);
|
||||||
$result = mysqli_query($this->dbConnection,
|
$members = $this->getMemberList();
|
||||||
'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`');
|
|
||||||
$tableBody = '<tbody>';
|
$tableBody = '<tbody>';
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
foreach ($members as $row) {
|
||||||
$tableBody .= '<tr>'
|
$tableBody .= '<tr>'
|
||||||
. '<td>' . $row['id'] . '</td>'
|
. '<td>' . $row['last_name'] . ', ' . $row['first_name'] . '</td>'
|
||||||
. '<td>' . $this->decode($row['last_name'], $row['salt']) . ', ' . $this->decode($row['first_name'], $row['salt']) . '</td>'
|
. '<td>' . $row['email'] . '</td>'
|
||||||
. '<td>' . $this->decode($row['email'], $row['salt']) . '</td>'
|
|
||||||
. '<td>' . $row['last_payment'] . '</td>'
|
. '<td>' . $row['last_payment'] . '</td>'
|
||||||
. '<td>' . $row['membership_start'] . '</td>'
|
. '<td>' . $row['membership_start'] . '</td>'
|
||||||
. '<td>' . $row['status_text'] . '</td>'
|
. '<td>' . $row['status_text'] . '</td>'
|
||||||
|
|||||||
@@ -537,4 +537,52 @@ class Renderer {
|
|||||||
return $decoded;
|
return $decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getMemberList(): array {
|
||||||
|
$query = <<<queryend
|
||||||
|
SELECT c.first_name, c.last_name , c.street , c.zip , c.town, c.birthdate, c.phone, c.email, c.child_name,
|
||||||
|
c.child_street, c.subscription, c.bank_name, c.iban, c.bic, c.account_member_name, c.membership_status, c.salt, c.membership_start,
|
||||||
|
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,
|
||||||
|
cp.description
|
||||||
|
FROM `clubmember` c
|
||||||
|
JOIN `clubmember_status` cs
|
||||||
|
ON cs.`id` = c.`membership_status`
|
||||||
|
LEFT JOIN `clubmember_position` cp
|
||||||
|
ON cp.id = c.position_id
|
||||||
|
WHERE cs.`status_text` NOT IN ("Mitgliedschaft abgelehnt", "Mitgliedschaft gekündigt")
|
||||||
|
queryend;
|
||||||
|
$result = mysqli_query($this->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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user