Optimisasi untuk K13 2020
- restriksi untuk print dihilangkan - stempel pada ttd ditambahkann - isi surat disesuaikan - ukuran kertas disesuaikan - data siswa baru ditambahkan
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Imports\HasilBelajarsImport;
|
||||
use App\Imports\K13HasilBelajarsImport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ImportExcel extends Command
|
||||
@@ -13,7 +14,7 @@ class ImportExcel extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ba:import-excel {filename}';
|
||||
protected $signature = 'ba:import-excel {filename} {--k|kurikulum=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -40,7 +41,15 @@ class ImportExcel extends Command
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
Excel::import(new HasilBelajarsImport, $this->argument('filename'));
|
||||
if ($this->option('kurikulum')) {
|
||||
if ($this->option('kurikulum') == 'k13')
|
||||
Excel::import(new K13HasilBelajarsImport, $this->argument('filename'));
|
||||
else
|
||||
throw new Exception('Kurikulum tidak ditemukan.');
|
||||
}
|
||||
else {
|
||||
Excel::import(new HasilBelajarsImport, $this->argument('filename'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
39
app/Events/K13HasilBelajarImported.php
Normal file
39
app/Events/K13HasilBelajarImported.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\K13HasilBelajar;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class K13HasilBelajarImported
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $hasilBelajar;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(K13HasilBelajar $hasilBelajar)
|
||||
{
|
||||
$this->hasilBelajar = $hasilBelajar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return \Illuminate\Broadcasting\Channel|array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
52
app/Imports/K13HasilBelajarsImport.php
Normal file
52
app/Imports/K13HasilBelajarsImport.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Siswa;
|
||||
use App\K13HasilBelajar;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class K13HasilBelajarsImport implements ToModel, WithHeadingRow
|
||||
{
|
||||
/**
|
||||
* @param array $row
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function model(array $row)
|
||||
{
|
||||
$siswa = Siswa::where('nisn', $row['nisn'])
|
||||
->where('nis', $row['nis'])->first();
|
||||
|
||||
if (!$siswa)
|
||||
return null;
|
||||
|
||||
$fieldMeta = [];
|
||||
foreach ($row as $key => $value) {
|
||||
if (preg_match("/\_+/", $key)) {
|
||||
$rowNames = explode('_', $key);
|
||||
if (count($rowNames) == 4)
|
||||
$fieldMeta[$rowNames[0]][$rowNames[1]][$rowNames[2]][$rowNames[3]] = round($value, 2);
|
||||
else
|
||||
$fieldMeta[$rowNames[0]][$rowNames[1]][$rowNames[2]] = round($value, 2);
|
||||
}
|
||||
else {
|
||||
$fieldMeta[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return new K13HasilBelajar([
|
||||
'siswa_id' => $siswa->id,
|
||||
'meta' => $fieldMeta,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sheets(): array
|
||||
{
|
||||
return [
|
||||
new FirstSheetImport()
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/K13HasilBelajar.php
Normal file
31
app/K13HasilBelajar.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Events\K13HasilBelajarImported;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class K13HasilBelajar extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'k13_hasil_belajars';
|
||||
|
||||
protected $fillable = [
|
||||
'siswa_id', 'meta',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'meta' => 'array',
|
||||
];
|
||||
|
||||
protected $dispatchesEvents = [
|
||||
'saved' => K13HasilBelajarImported::class,
|
||||
];
|
||||
|
||||
public function siswa()
|
||||
{
|
||||
return $this->belongsTo('App\Siswa');
|
||||
}
|
||||
}
|
||||
32
app/Listeners/LogImportedK13HasilBelajar.php
Normal file
32
app/Listeners/LogImportedK13HasilBelajar.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Events\K13HasilBelajarImported;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogImportedK13HasilBelajar
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(K13HasilBelajarImported $event)
|
||||
{
|
||||
Log::channel('single')->debug($event->hasilBelajar);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\HasilBelajarImported;
|
||||
use App\Events\K13HasilBelajarImported;
|
||||
use App\Listeners\LogImportedHasilBelajar;
|
||||
use App\Listeners\LogImportedK13HasilBelajar;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
@@ -23,6 +25,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
HasilBelajarImported::class => [
|
||||
LogImportedHasilBelajar::class,
|
||||
],
|
||||
K13HasilBelajarImported::class => [
|
||||
LogImportedK13HasilBelajar::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,4 +31,9 @@ class Siswa extends Model
|
||||
{
|
||||
return $this->hasOne('App\HasilBelajar');
|
||||
}
|
||||
|
||||
public function k13HasilBelajar()
|
||||
{
|
||||
return $this->hasOne('App\K13HasilBelajar');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user