-
Notifications
You must be signed in to change notification settings - Fork 55
/
MeasureSeeder.php
55 lines (47 loc) · 1.53 KB
/
MeasureSeeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Database\Seeders;
use App\Models\Measure;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class MeasureSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('measures')->delete();
// get language
$lang = env('LANG', 1);
// get filename
if (strtolower($lang)==="fr")
$filename="database/data/measures.fr.csv";
else
$filename="database/data/measures.en.csv";
// Open CSV file
$csvFile = fopen(base_path($filename), "r");
// Loop on each line
$firstline = true;
while (($data = fgetcsv($csvFile, 8000, ",")) !== FALSE) {
\Log::Debug($data);
if (!$firstline) {
Measure::create([
"domain_id" => $data['0'],
"clause" => $data['1'],
"name" => $data['2'],
"objective" => str_replace("\\n","\n",$data['3']),
"attributes" => str_replace("\\n","\n",$data['4']),
"input" => str_replace("\\n","\n",$data['5']),
"model" => str_replace("\\n","\n",$data['6']),
"indicator" => str_replace("\\n","\n",$data['7']),
"action_plan" => str_replace("\\n","\n",$data['8']),
"created_at" => now()
]);
}
$firstline = false;
}
fclose($csvFile);
}
}