thebadspace/app/Http/Controllers/ExportController.php
ro 29c8935bfa Quote clean up CSV export, tweaking action counts
https://tenforward.social/@noracodes reported an issue with the CSV not
rendering properly because of the mix of single and double quotes, so
that's been cleaned up.

Also fixed action sorting which was reversed.
2023-11-12 12:22:22 -06:00

64 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Location;
use App\Models\Source;
class ExportController extends Controller
{
public function exportIndex()
{
return view('front.exports', [
'title' => "Exports"
]);
}
//
public function exportCSV($type, $percent)
{
$columns = [];
$list = [];
$locations = Location::where("active", true)->get();
$sources = Source::where("active", true)->get();
if ($type == 'mastodon') {
$columns = [
'domain',
'severity',
'public_comment',
'reject_media',
'reject_reports',
'obfuscate',
];
};
foreach ($locations as $location) {
$total = $location->block_count + $location->silence_count;
if ($total >= 2) {
$rate = $total / count($sources);
if ($rate * 100 >= $percent) {
if ($type == 'mastodon') {
//comman break teh CSV so just take them out
$comments = str_replace(",", ";", $location->description);
//remove extra white space
$comments = str_replace(["\n\r", "\n", "\r"], " ", $comments);
$comments = str_replace(['"', "'"], "", $comments);
//add to the export list
array_push($list, [$location->url, $location->rating, $comments, "FALSE", "FALSE", "FALSE"]);
}
}
}
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=' . $type . "-" . $percent);
echo implode(',', $columns) . PHP_EOL;
foreach ($list as $item) {
echo implode(',', $item) . PHP_EOL;
}
}
}