atcheck/app/Exports/AttendanceGroupedExportSingleView.php

47 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Exports;
use App\Subject;
use App\Classes;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\WithTitle;
class AttendanceGroupedExportSingleView implements FromView, WithTitle
{
/**
* @return \Illuminate\Support\Collection
*/
private $attendances;
private $groupBy;
private $groupedValue;
public function __construct($attendances, $groupBy, $groupedValue)
{
$this->attendances = $attendances;
$this->groupBy = $groupBy;
$this->groupedValue = $groupedValue;
}
public function view(): View
{
return view('user.attendances_table', ['attendances_list' => $this->attendances, 'export' => 1]);
}
public function title(): string
{
if($this->groupBy == 'classes_id') {
$subject = Subject::findOrFail(Classes::find($this->groupedValue)->subject_id)->name;
$date = Classes::findOrFail($this->groupedValue)->date;
2019-12-14 22:41:09 +01:00
$this->groupedValue = "{$date} {$subject}";
} else if($this->groupBy == 'seat_number') {
$this->groupedValue = "{$this->groupedValue}";
}
2019-12-14 22:38:00 +01:00
return substr(str_replace(":", "-", "{$this->groupedValue}"), 0, 30);
}
}