monthly stats widget fixes

main
Yasen Pramatarov 2024-08-08 11:49:10 +03:00
parent 3943ba49b6
commit 0f868f07e2
2 changed files with 54 additions and 22 deletions

View File

@ -30,34 +30,56 @@ $thisMonth = new DateTime();
$from_time = $fromMonth->format('Y-m-d');
$until_time = $thisMonth->format('Y-m-d');
$widget['table_headers'] = array();
$widget['table_records_conferences'] = array();
$widget['table_records_participants'] = array();
$widget['records'] = array();
//$widget['table_headers'] = array();
//$widget['table_records_conferences'] = array();
//$widget['table_records_participants'] = array();
// loop 1 year in the past
$i = 0;
while ($fromMonth < $thisMonth) {
$untilMonth = clone $fromMonth;
$untilMonth->modify('last day of this month');
$searchConferenceNumber = $conference->conferenceNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
$searchParticipantNumber = $participant->participantNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
$from_time = $fromMonth->format('Y-m-d');
$until_time = $untilMonth->format('Y-m-d');
// $searchConferenceNumber = $conference->conferenceNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
// $searchParticipantNumber = $participant->participantNumber($fromMonth->format('Y-m-d'), $untilMonth->format('Y-m-d'));
$searchConferenceNumber = $conference->conferenceNumber($from_time, $until_time);
$searchParticipantNumber = $participant->participantNumber($from_time, $until_time);
// pretty format for displaying the month in the widget
$month = $fromMonth->format('F Y');
$widget['records'][$i] = array(
// 'fromMonth' => $fromMonth,
// 'untilMonth' => $untilMonth,
'from_time' => $from_time,
'until_time' => $until_time,
'table_headers' => $month,
'conferences' => $searchConferenceNumber[0]['conferences'],
'participants' => $searchParticipantNumber[0]['participants'],
);
// $widget['records'][$i]['fromMonth'] = $fromMonth;
// $widget['records'][$i]['untilMonth'] = $untilMonth;
// populate the table
array_push($widget['table_headers'], $month);
if (isset($searchConferenceNumber[0]['conferences'])) {
array_push($widget['table_records_conferences'], $searchConferenceNumber[0]['conferences']);
} else {
array_push($widget['table_records_conferences'], '0');
}
if (isset($searchParticipantNumber[0]['participants'])) {
array_push($widget['table_records_participants'], $searchParticipantNumber[0]['participants']);
} else {
array_push($widget['table_records_participants'], '0');
}
// array_push($widget['records'][$i]['table_headers'], $month);
// if (isset($searchConferenceNumber[0]['conferences'])) {
// array_push($widget['records'][$i]['table_records_conferences'], $searchConferenceNumber[0]['conferences']);
// } else {
// array_push($widget['records'][$i]['table_records_conferences'], '0');
// }
// if (isset($searchParticipantNumber[0]['participants'])) {
// array_push($widget['records'][$i]['table_records_participants'], $searchParticipantNumber[0]['participants']);
// } else {
// array_push($widget['records'][$i]['table_records_participants'], '0');
// }
$i++;
// move everything one month in future
$untilMonth->add(new DateInterval('P1M'));

View File

@ -26,22 +26,32 @@
<thead class="thead-dark">
<tr>
<th scope="col"></th>
<?php foreach ($widget['table_headers'] as $header) { ?>
<th scope="col"><?= htmlspecialchars($header) ?></th>
<?php foreach ($widget['records'] as $record) { ?>
<th scope="col"><?= htmlspecialchars($record['table_headers']) ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<td>conferences</td>
<?php foreach ($widget['table_records_conferences'] as $row) { ?>
<td><?= htmlspecialchars($row ?? '') ?></td>
<?php foreach ($widget['records'] as $record) {
print_r($record);
// $from_time = $record['fromMonth']->format('Y-m-d');
// $until_time = $record['untilMonth']->format('Y-m-d');
?>
<td><?php if (!empty($record['conferences'])) { ?>
<a href="?page=conferences&from_time=<?= $record['from_time'] ?>&until_time=<?= $record['until_time'] ?>"><?= htmlspecialchars($record['conferences']) ?></a> <?php } else { ?>
0<?php } ?>
</td>
<?php } ?>
</tr>
<tr>
<td>participants</td>
<?php foreach ($widget['table_records_participants'] as $row) { ?>
<td><?= htmlspecialchars($row ?? '') ?></td>
<?php foreach ($widget['records'] as $record) {
// $from_time = $record['fromMonth']->format('Y-m-d');
// $until_time = $record['untilMonth']->format('Y-m-d');
?>
<td><?= !empty($record['participants']) ? '<a href="?page=participants&from_time=$from_time&until_time=$until_time">' . htmlspecialchars($record['participants']) . '</a>' : '0'; ?></td>
<?php } ?>
</tr>
</tbody>