2023-08-28 23:51:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-02-11 19:26:54 +01:00
|
|
|
use App\Repositories\LocationRepository;
|
2023-09-28 23:02:35 +02:00
|
|
|
use App\Models\Source;
|
|
|
|
|
2023-08-28 23:51:42 +02:00
|
|
|
class ExportController extends Controller
|
|
|
|
{
|
2024-02-11 19:26:54 +01:00
|
|
|
protected $locationRepository;
|
|
|
|
|
|
|
|
public function __construct(LocationRepository $locationRepository)
|
|
|
|
{
|
|
|
|
$this->locationRepository = $locationRepository;
|
|
|
|
}
|
|
|
|
|
2023-09-28 23:02:35 +02:00
|
|
|
public function exportIndex()
|
|
|
|
{
|
2024-02-11 19:26:54 +01:00
|
|
|
$heatArray = [90, 80, 70, 60, 50, 40, 30, 20];
|
|
|
|
$sources = Source::where("active", true)->get();
|
|
|
|
$locations = $this->locationRepository->getActiveLocations();
|
|
|
|
$list = [];
|
|
|
|
foreach ($heatArray as $rating) {
|
|
|
|
$count = 0;
|
|
|
|
foreach ($locations as $location) {
|
|
|
|
$rate = $location->actions_count / count($sources);
|
|
|
|
if ($rate * 100 >= $rating) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
array_push($list, ["heatRating" => $rating, "ratingCount" => $count]);
|
|
|
|
}
|
2023-09-28 23:02:35 +02:00
|
|
|
return view('front.exports', [
|
2024-02-11 19:26:54 +01:00
|
|
|
'title' => "Exports",
|
|
|
|
'list' => $list
|
2023-09-28 23:02:35 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-08-28 23:51:42 +02:00
|
|
|
//
|
2023-09-28 23:02:35 +02:00
|
|
|
public function exportCSV($type, $percent)
|
2023-08-28 23:51:42 +02:00
|
|
|
{
|
2023-09-28 23:02:35 +02:00
|
|
|
$columns = [];
|
|
|
|
$list = [];
|
|
|
|
|
2024-02-11 19:26:54 +01:00
|
|
|
$locations = $this->locationRepository->getActiveLocations();
|
2023-09-28 23:02:35 +02:00
|
|
|
$sources = Source::where("active", true)->get();
|
|
|
|
if ($type == 'mastodon') {
|
|
|
|
$columns = [
|
|
|
|
'domain',
|
|
|
|
'severity',
|
|
|
|
'public_comment',
|
|
|
|
'reject_media',
|
|
|
|
'reject_reports',
|
|
|
|
'obfuscate',
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach ($locations as $location) {
|
2024-02-11 19:26:54 +01:00
|
|
|
$rate = $location->actions_count / 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"]);
|
2023-09-28 23:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-28 23:51:42 +02:00
|
|
|
|
|
|
|
header('Content-Type: text/csv');
|
2023-09-28 23:02:35 +02:00
|
|
|
header('Content-Disposition: attachment; filename=' . $type . "-" . $percent);
|
2023-08-28 23:51:42 +02:00
|
|
|
|
|
|
|
echo implode(',', $columns) . PHP_EOL;
|
2023-09-28 23:02:35 +02:00
|
|
|
foreach ($list as $item) {
|
|
|
|
echo implode(',', $item) . PHP_EOL;
|
2023-08-28 23:51:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|