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

View File

@ -26,22 +26,32 @@
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col"></th> <th scope="col"></th>
<?php foreach ($widget['table_headers'] as $header) { ?> <?php foreach ($widget['records'] as $record) { ?>
<th scope="col"><?= htmlspecialchars($header) ?></th> <th scope="col"><?= htmlspecialchars($record['table_headers']) ?></th>
<?php } ?> <?php } ?>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>conferences</td> <td>conferences</td>
<?php foreach ($widget['table_records_conferences'] as $row) { ?> <?php foreach ($widget['records'] as $record) {
<td><?= htmlspecialchars($row ?? '') ?></td> 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 } ?> <?php } ?>
</tr> </tr>
<tr> <tr>
<td>participants</td> <td>participants</td>
<?php foreach ($widget['table_records_participants'] as $row) { ?> <?php foreach ($widget['records'] as $record) {
<td><?= htmlspecialchars($row ?? '') ?></td> // $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 } ?> <?php } ?>
</tr> </tr>
</tbody> </tbody>