1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Exports; |
4
|
|
|
|
5
|
|
|
use App\Models\Security_user; |
6
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection; |
7
|
|
|
use Maatwebsite\Excel\Concerns\WithHeadings; |
8
|
|
|
use Maatwebsite\Excel\Concerns\Exportable; |
9
|
|
|
use App\Models\Import_mapping; |
10
|
|
|
use Maatwebsite\Excel\Concerns\WithEvents; |
11
|
|
|
use Maatwebsite\Excel\Concerns\WithStartRow; |
12
|
|
|
use Maatwebsite\Excel\Events\BeforeWriting; |
13
|
|
|
use Maatwebsite\Excel\Events\BeforeExport; |
14
|
|
|
use Illuminate\Support\Facades\Auth; |
15
|
|
|
use Maatwebsite\Excel\Excel; |
16
|
|
|
use Maatwebsite\Excel\Files\LocalTemporaryFile; |
17
|
|
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets; |
18
|
|
|
use Maatwebsite\Excel\Concerns\RegistersEventListeners; |
19
|
|
|
use Maatwebsite\Excel\Events\BeforeSheet; |
20
|
|
|
|
21
|
|
|
class UsersExport implements FromCollection, WithEvents, WithStartRow, WithMultipleSheets { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return \Illuminate\Support\Collection |
25
|
|
|
*/ |
26
|
|
|
use Exportable, |
|
|
|
|
27
|
|
|
RegistersEventListeners; |
28
|
|
|
|
29
|
|
|
public $_file_name = 'users.xls'; |
30
|
|
|
|
31
|
|
|
public function __construct($class) { |
32
|
|
|
|
33
|
|
|
$this->class = $class; |
|
|
|
|
34
|
|
|
$this->_file_name = time() . '_' . Auth::user()->id . '_' . 'student_upload.xls'; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function registerEvents(): array { |
38
|
|
|
return [ |
39
|
|
|
BeforeSheet::class => function(BeforeSheet $event){ |
|
|
|
|
40
|
|
|
// dd($event->crea) |
41
|
|
|
}, |
42
|
|
|
BeforeWriting::class => function(BeforeWriting $event) { |
43
|
|
|
$file_path = 'app/censusNo_className_sis_students_bulk_upload_v1.xlsx'; |
44
|
|
|
$event->writer->reopen(new LocalTemporaryFile(storage_path($file_path)), Excel::XLSX); |
45
|
|
|
$event->writer->getDelegate()->setActiveSheetIndex(1); |
46
|
|
|
return $event->getWriter()->getDelegate()->getActiveSheet(); |
47
|
|
|
} |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function sheets(): array { |
52
|
|
|
return [ |
53
|
|
|
1 => $this |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function startRow(): int { |
58
|
|
|
return 3; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function collection() { |
62
|
|
|
|
63
|
|
|
$class = $this->class; |
64
|
|
|
return Security_user::select('openemis_no', 'first_name', 'gender_id', 'date_of_birth', 'address', 'birthplace_area_id') |
65
|
|
|
->with(['class', 'special_needs']) |
66
|
|
|
->whereHas('class', function ($query) use ($class) { |
67
|
|
|
$query->where('institution_class_id', '=', $class); |
68
|
|
|
}) |
69
|
|
|
->get(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|