Code Duplication    Length = 111-111 lines in 2 locations

src/database/seeds/BantenprovNilaiSeederAkademik.php 1 location

@@ 11-121 (lines=111) @@
8
 * [2] $ php artisan db:seed --class=BantenprovNilaiSeederAkademik
9
 */
10
11
class BantenprovNilaiSeederAkademik extends Seeder
12
{
13
    /* text color */
14
    protected $RED     ="\033[0;31m";
15
    protected $CYAN    ="\033[0;36m";
16
    protected $YELLOW  ="\033[1;33m";
17
    protected $ORANGE  ="\033[0;33m";
18
    protected $PUR     ="\033[0;35m";
19
    protected $GRN     ="\e[32m";
20
    protected $WHI     ="\e[37m";
21
    protected $NC      ="\033[0m";
22
23
    /* File name */
24
    /* location : /databse/seeds/file_name.csv */
25
    protected $fileName = "BantenprovNilaiSeederAkademik.csv";
26
27
    /* text info : default (true) */
28
    protected $textInfo = true;
29
30
    /* model class */
31
    protected $model;
32
33
    /* __construct */
34
    public function __construct(){
35
36
        $this->model = new Bantenprov\Nilai\Models\Bantenprov\Nilai\Akademik;
37
38
    }
39
40
    /**
41
     * Run the database seeds.
42
     *
43
     * @return void
44
     */
45
    public function run()
46
    {
47
        $this->insertData();
48
    }
49
50
    /* function insert data */
51
    protected function insertData()
52
    {
53
        /* silahkan di rubah sesuai kebutuhan */
54
        foreach($this->readCSV() as $data){
55
56
            $this->model->create([
57
                'nomor_un' => $data['nomor_un'],
58
                'bahasa_indonesia' => $data['bahasa_indonesia'],
59
                'bahasa_inggris' => $data['bahasa_inggris'],
60
                'matematika' => $data['matematika'],
61
                'ipa' => $data['ipa'],
62
                'user_id' => $data['user_id'],
63
            ]);
64
65
            if($this->textInfo){
66
                echo "============[DATA]============\n";
67
                $this->orangeText('nomor_un : ').$this->greenText($data['nomor_un']);
68
                echo"\n";
69
                $this->orangeText('bahasa_indonesia : ').$this->greenText($data['bahasa_indonesia']);
70
                echo"\n";
71
                $this->orangeText('bahasa_inggris : ').$this->greenText($data['bahasa_inggris']);
72
                echo"\n";
73
                $this->orangeText('matematika : ').$this->greenText($data['matematika']);
74
                echo"\n";
75
                $this->orangeText('ipa : ').$this->greenText($data['ipa']);
76
                echo"\n";
77
                $this->orangeText('user_id : ').$this->greenText($data['user_id']);
78
                echo"\n";
79
                echo "============[DATA]============\n\n";
80
            }
81
82
        }
83
84
        $this->greenText('[ SEEDER DONE ]');
85
        echo"\n\n";
86
    }
87
88
    /* text color: orange */
89
    protected function orangeText($text)
90
    {
91
        printf($this->ORANGE.$text.$this->NC);
92
    }
93
94
    /* text color: green */
95
    protected function greenText($text)
96
    {
97
        printf($this->GRN.$text.$this->NC);
98
    }
99
100
    /* function read CSV file */
101
    protected function readCSV()
102
    {
103
        /* Silahkan di rubah sesuai struktur file csv */
104
        $file = fopen(database_path("seeds/".$this->fileName), "r");
105
        $all_data = array();
106
        $row = 1;
107
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){
108
            $all_data[] = [
109
                           'nomor_un' => $data[0],
110
                           'bahasa_indonesia' => $data[1],
111
                           'bahasa_inggris' => $data[2],
112
                           'matematika' => $data[3],
113
                           'ipa' => $data[4],
114
                           'user_id' => $data[5],
115
                        ];
116
        }
117
        fclose($file);
118
119
        return  $all_data;
120
    }
121
}
122

src/database/seeds/BantenprovNilaiSeederNilai.php 1 location

@@ 11-121 (lines=111) @@
8
 * [2] $ php artisan db:seed --class=BantenprovNilaiSeederNilai
9
 */
10
11
class BantenprovNilaiSeederNilai extends Seeder
12
{
13
    /* text color */
14
    protected $RED     ="\033[0;31m";
15
    protected $CYAN    ="\033[0;36m";
16
    protected $YELLOW  ="\033[1;33m";
17
    protected $ORANGE  ="\033[0;33m";
18
    protected $PUR     ="\033[0;35m";
19
    protected $GRN     ="\e[32m";
20
    protected $WHI     ="\e[37m";
21
    protected $NC      ="\033[0m";
22
23
    /* File name */
24
    /* location : /databse/seeds/file_name.csv */
25
    protected $fileName = "BantenprovNilaiSeederNilai.csv";
26
27
    /* text info : default (true) */
28
    protected $textInfo = true;
29
30
    /* model class */
31
    protected $model;
32
33
    /* __construct */
34
    public function __construct(){
35
36
        $this->model = new Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
37
38
    }
39
40
    /**
41
     * Run the database seeds.
42
     *
43
     * @return void
44
     */
45
    public function run()
46
    {
47
        $this->insertData();
48
    }
49
50
    /* function insert data */
51
    protected function insertData()
52
    {
53
        /* silahkan di rubah sesuai kebutuhan */
54
        foreach($this->readCSV() as $data){
55
56
            $this->model->create([
57
                'nomor_un' => $data['nomor_un'],
58
                'akademik' => $data['akademik'],
59
                'prestasi' => $data['prestasi'],
60
                'zona' => $data['zona'],
61
                'sktm' => $data['sktm'],
62
                'user_id' => $data['user_id'],
63
            ]);
64
65
            if($this->textInfo){
66
                echo "============[DATA]============\n";
67
                $this->orangeText('nomor_un : ').$this->greenText($data['nomor_un']);
68
                echo"\n";
69
                $this->orangeText('akademik : ').$this->greenText($data['akademik']);
70
                echo"\n";
71
                $this->orangeText('prestasi : ').$this->greenText($data['prestasi']);
72
                echo"\n";
73
                $this->orangeText('zona : ').$this->greenText($data['zona']);
74
                echo"\n";
75
                $this->orangeText('sktm : ').$this->greenText($data['sktm']);
76
                echo"\n";
77
                $this->orangeText('user_id : ').$this->greenText($data['user_id']);
78
                echo"\n";
79
                echo "============[DATA]============\n\n";
80
            }
81
82
        }
83
84
        $this->greenText('[ SEEDER DONE ]');
85
        echo"\n\n";
86
    }
87
88
    /* text color: orange */
89
    protected function orangeText($text)
90
    {
91
        printf($this->ORANGE.$text.$this->NC);
92
    }
93
94
    /* text color: green */
95
    protected function greenText($text)
96
    {
97
        printf($this->GRN.$text.$this->NC);
98
    }
99
100
    /* function read CSV file */
101
    protected function readCSV()
102
    {
103
        /* Silahkan di rubah sesuai struktur file csv */
104
        $file = fopen(database_path("seeds/".$this->fileName), "r");
105
        $all_data = array();
106
        $row = 1;
107
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){
108
            $all_data[] = [
109
                           'nomor_un' => $data[0],
110
                           'akademik' => $data[1],
111
                           'prestasi' => $data[2],
112
                           'zona' => $data[3],
113
                           'sktm' => $data[4],
114
                           'user_id' => $data[5],
115
                        ];
116
        }
117
        fclose($file);
118
119
        return  $all_data;
120
    }
121
}
122