From d5c88f51e2821358fb50a2a2293333b3088f8faa Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Mon, 28 Aug 2023 12:19:16 +0100 Subject: [PATCH 1/5] Retire /search page. --- app/Http/Controllers/SearchController.php | 102 ----- lang/de/general.php | 1 - lang/en/general.php | 1 - lang/fr-BE/general.php | 1 - lang/fr/general.php | 1 - lang/it/general.php | 1 - lang/ne/general.php | 1 - lang/nl-BE/general.php | 1 - lang/no/general.php | 1 - resources/views/layouts/navbar.blade.php | 7 - resources/views/search/index.blade.php | 446 ---------------------- routes/web.php | 4 - tests/Feature/Stats/EventStatsTest.php | 10 - 13 files changed, 577 deletions(-) delete mode 100644 app/Http/Controllers/SearchController.php delete mode 100644 resources/views/search/index.blade.php diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php deleted file mode 100644 index 3569ffa657..0000000000 --- a/app/Http/Controllers/SearchController.php +++ /dev/null @@ -1,102 +0,0 @@ -has('fltr') && ! empty($request->input('fltr'))) { - // validate filters - - $filters = SearchHelper::getSearchFilters($request); - if (! empty($filters['response'])) { - // validation error - return error message - - $params['response'] = $filters['response']; - } else { - // execute the search - - $Search = new Search; - $PartyList = $Search->parties( - $filters['searched_parties'], - $filters['searched_groups'], - $filters['from_date'], - $filters['to_date'], - $filters['group_tags'], - $dropdowns['allowed_parties'] - ); - - // Send these to getEventStats() to speed things up a bit. - $eEmissionRatio = \App\Helpers\LcaStats::getEmissionRatioPowered(); - $uEmissionratio = \App\Helpers\LcaStats::getEmissionRatioUnpowered(); - - if (count($PartyList) > 0) { - $partyIds = []; - - /// waste stats - $stats = Party::getEventStatsArrayKeys(); - foreach ($PartyList as $party) { - $partyIds[] = $party->idevents; - - $eventStats = $party->getEventStats($eEmissionRatio, $uEmissionratio); - foreach (array_keys($stats) as $v) { - $party->{$v} = $eventStats[$v]; - $stats[$v] += $eventStats[$v]; - } - } - - // cluster dataviz - $clusters = []; - for ($i = 1; $i <= 4; $i++) { - $cluster = $Search->countByCluster($partyIds, $i); - $total = 0; - foreach ($cluster as $state) { - $total += $state->counter; - } - $cluster['total'] = $total; - $clusters['all'][$i] = $cluster; - } - - // most/least stats for clusters - $mostleast = []; - for ($i = 1; $i <= 4; $i++) { - $mostleast[$i]['most_seen'] = $Search->findMostSeen($partyIds, null, $i); - $mostleast[$i]['most_repaired'] = $Search->findMostSeen($partyIds, 1, $i); - $mostleast[$i]['least_repaired'] = $Search->findMostSeen($partyIds, 3, $i); - } - - $params['PartyList'] = $PartyList; - $params['mostleast'] = $mostleast; - $params['clusters'] = $clusters; - $params['category_clusters'] = \App\Helpers\Fixometer::categoryCluster(); - $params['stats'] = $stats; - $params['device_count_status'] = $Search->deviceStatusCount($partyIds); - $params['top'] = $Search->findMostSeen($partyIds, 1, null); - } else { - // return no-results message - - // Don't log to Sentry - legitimate user error. - $params['response'] = ['warning' => 'No results for these filters']; - } - } - } - // finally, return the view - return view('search.index', $params); - } -} diff --git a/lang/de/general.php b/lang/de/general.php index 76a4edfa2b..59cfe48ac2 100644 --- a/lang/de/general.php +++ b/lang/de/general.php @@ -11,7 +11,6 @@ 'alert_uptodate_text' => 'You have nothing to action now. When you do, we\'ll let you know.', 'general' => 'General', 'reporting' => 'Reporting', - 'party_reporting' => 'Event reporting', 'signmeup' => 'Sign me up!', 'introduction_message' => 'We are a global community of people who help others fix their electronics in community events. Join us!', 'your_name' => 'Your name', diff --git a/lang/en/general.php b/lang/en/general.php index ea7a365ebc..94c810ce2d 100644 --- a/lang/en/general.php +++ b/lang/en/general.php @@ -18,7 +18,6 @@ 'new_group' => 'Create a new group', 'alert_uptodate' => 'Thanks! You are up to date', 'alert_uptodate_text' => 'You have nothing to action now. When you do, we\'ll let you know.', - 'party_reporting' => 'Event reporting', 'signmeup' => 'Sign me up!', 'introduction_message' => 'We are a global community of people who help others fix their electronics in community events. Join us!', 'your_name' => 'Your name', diff --git a/lang/fr-BE/general.php b/lang/fr-BE/general.php index 03b00d5e0d..e9c053f276 100644 --- a/lang/fr-BE/general.php +++ b/lang/fr-BE/general.php @@ -11,7 +11,6 @@ 'alert_uptodate_text' => 'Vous n\'avez rien à faire. Quand vous devrez, nous vous préviendrons.', 'general' => 'Général', 'reporting' => 'Rapports', - 'party_reporting' => 'Rapports d’événements', 'signmeup' => 'Enregistrez‐moi!', 'introduction_message' => 'Nous sommes une communauté de bénévoles à travers le monde qui aident les gens à réparer leurs appareils électroniques lors d\'événements communautaires. Rejoignez‐nous !', 'your_name' => 'Prénom & Nom', diff --git a/lang/fr/general.php b/lang/fr/general.php index 03b00d5e0d..e9c053f276 100644 --- a/lang/fr/general.php +++ b/lang/fr/general.php @@ -11,7 +11,6 @@ 'alert_uptodate_text' => 'Vous n\'avez rien à faire. Quand vous devrez, nous vous préviendrons.', 'general' => 'Général', 'reporting' => 'Rapports', - 'party_reporting' => 'Rapports d’événements', 'signmeup' => 'Enregistrez‐moi!', 'introduction_message' => 'Nous sommes une communauté de bénévoles à travers le monde qui aident les gens à réparer leurs appareils électroniques lors d\'événements communautaires. Rejoignez‐nous !', 'your_name' => 'Prénom & Nom', diff --git a/lang/it/general.php b/lang/it/general.php index f96a616ee4..f4fc8d3e95 100644 --- a/lang/it/general.php +++ b/lang/it/general.php @@ -11,7 +11,6 @@ 'alert_uptodate_text' => 'Non hai nessuna azione da fare ora. Quando sara\' necessaria ti faremo sapere.', 'general' => 'Generale', 'reporting' => 'Reporting', - 'party_reporting' => 'Segnalazione eventi', 'signmeup' => 'Fammi entrare!', 'introduction_message' => 'Siamo una comunità globale di persone che aiutano gli altri a riparare i propri dispositivi elettronici in eventi comunitari. Unisciti a noi!', 'your_name' => 'Tuo nome', diff --git a/lang/ne/general.php b/lang/ne/general.php index 23bf9be8c5..c51d0fe0ad 100644 --- a/lang/ne/general.php +++ b/lang/ne/general.php @@ -22,7 +22,6 @@ 'menu_wiki' => 'Wiki', 'new_group' => 'Een nieuwe groep maken', 'other_profile' => 'profiel', - 'party_reporting' => 'Activiteitenverslagen', 'please_select' => 'Selecteer iets aub', 'profile' => 'Jouw profiel', 'profile_content' => 'Geef aub wat info over jezelf. Zo kun je makkelijker in contact komen met andere organisatoren en herstellers. En het helpt ons om de gemeenschap beter te begrijpen.', diff --git a/lang/nl-BE/general.php b/lang/nl-BE/general.php index 8ed1da8c61..dc24f16abe 100644 --- a/lang/nl-BE/general.php +++ b/lang/nl-BE/general.php @@ -22,7 +22,6 @@ 'menu_wiki' => 'Wiki', 'new_group' => 'Een nieuwe groep maken', 'other_profile' => 'profiel', - 'party_reporting' => 'Activiteitenverslagen', 'please_select' => 'Selecteer iets aub', 'profile' => 'Jouw profiel', 'profile_content' => 'Schrijf hier wat info over jezelf. Zo leg je makkelijker contact met andere organisatoren en herstellers. Je info geeft ons ook meer inzicht in de Repair Community.', diff --git a/lang/no/general.php b/lang/no/general.php index 546dc92616..12d6614a2e 100644 --- a/lang/no/general.php +++ b/lang/no/general.php @@ -11,7 +11,6 @@ 'alert_uptodate_text' => 'You have nothing to action now. When you do, we\'ll let you know.', 'general' => 'General', 'reporting' => 'Reporting', - 'party_reporting' => 'Event reporting', 'signmeup' => 'Sign me up!', 'introduction_message' => 'We are a global community of people who help others fix their electronics in community events. Join us!', 'your_name' => 'Your name', diff --git a/resources/views/layouts/navbar.blade.php b/resources/views/layouts/navbar.blade.php index bf25a160d3..c040deabc1 100644 --- a/resources/views/layouts/navbar.blade.php +++ b/resources/views/layouts/navbar.blade.php @@ -140,13 +140,6 @@ @endcan - @if ( App\Helpers\Fixometer::hasRole(Auth::user(), 'Administrator') || App\Helpers\Fixometer::hasRole(Auth::user(), 'Host') ) -
  • @lang('general.reporting') - -
  • - @endif
  • @if ( App\Helpers\Fixometer::hasRole(Auth::user(), 'Administrator') || App\Helpers\Fixometer::hasRole(Auth::user(), 'Host') ) @lang('general.general') diff --git a/resources/views/search/index.blade.php b/resources/views/search/index.blade.php deleted file mode 100644 index 5e2a825b3b..0000000000 --- a/resources/views/search/index.blade.php +++ /dev/null @@ -1,446 +0,0 @@ -@extends('layouts.app') - -@section('content') - -
    -
    - - @if (\Session::has('success')) -
    - {!! \Session::get('success') !!} -
    - @endif - @if (\Session::has('warning')) -
    - {!! \Session::get('warning') !!} -
    - @endif - -
    -
    -
    -

    - @lang('events.reporting') -

    - - @if(isset($PartyList)) - - - @lang('events.download-results') - - @endif - -
    -
    -
    - -
    - -
    - -
    - - @csrf - - - -
    - - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - - > -
    - -
    - - > -
    - - @if (App\Helpers\Fixometer::hasRole($user, 'Administrator')) -
    - -
    - -
    -
    - @endif - - - -
    -
    - -
    - -
    - - @if(isset($PartyList)) - -

    Key stats

    -
      -
    • -
      -

      Participants

      - {{{ number_format($stats['participants'], 0, '.' , ',') }}} - -
      -
    • -
    • -
      -

      Hours volunteered

      - {{{ number_format($stats['hours_volunteered'], 0, '.' , ',') }}} - -
      -
    • -
    • -
      -

      Total events

      - {{{ number_format(count($PartyList), 0, '.' , ',') }}} - -
      -
    • -
    • -
      -

      Waste prevented

      - {{{ number_format(round($stats['waste_total']), 0, '.' , ',') }}} kg - -
      -
    • -
    • -
      -

      CO2 emissions prevented

      - {{{ number_format(round($stats['co2_total']), 0, '.' , ',') }}} kg - -
      -
    • -
    - -

    Filtered event results

    - - - - - - -
    - -

    Environmental impact

    - -
    -
    -
      -
    • -
      -

      Waste prevented

      - {{{ number_format(round($stats['waste_total']), 0, '.' , ',') }}} kg - -
      -
    • -
    • -
      -

      CO2 emissions prevented

      - {{{ number_format(round($stats['co2_total']), 0, '.' , ',') }}} kg - -
      -
    • -
    -
    - - 6000) { - $consume_svg = 'svg-car1'; - $consume_label = 'Equal to driving'; - $consume_eql_to = (1 / 0.12) * $stats['co2_total']; - $consume_legend = number_format(round($consume_eql_to), 0, '.', ',') . ' km'; - - $manufacture_svg = 'svg-car2'; - $manufacture_label = 'Like manufacturing'; - $manufacture_eql_to = round($stats['co2_total'] / 6000); - $manufacture_legend = $manufacture_eql_to . ' ' . Str::plural('car', $manufacture_eql_to); - } - else { - $consume_svg = 'svg-tv'; - $consume_label = 'Like watching TV for'; - $consume_eql_to = ((1 / 0.024) * $stats['co2_total'] ) / 24; - $consume_eql_to = number_format(round($consume_eql_to), 0, '.', ','); - $consume_legend = $consume_eql_to . ' ' . Str::plural('day', $consume_eql_to); - - $manufacture_svg = 'svg-sofa'; - $manufacture_label = 'Like manufacturing'; - $manufacture_eql_to = round($stats['co2_total'] / 100); - $manufacture_legend = $manufacture_eql_to . ' ' . Str::plural('sofa', $manufacture_eql_to); - } - ?> - -
    -
    -
    -
    -

    {{{ $consume_label }}}

    - @include('partials/'.$consume_svg) -

    {{{ $consume_legend }}}

    -
    -
    -
    -
    -

    {{{ $manufacture_label }}}

    - @include('partials/'.$manufacture_svg) -

    {{{ $manufacture_legend }}}

    -
    -
    -
    -
    -
    - -
    - -

    Device breakdown

    - -
    -
    -
      -
    • -
      - @php( $group_device_count = 0 ) - - @if (isset($device_count_status[0])) - @php( $group_device_count = (int)$device_count_status[0]->counter ) - @endif - - @if (isset($device_count_status[1])) - @php( $group_device_count += (int)$device_count_status[1]->counter ) - @endif - - @if (isset($device_count_status[2])) - @php( $group_device_count += (int)$device_count_status[2]->counter ) - @endif - -

      Total devices worked on

      - {{{ $group_device_count }}} - -
      -
    • -
    • -
      -

      Fixed devices

      - @if (isset($device_count_status[0])) - {{{ (int)$device_count_status[0]->counter }}} - @else - 0 - @endif - -
      -
    • -
    • -
      -

      Repairable devices

      - @if (isset($device_count_status[1])) - {{{ (int)$device_count_status[1]->counter }}} - @else - 0 - @endif - -
      -
    • -
    • -
      -

      End-of-life devices

      - @if (isset($device_count_status[2])) - {{{ (int)$device_count_status[2]->counter }}} - @else - 0 - @endif - -
      -
    • -
    • -
      -

      Most repaired devices

      -
      - - @for ($i=0; $i < 3; $i++) - @if (isset($top[$i])) -
      {{{ $top[$i]->name }}}:
      -
      {{{ $top[$i]->counter }}}
      - @else -
      {{{ $i+1 }}}. N/A
      - @endif - @endfor - -
      - -
      -
    • -
    -
    -
    - @include('partials.group-device-breakdown') -
    -
    - -
    - - @else - - @if(isset($response)) -
    -
    - -
    -
    - @endif - - @endif - -
    - -
    - -
    - -@endsection diff --git a/routes/web.php b/routes/web.php index da7fbe15f2..21d1494f55 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,7 +25,6 @@ use App\Http\Controllers\PartyController; use App\Http\Controllers\PrintcatOraController; use App\Http\Controllers\RoleController; -use App\Http\Controllers\SearchController; use App\Http\Controllers\SkillsController; use App\Http\Controllers\StyleController; use App\Http\Controllers\TabicatOraController; @@ -379,9 +378,6 @@ Route::get('/delete/{id}', [GroupTagsController::class, 'getDeleteTag']); }); - //Search Controller - Route::get('/search', [SearchController::class, 'index']); - //Export Controller Route::get('/export/parties', [ExportController::class, 'parties']); }); diff --git a/tests/Feature/Stats/EventStatsTest.php b/tests/Feature/Stats/EventStatsTest.php index e21df60ef7..a683f4f9a7 100644 --- a/tests/Feature/Stats/EventStatsTest.php +++ b/tests/Feature/Stats/EventStatsTest.php @@ -178,16 +178,6 @@ public function event_stats_with_both_powered_and_unpowered_devices() $response = $this->get('/party/stats/' . $event->idevents . '/wide'); $response->assertSuccessful(); $response->assertSee('23', false); - - // Check that the search page loads. - $this->loginAsTestUser(Role::ADMINISTRATOR); - $response = $this->get('/search'); - $response->assertSuccessful(); - $response->assertSee($event->venue); - - $response = $this->get("/search?fltr=1&parties[]={$event->idevents}"); - $response->assertSee('id="key-stats"', false); - $response->assertSee($event->venue); } /** @test */ From 791052334b94c9caa3b5a330c53a70968b7873ee Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Mon, 28 Aug 2023 13:58:50 +0100 Subject: [PATCH 2/5] WIP export of events. --- app/Helpers/SearchHelper.php | 133 ---------------------- app/Http/Controllers/ExportController.php | 119 +++++++++---------- app/Search.php | 118 ------------------- lang/en/devices.php | 2 +- lang/en/groups.php | 14 ++- resources/js/components/GroupEvents.vue | 11 +- routes/web.php | 4 +- tests/Feature/Events/ExportTest.php | 41 +++---- 8 files changed, 90 insertions(+), 352 deletions(-) delete mode 100644 app/Helpers/SearchHelper.php delete mode 100644 app/Search.php diff --git a/app/Helpers/SearchHelper.php b/app/Helpers/SearchHelper.php deleted file mode 100644 index 18d9e3797a..0000000000 --- a/app/Helpers/SearchHelper.php +++ /dev/null @@ -1,133 +0,0 @@ - 'Filter Stats', - 'charts' => true, - 'clusters' => null, - 'mostleast' => null, - 'groups' => [], - 'sorted_parties' => [], - 'stats' => null, - 'response' => null, - 'user' => User::find(Auth::id()), - 'group_tags' => GroupTags::all(), - ]; - } - - public static function getUserGroupsAndParties() - { - /** Init all needed classes **/ - $Groups = new Group; - $Parties = new Party; - $user = User::find(Auth::id()); - $data = [ - 'groups' => [], - 'group_ids' => [], - 'parties' => [], - 'sorted_parties' => [], - 'allowed_parties' => [], - ]; - - /* Get default data for the search dropdowns **/ - if (Fixometer::hasRole($user, 'Administrator')) { - $data['groups'] = $Groups->findList(); - $data['parties'] = $Parties->findAllSearchable(); - foreach ($data['parties'] as $i => $party) { - $data['parties'][$i]->venue = is_null($data['parties'][$i]->venue) ? $data['parties'][$i]->location : $data['parties'][$i]->venue; - $data['allowed_parties'][] = $party->id; - } - } elseif (Fixometer::hasRole($user, 'Host')) { - $data['groups'] = $Groups->ofThisUser($user->id); - foreach ($data['groups'] as $i => $group) { - $data['groups'][$i]->id = $group->idgroups; - $data['group_ids'][] = $group->idgroups; - } - $data['parties'] = $Parties->ofTheseGroups($data['group_ids'], true); - foreach ($data['parties'] as $i => $party) { - $data['parties'][$i]->id = $party->idevents; - $data['parties'][$i]->venue = is_null($data['parties'][$i]->venue) ? $data['parties'][$i]->location : $data['parties'][$i]->venue; - $data['allowed_parties'][] = $party->idevents; - } - } - foreach ($data['parties'] as $party) { - $data['sorted_parties'][$party->group_name][] = $party; - } - - return $data; - } - - /** - * Validate and process input filters. - * - * @return array - */ - public static function getSearchFilters(Request $request) - { - $filters = [ - 'searched_groups' => null, - 'searched_parties' => null, - 'from_date' => null, - 'to_date' => null, - 'group_tags' => null, - 'response' => null, - ]; - - if ($request->has('groups') && is_array($request->input('groups'))) { - $filters['searched_groups'] = filter_var_array($request->input('groups'), FILTER_SANITIZE_NUMBER_INT); - } - - if ($request->has('parties') && is_array($request->input('parties'))) { - $filters['searched_parties'] = filter_var_array($request->input('parties'), FILTER_SANITIZE_NUMBER_INT); - } - - if ($request->has('from-date') && ! empty($request->input('from-date'))) { - if (! DateTime::createFromFormat('Y-m-d', $request->input('from-date'))) { - $filters['response'] = ['danger' => 'Invalid "From" date"']; - } else { - $fromDate = DateTime::createFromFormat('Y-m-d', $request->input('from-date')); - $filters['from_date'] = strtotime($fromDate->format('Y-m-d')); - } - } - - if ($request->has('to-date') && ! empty($request->input('to-date'))) { - if (! DateTime::createFromFormat('Y-m-d', $request->input('to-date'))) { - $filters['response'] = ['danger' => 'Invalid "To" date"']; - } else { - $toDate = DateTime::createFromFormat('Y-m-d', $request->input('to-date')); - $filters['to_date'] = strtotime($toDate->format('Y-m-d')); - } - } - - if ($request->has('group_tags') && ! empty($request->input('group_tags'))) { - $filters['group_tags'] = $request->input('group_tags'); - } - - return $filters; - } - - public static function debugParams($params) - { - foreach ($params as $k => $v) { - $type = gettype($v); - if (is_array($v)) { - $type .= ' ('.count($v).')'; - } - logger($k.' => '.$type); - } - } -} diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 6a4a705bcc..6b550427df 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -145,78 +145,67 @@ public function devices(Request $request, $idevents = NULL, $idgroups = NULL) /** * @return \Illuminate\Http\Response */ - public function parties(Request $request) + public function groupEvents(Request $request, $idgroups) { - if ($request->has('fltr') && ! empty($request->input('fltr'))) { - $dropdowns = SearchHelper::getUserGroupsAndParties(); - $filters = SearchHelper::getSearchFilters($request); - - $Search = new Search; - $PartyList = $Search->parties( - $filters['searched_parties'], - $filters['searched_groups'], - $filters['from_date'], - $filters['to_date'], - $filters['group_tags'], - $dropdowns['allowed_parties'] - ); - - if (count($PartyList) > 0) { - - // prepare the column headers - $statsKeys = array_keys(\App\Party::getEventStatsArrayKeys()); - array_walk($statsKeys, function (&$k) { - $key = explode('_', $k); - array_walk($key, function (&$v) { - $v = str_replace('Waste', 'Weight', str_replace('Co2', 'CO2', ucfirst($v))); - }); - $k = implode(' ', $key); - }); - $headers = array_merge(['Date', 'Venue', 'Group', 'Approved'], $statsKeys); - - // Send these to getEventStats() to speed things up a bit. - $eEmissionRatio = \App\Helpers\LcaStats::getEmissionRatioPowered(); - $uEmissionratio = \App\Helpers\LcaStats::getEmissionRatioUnpowered(); - - // prepare the column values - $PartyArray = []; - foreach ($PartyList as $i => $party) { - $stats = $party->getEventStats($eEmissionRatio, $uEmissionratio); - array_walk($stats, function (&$v) { - $v = round($v); - }); - - $PartyArray[$i] = [ - $party->getFormattedLocalStart(), - $party->getEventName(), - $party->theGroup && $party->theGroup->name ? $party->theGroup->name : '?', - $party->approved ? 'true' : 'false', - ]; - $PartyArray[$i] += $stats; - } + $group = Group::findOrFail($idgroups); + $parties = $group->parties()->undeleted()->get(); - // write content to file - $filename = 'parties.csv'; + $headers = [ + __('groups.export.events.date'), + __('groups.export.events.event'), + __('groups.export.events.group'), + __('groups.export.events.volunteers'), + __('groups.export.events.participants'), + __('groups.export.events.items_total'), + __('groups.export.events.items_fixed'), + __('groups.export.events.items_repairable'), + __('groups.export.events.items_end_of_life'), + __('groups.export.events.items_kg_waste_prevented'), + __('groups.export.events.items_kg_co2_prevent'), + ]; + + // Send these to getEventStats() to speed things up a bit. + $eEmissionRatio = \App\Helpers\LcaStats::getEmissionRatioPowered(); + $uEmissionratio = \App\Helpers\LcaStats::getEmissionRatioUnpowered(); - $file = fopen($filename, 'w+'); - fputcsv($file, $headers); + // prepare the column values + $PartyArray = []; + foreach ($parties as $party) { + $stats = $party->getEventStats($eEmissionRatio, $uEmissionratio); + array_walk($stats, function (&$v) { + $v = round($v); + }); + + $PartyArray[] = [ + $party->getFormattedLocalStart(), + $party->getEventName(), + $party->theGroup && $party->theGroup->name ? $party->theGroup->name : '?', + $party->volunteers, + $party->participants ? $party->participants : 0, + $stats['fixed_devices'] + $stats ['repairable_devices'] + $stats['dead_devices'], + $stats['fixed_devices'], + $stats['repairable_devices'], + $stats['dead_devices'], + $stats['waste_powered'] + $stats['waste_unpowered'], + $stats['co2_powered'] + $stats['co2_unpowered'], + ]; + } - foreach ($PartyArray as $d) { - fputcsv($file, $d); - } - fclose($file); + // write content to file + $filename = 'events.csv'; - $headers = [ - 'Content-Type' => 'text/csv', - ]; + $file = fopen($filename, 'w+'); + fputcsv($file, $headers); - return Response::download($filename, $filename, $headers); - } - // } + foreach ($PartyArray as $d) { + fputcsv($file, $d); } + fclose($file); + + $headers = [ + 'Content-Type' => 'text/csv', + ]; - return view('export.parties', [ - 'data' => ['No data to return'], - ]); + return Response::download($filename, $filename, $headers); } } diff --git a/app/Search.php b/app/Search.php deleted file mode 100644 index 174b239e17..0000000000 --- a/app/Search.php +++ /dev/null @@ -1,118 +0,0 @@ -leftJoin('grouptags_groups as gtag', 'events.group', 'gtag.group'); - - if (! empty($list)) { - $eventsQuery->whereIn('events.idevents', $list); - } - - if (! is_null($groups)) { - $eventsQuery->whereIn('events.group', $groups); - } - - if (! is_null($from)) { - $eventsQuery->where('event_start_utc', '>=', date('Y-m-d H:i:s', $from)); - } - - if (! is_null($to)) { - $eventsQuery->where('event_end_utc', '<=', date('Y-m-d H:i:s', $to)); - } - - if (! is_null($group_tags)) { - $eventsQuery->whereIn('gtag.group_tag', $group_tags); - } - - if (! is_null($allowedParties)) { - $eventsQuery->whereIn('events.idevents', $allowedParties); - } - - $eventsQuery->groupBy('events.idevents'); - $eventsQuery->orderBy('events.event_start_utc', 'desc'); - - // We need to explicitly select what we want to return otherwise gtag.group might overwrite events.group. - $events = $eventsQuery->select(['events.*', 'gtag.group_tag'])->get(); - - $me = auth()->user(); - - $events = $events->filter(function ($event) use ($me) { - return User::userCanSeeEvent($me, $event); - }); - - return $events; - } - - public function deviceStatusCount($parties) - { - $sql = 'SELECT COUNT(*) AS `counter`, `d`.`repair_status` AS `status`, `d`.`event` - FROM `devices` AS `d`'; - $sql .= ' WHERE `repair_status` > 0 '; - $sql .= ' AND `d`.`event` IN ('.implode(', ', $parties).')'; - $sql .= ' GROUP BY `status`'; - - return DB::select(DB::raw($sql)); - } - - public function countByCluster($parties, $cluster) - { - $sql = 'SELECT COUNT(*) AS `counter`, `repair_status` FROM `devices` AS `d` - INNER JOIN `events` AS `e` - ON `d`.`event` = `e`.`idevents` - INNER JOIN `categories` AS `c` - ON `d`.`category` = `c`.`idcategories` - WHERE `c`.`cluster` = :cluster AND `d`.`repair_status` > 0 '; - $sql .= ' AND `d`.`event` IN ('.implode(', ', $parties).') '; - $sql .= ' GROUP BY `repair_status` - ORDER BY `repair_status` ASC - '; - try { - return DB::select(DB::raw($sql), ['cluster' => $cluster]); - } catch (\Illuminate\Database\QueryException $e) { - dd($e); - } - } - - public function findMostSeen($parties, $status = 1, $cluster = null) - { - $m1 = env('MISC_CATEGORY_ID'); - $parties = implode(', ', $parties); - $sql = "SELECT COUNT(`d`.`category`) AS `counter`, `c`.`name` FROM `devices` AS `d` - INNER JOIN `events` AS `e` ON `d`.`event` = `e`.`idevents` - INNER JOIN `categories` AS `c` ON `d`.`category` = `c`.`idcategories` - WHERE 1=1 and `c`.`idcategories` NOT IN ($m1) - AND `d`.`event` IN ($parties)"; - if (! is_null($status) && is_numeric($status)) { - $sql .= ' AND `d`.`repair_status` = :status '; - } - if (! is_null($cluster) && is_numeric($cluster)) { - $sql .= ' AND `c`.`cluster` = :cluster '; - } - $sql .= ' GROUP BY `d`.`category` ORDER BY `counter` DESC'; - $sql .= (! is_null($cluster) ? ' LIMIT 1' : ''); - - try { - if (! is_null($status) && is_numeric($status) && is_null($cluster)) { - return DB::select(DB::raw($sql), ['status' => $status]); - } elseif (! is_null($cluster) && is_numeric($cluster) && is_null($status)) { - return DB::select(DB::raw($sql), ['cluster' => $cluster]); - } elseif (! is_null($status) && is_numeric($status) && ! is_null($cluster) && is_numeric($cluster)) { - return DB::select(DB::raw($sql), ['status' => $status, 'cluster' => $cluster]); - } else { - return DB::select(DB::raw($sql)); - } - } catch (\Illuminate\Database\QueryException $e) { - dd($e); - } - } -} diff --git a/lang/en/devices.php b/lang/en/devices.php index 5d9d4e6169..8cb8c52fdb 100644 --- a/lang/en/devices.php +++ b/lang/en/devices.php @@ -4,7 +4,7 @@ 'devices' => 'Repairs', 'export_device_data' => 'Export all data', 'export_event_data' => 'Export event data', - 'export_group_data' => 'Export group data', + 'export_group_data' => 'Download repair data', 'by_date' => 'By date', 'category' => 'Category', 'group' => 'Group', diff --git a/lang/en/groups.php b/lang/en/groups.php index 6ea7512550..3c5db40b8a 100644 --- a/lang/en/groups.php +++ b/lang/en/groups.php @@ -170,5 +170,17 @@ 'made_host' => 'We have made :name a host for this group.', 'permission' => 'Sorry, you do not have permission to do this.', 'volunteer_remove_success' => 'We have removed :name from this group.', - 'volunteer_remove_error' => 'We are unable to remove :name from this group.' + 'volunteer_remove_error' => 'We are unable to remove :name from this group.', + 'export_event_list' => 'Download event list', + 'export.events.date' => 'Date', + 'export.events.event' => 'Event', + 'export.events.group' => 'Group', + 'export.events.volunteers' => 'Volunteers', + 'export.events.participants' => 'Participants', + 'export.events.items_total' => 'Items total', + 'export.events.items_fixed' => 'Items fixed', + 'export.events.items_repairable' => 'Items repairable', + 'export.events.items_end_of_life' => 'Items end-of-life', + 'export.events.items_kg_waste_prevented' => 'kg waste prevented', + 'export.events.items_kg_co2_prevent' => 'kg CO2 prevented', ]; diff --git a/resources/js/components/GroupEvents.vue b/resources/js/components/GroupEvents.vue index 584fadf13b..b44c013bb1 100644 --- a/resources/js/components/GroupEvents.vue +++ b/resources/js/components/GroupEvents.vue @@ -12,9 +12,14 @@