atcheck/app/Exports/AttendanceGroupedExportSingleView.php

46 lines
1.1 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::find(Classes::find($this->groupedValue)->subject_id)->name;
$date = Classes::find($this->groupedValue)->date;
2019-12-14 22:41:09 +01:00
$this->groupedValue = "{$date} {$subject}";
}
2019-12-14 22:38:00 +01:00
return substr(str_replace(":", "-", "{$this->groupedValue}"), 0, 30);
}
}