Completed
Push — master ( f39e45...7bc33b )
by
unknown
10s
created

BantenprovZonaSeeder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
use Illuminate\Database\Seeder;
3
/**
4
 * Usage :
5
 * [1] $ composer dump-autoload -o
6
 * [2] $ php artisan db:seed --class=BantenprovZonaSeeder
7
 */
8
class BantenprovZonaSeeder extends Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /* text color */
11
    protected $RED     ="\033[0;31m";
12
    protected $CYAN    ="\033[0;36m";
13
    protected $YELLOW  ="\033[1;33m";
14
    protected $ORANGE  ="\033[0;33m";
15
    protected $PUR     ="\033[0;35m";
16
    protected $GRN     ="\e[32m";
17
    protected $WHI     ="\e[37m";
18
    protected $NC      ="\033[0m";
19
    /* File name */
20
    /* location : /databse/seeds/file_name.csv */
21
    protected $fileName = "BantenprovZonaSeeder.csv";
22
    /* text info : default (true) */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
    protected $textInfo = true;
24
    /* model class */
25
    protected $model;
26
    /* __construct */
27
    public function __construct(){
28
        $this->model = new Bantenprov\Zona\Models\Bantenprov\Zona\Zona;
29
    }
30
    /**
31
     * Run the database seeds.
32
     *
33
     * @return void
34
     */
35
    public function run()
36
    {
37
        $this->insertData();
38
    }
39
    /* function insert data */
40
    protected function insertData()
41
    {
42
        /* silahkan di rubah sesuai kebutuhan */
43
        foreach($this->readCSV() as $data){
44
45
            
46
        	$this->model->create([
47
            	'user_id' => $data['user_id'],
48
				'master_zona_id' => $data['master_zona_id'],
49
				'siswa_id' => $data['siswa_id'],
50
				'nomor_un' => $data['nomor_un'],
51
                'zona_siswa' => $data['zona_siswa'],
52
                'zona_sekolah' => $data['zona_sekolah'],
53
                'lokasi_siswa' => $data['lokasi_siswa'],
54
                'lokasi_sekolah' => $data['lokasi_sekolah'],
55
                'nilai_zona' => $data['nilai_zona'],
56
57
        	]);
58
        
59
60
        }
61
62
        if($this->textInfo){                
63
            echo "============[DATA]============\n";
64
            $this->orangeText('user_id : ').$this->greenText($data['user_id']);
65
			echo"\n";
66
			$this->orangeText('master_zona_id : ').$this->greenText($data['master_zona_id']);
67
			echo"\n";
68
			$this->orangeText('siswa_id : ').$this->greenText($data['siswa_id']);
69
			echo"\n";
70
			$this->orangeText('nomor_un : ').$this->greenText($data['nomor_un']);
71
			echo"\n";
72
            this->orangeText('zona_siswa : ').$this->greenText($data['zona_siswa']);
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
73
            echo"\n";
74
            this->orangeText('zona_sekolah : ').$this->greenText($data['zona_sekolah']);
75
            echo"\n";
76
            this->orangeText('lokasi_siswa : ').$this->greenText($data['lokasi_siswa']);
77
            echo"\n";
78
            this->orangeText('lokasi_sekolah : ').$this->greenText($data['lokasi_sekolah']);
79
            echo"\n";
80
            this->orangeText('nilai_zona : ').$this->greenText($data['nilai_zona']);
81
            echo"\n";
82
83
            
84
            
85
        
86
            echo "============[DATA]============\n\n";
87
        }
88
89
        $this->greenText('[ SEEDER DONE ]');
90
        echo"\n\n";
91
    }
92
    /* text color: orange */
93
    protected function orangeText($text)
94
    {
95
        printf($this->ORANGE.$text.$this->NC);
96
    }
97
    /* text color: green */
98
    protected function greenText($text)
99
    {
100
        printf($this->GRN.$text.$this->NC);
101
    }
102
    /* function read CSV file */
103
    protected function readCSV()
104
    {
105
        $file = fopen(database_path("seeds/".$this->fileName), "r");
106
        $all_data = array();
107
        $row = 1;
108
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){
109
            $all_data[] = ['user_id' => $data[0],
110
                           'master_zona_id' => $data[1],
111
                           'siswa_id' => $data[2],
112
                           'nomor_un' => $data[3],
113
                           'zona_siswa' => $data[4],
114
                           'zona_sekolah' => $data[5],
115
                           'lokasi_siswa' => $data[6],
116
                           'lokasi_sekolah' => $data[7],
117
                           'nilai_zona' => $data[8],
118
                          ];
119
        }
120
        fclose($file);
121
        return  $all_data;
122
    }
123
}
124