Skip to content

Commit

Permalink
Merge branch 'main' into api-bsr-berlin
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Feb 12, 2024
2 parents 3e07a46 + 5cebcf4 commit 0a24ea7
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 100 deletions.
16 changes: 16 additions & 0 deletions config/sql/workshops-with-info-sheets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT DISTINCT count(*) AS anzahl_laufzettel,
w.uid,
w.name,
w.zip,
w.city,
w.street,
w.adresszusatz,
concat('https://www.reparatur-initiativen.de/', w.url) AS url
FROM info_sheets i
LEFT JOIN events e ON e.uid = i.event_uid
LEFT JOIN workshops w ON w.uid = e.workshop_uid
WHERE 1
AND i.status = 1
GROUP BY w.uid
ORDER BY anzahl_laufzettel DESC
LIMIT 10000;
1 change: 1 addition & 0 deletions src/Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ public function all()
'30days' => '30 Tage',
'3months' => '3 Monate',
'6months' => '6 Monate',
'gt6months' => '> 6 Monate',
];
$this->set('timeRangeOptions', $timeRangeOptions);

Expand Down
18 changes: 15 additions & 3 deletions src/Model/Table/EventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,28 @@ public function getTimeRangeCondition($timeRange, $negate) {
return function ($exp, $query) use ($timeRange, $negate) {

$now = new \Cake\I18n\DateTime();
$minDate = null;
$maxDate = $now->addDays(30);

if ($timeRange == '3months') {
$maxDate = $now->addDays(90);
$maxDate = $now->addMonths(3);
}
if ($timeRange == '6months') {
$maxDate = $now->addDays(180);
$maxDate = $now->addMonths(6);
}
if ($timeRange == 'gt6months') {
$minDate = $now->addDays(180);
$minDate = $now->addMonths(6);
$maxDate = null;
}

if (!is_null($minDate)) {
$result = $exp->gte('Events.datumstart', $minDate, 'date');
}
if (!is_null($maxDate)) {
$result = $exp->lte('Events.datumstart', $maxDate, 'date');
}

$result = $exp->lte('Events.datumstart', $maxDate, 'date');
if ($negate) {
$result = $exp->not($result);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Table/InfoSheetsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function prepareStatisticsDataGlobal($dateFrom=null, $dateTo=null)
'Events'
]);
$query->where([
'InfoSheets.status >= ' . APP_OFF,
'InfoSheets.status' => APP_ON,
]);

if (!is_null($dateFrom) && !is_null($dateTo)) {
Expand Down Expand Up @@ -234,7 +234,7 @@ public function getWorkshopCountWithInfoSheets($dateFrom, $dateTo)
{
$query = $this->prepareStatisticsDataGlobal($dateFrom, $dateTo);
$query->select(['Events.workshop_uid']);
$query->group('Events.workshop_uid');
$query->groupBy('Events.workshop_uid');
return $query->count();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Table/ThirdPartyStatisticsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getSumsByDate($dateFrom, $dateTo)
['sumRepaired' => $query->func()->sum('ThirdPartyStatistics.repaired')]
);
$query->select('ThirdPartyStatistics.category_id');
$query->group('ThirdPartyStatistics.category_id');
$query->groupBy('ThirdPartyStatistics.category_id');

return $query->toArray();

Expand Down
Loading

0 comments on commit 0a24ea7

Please sign in to comment.