Files
nuhodds_fi4/app/Traits/PlayerProps/CopyData.php
T
2026-10-31 21:41:03 +01:00

83 lines
2.3 KiB
PHP

<?php
namespace App\Traits\PlayerProps;
use Filament\Notifications\Notification;
trait CopyData
{
public function copyDevelopment()
{
if ($this->player_on_field_counter < 10) {
Notification::make()->title('Needs a calculation first ')
->info()
->send();
return;
}
$copystring = '';
foreach ($this->calculationVariables as $k => $part) {
foreach ($part as $row) {
if ($copystring == '') {
$copystring = "Part 1\n";
$keys = array_keys($row);
$copystring .= implode(';', $keys)."\n";
}
$copystring .= implode(';', $row)."\n";
}
if ($k == 0) {
$copystring .= "\nPart 2\n";
}
}
$this->js("navigator.clipboard.writeText(`$copystring`)");
Notification::make()
->title('Calculation variables copied')
->success()
->send();
}
public function copyResult()
{
if ($this->player_on_field_counter < 10) {
Notification::make()->title('Needs a calculation first ')
->info()
->send();
return;
}
$header = ['name', 'foot', 'events', 'average min', 'position', 'on field', 'gls', 'fls', 'ofs', 'crd', 'snt', 'tsh', 'wfl'];
$copystring = implode(';', $header)."\n";
foreach ($this->players as $row) {
$tmp = [];
$tmp[] = $row['name'];
$tmp[] = $row['foot'];
$tmp[] = $row['tot_evt'];
$tmp[] = $row['ave_min'];
if ($row['pos']) {
$tmp[] = $row['pos'];
} else {
$tmp[] = $row['pos_ori'];
}
$tmp[] = $row['active'];
$tmp[] = $row['gls'];
$tmp[] = $row['fls'];
$tmp[] = $row['ofs'];
$tmp[] = $row['crd'];
$tmp[] = $row['snt'];
$tmp[] = $row['tsh'];
$tmp[] = $row['wfl'];
$copystring .= implode(';', $tmp)."\n";
}
$this->js("navigator.clipboard.writeText(`$copystring`)");
Notification::make()
->title('Results copied')
->success()
->send();
}
}