Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
SDClowen committed Mar 21, 2024
1 parent 27dfe53 commit cff8186
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/config/database.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
return[
"driver" => "mysql",
"name" => "survey",
"name" => "surmey",
"charset" => "utf8",
"collation" => "utf8_general_ci",
"host" => "localhost",
Expand Down
15 changes: 8 additions & 7 deletions app/controllers/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,25 @@ public function csv(int $surveyId)
header('Pragma: private');
header('Cache-control: private, must-revalidate');
header('Content-type: text/csv');
$csvFileName = preg_replace('/[^A-Za-z0-9_-]/', '', str_replace(' ', '_', $survey->title));
$csvFileName = preg_replace('/[^A-Za-z0-9_-]/', '', str_replace(' ', '-', $survey->title));
header('Content-Disposition: attachment; filename=' . $csvFileName . '.csv');

$fp = fopen('php://output', 'w');

$report = Survey::report($survey);
$data = [];

#values
foreach($report as $title => $data)
{
$csvData[] = $title;

foreach($data["answers"] as $answerKey => $answerValue)
foreach($data["answers"] as $answerTitle => $participateCount)
{
$csvData[] = $answerKey.":".$answerValue;
$answerData[] = $answerTitle;
$valueData[] = $participateCount;
}

fputcsv($fp, $csvData);
fputcsv($fp, [$title]);
fputcsv($fp, $answerData);
fputcsv($fp, $valueData);
}

fclose($fp);
Expand Down
4 changes: 2 additions & 2 deletions app/views/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- Dropdown menu -->
<div id="dropdownRadioHelper" x-show="dropIsOpen" @click.away="dropIsOpen = false" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="opacity-0 scale-90" x-transition:enter-end="opacity-100 scale-100" x-transition:leave="transition ease-in duration-100" x-transition:leave-start="opacity-100 scale-100" x-transition:leave-end="opacity-0 scale-90" class="absolute right-0 top-8 py-2 mt-2 overflow-hidden origin-top z-10 bg-white divide-y divide-gray-100 rounded-lg shadow w-60 border dark:bg-gray-700 dark:divide-gray-600">
<ul class="p-1 space-y-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownRadioHelperButton">
<!--<li>
<li>
<a href="/reports/csv/{$surveyId}" target="blank" class="flex items-center content-center p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-600">
<svg class="w-8 h-8" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
Expand All @@ -55,7 +55,7 @@
</p>
</div>
</a>
</li>-->
</li>
<li>
<a href="#" data-url="/reports/reset/{$surveyId}" class="flex items-center content-center p-2 rounded hover:bg-gray-100 dark:hover:bg-gray-600">
<svg class="w-8 h-8" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
Expand Down

0 comments on commit cff8186

Please sign in to comment.