You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TheBadSpace/app/Http/Controllers/ExportController.php

58 lines
1.6 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') {
$comments = str_replace(",", ";", $location->description);
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;
}
}
}