|
@@ -5,7 +5,8 @@ class StudentTableSeeder extends Seeder {
|
5
|
5
|
public function run()
|
6
|
6
|
{
|
7
|
7
|
// Set term
|
8
|
|
- $term = "B91";
|
|
8
|
+ $term = "C12";
|
|
9
|
+ $semester_id = Semester::select('id')->where('code', $term)->first();
|
9
|
10
|
|
10
|
11
|
// Disable query logging to avoid memory exhaustion
|
11
|
12
|
DB::disableQueryLog();
|
|
@@ -14,10 +15,12 @@ class StudentTableSeeder extends Seeder {
|
14
|
15
|
|
15
|
16
|
// Initiates time
|
16
|
17
|
$time_start = microtime(true);
|
17
|
|
-
|
|
18
|
+/*
|
|
19
|
+ //Primero entra la informacion basica eg. numero_estu, nombre, email
|
18
|
20
|
// Open file
|
19
|
|
- $file_path = 'http://136.145.180.72/tools/proceso_files/';
|
20
|
|
- $file_name = 'webmatri_vivienda_b83-b91.dat';
|
|
21
|
+ $file_path = 'app/database/csv/';
|
|
22
|
+// $file_name = 'ARCEXTRT-20-C12-20220411-164329.TXT';
|
|
23
|
+ $file_name = 'ARCEXT-20-C12-20220411-164329.TXT';
|
21
|
24
|
|
22
|
25
|
if($file = fopen($file_path.$file_name, 'r'))
|
23
|
26
|
{
|
|
@@ -29,13 +32,13 @@ class StudentTableSeeder extends Seeder {
|
29
|
32
|
$warning = 0;
|
30
|
33
|
|
31
|
34
|
// Read each row
|
32
|
|
- while($data = fgetcsv($file, 5000, ";"))
|
|
35
|
+ while($data = fgetcsv($file, 0, ";"))
|
33
|
36
|
{
|
34
|
37
|
// Skip iterations from previous semesters
|
35
|
|
- if(trim($data[8]) != $term)
|
36
|
|
- {
|
37
|
|
- continue;
|
38
|
|
- }
|
|
38
|
+// if(trim($data[8]) != $term)
|
|
39
|
+// {
|
|
40
|
+// continue;
|
|
41
|
+// }
|
39
|
42
|
|
40
|
43
|
// Add read count
|
41
|
44
|
$read++;
|
|
@@ -43,11 +46,11 @@ class StudentTableSeeder extends Seeder {
|
43
|
46
|
try
|
44
|
47
|
{
|
45
|
48
|
// Get row info
|
46
|
|
- $number = str_pad(trim($data[1]), 9, '000000000', STR_PAD_LEFT);
|
47
|
|
- $name = trim(ucwords(strtoupper($data[2])));
|
48
|
|
- $email = trim($data[15]).'@upr.edu';
|
49
|
|
- $school_code = trim($data[5]);
|
50
|
|
- $conc_code = trim($data[7]);
|
|
49
|
+ $number = str_pad(trim($data[2]), 9, '000000000', STR_PAD_LEFT);
|
|
50
|
+ $name = trim(ucwords(strtoupper($data[4])));
|
|
51
|
+ $email = trim($data[5]).'@upr.edu';
|
|
52
|
+// $school_code = trim($data[5]);
|
|
53
|
+ $gender = trim($data[7]);
|
51
|
54
|
|
52
|
55
|
// If any row is empty, raise an exception
|
53
|
56
|
if(!$number || !$name)
|
|
@@ -78,12 +81,13 @@ class StudentTableSeeder extends Seeder {
|
78
|
81
|
array(
|
79
|
82
|
'name' => $name,
|
80
|
83
|
'email' => $email,
|
81
|
|
- 'school_code' => $school_code,
|
82
|
|
- 'conc_code' => $conc_code,
|
|
84
|
+ 'gender' => $gender,
|
|
85
|
+// 'school_code' => $school_code,
|
|
86
|
+// 'conc_code' => $conc_code,
|
83
|
87
|
'updated_at' => date("Y-m-d H:i:s"),
|
84
|
88
|
)
|
85
|
89
|
);
|
86
|
|
- $this->command->info($read.' - Updated '.$number.': '.$name.' ['.$school_code.' '.$conc_code.']');
|
|
90
|
+ $this->command->info($read.' - Updated '.$number.': '.$name.' ['.$gender.']');
|
87
|
91
|
$updated++;
|
88
|
92
|
|
89
|
93
|
}
|
|
@@ -95,8 +99,9 @@ class StudentTableSeeder extends Seeder {
|
95
|
99
|
'number' => $number,
|
96
|
100
|
'name' => $name,
|
97
|
101
|
'email' => $email,
|
98
|
|
- 'school_code' => $school_code,
|
99
|
|
- 'conc_code' => $conc_code,
|
|
102
|
+ 'gender' => $gender,
|
|
103
|
+// 'school_code' => $school_code,
|
|
104
|
+// 'conc_code' => $conc_code,
|
100
|
105
|
'created_at' => date("Y-m-d H:i:s"),
|
101
|
106
|
'updated_at' => date("Y-m-d H:i:s")
|
102
|
107
|
)
|
|
@@ -137,6 +142,138 @@ class StudentTableSeeder extends Seeder {
|
137
|
142
|
{
|
138
|
143
|
$this->command->info('File '.$file_name.' could not be opened. Make sure it is located in the app/database/csv directory of this project.');
|
139
|
144
|
}
|
|
145
|
+*/
|
|
146
|
+ // Segundo entra la informacion de programa, grado, nivel, anho y anhade en program_student_semester
|
|
147
|
+ $file_path = 'app/database/csv/';
|
|
148
|
+ $file_name = 'ARCEXTRT-20-C12-20220411-164329.TXT';
|
|
149
|
+// $file_name = 'ARCEXT-20-C12-20220411-164329.TXT';
|
|
150
|
+
|
|
151
|
+ if($file = fopen($file_path.$file_name, 'r'))
|
|
152
|
+ {
|
|
153
|
+ // Initialize count variables
|
|
154
|
+ $read = 0;
|
|
155
|
+ $added =0;
|
|
156
|
+ $updated = 0;
|
|
157
|
+ $error = 0;
|
|
158
|
+ $warning = 0;
|
|
159
|
+
|
|
160
|
+ // Read each row
|
|
161
|
+ while($data = fgetcsv($file, 0, ";"))
|
|
162
|
+ {
|
|
163
|
+ // Skip iterations from previous semesters
|
|
164
|
+// if(trim($data[8]) != $term)
|
|
165
|
+// {
|
|
166
|
+// continue;
|
|
167
|
+// }
|
|
168
|
+//
|
|
169
|
+ // Add read count
|
|
170
|
+ $read++;
|
|
171
|
+
|
|
172
|
+ try
|
|
173
|
+ {
|
|
174
|
+ // Get row info
|
|
175
|
+ $number = str_pad(trim($data[3]), 9, '000000000', STR_PAD_LEFT);
|
|
176
|
+// $name = trim(ucwords(strtoupper($data[4])));
|
|
177
|
+// $email = trim($data[5]).'@upr.edu';
|
|
178
|
+ $school_code = trim($data[19]);
|
|
179
|
+ $conc_code = trim($data[21]);
|
|
180
|
+ $level = trim($data[16]);
|
|
181
|
+ $degree = trim($data[23]);
|
|
182
|
+ $year = trim($data[25]);
|
|
183
|
+// $school_code = trim($data[5]);
|
|
184
|
+// $conc_code = trim($data[7]);
|
|
185
|
+
|
|
186
|
+ // If any row is empty, raise an exception
|
|
187
|
+ if(!$number)
|
|
188
|
+ {
|
|
189
|
+ throw new Exception('NON-FATAL ERROR(line '.$read.'): Missing name or student number, read \''.implode(",", $data).'\'');
|
|
190
|
+ }
|
|
191
|
+
|
|
192
|
+ $program=DB::table('programs')
|
|
193
|
+ ->where('code', $conc_code)
|
|
194
|
+ ->where('degree', $degree)
|
|
195
|
+ ->select('id')
|
|
196
|
+ ->first();
|
|
197
|
+// var_dump($program_id);
|
|
198
|
+ if(!$program)$program->id=null;
|
|
199
|
+ // Check if student exists
|
|
200
|
+ $student = Student::where('number', $number)->count();
|
|
201
|
+
|
|
202
|
+ // If s/he does, update information and add to updated
|
|
203
|
+ if($student)
|
|
204
|
+ {
|
|
205
|
+ $student_id = Student::select('id')->where('number', $number)->first();
|
|
206
|
+// print $read."\n";
|
|
207
|
+
|
|
208
|
+ DB::table('students')
|
|
209
|
+ ->where('number', $number)
|
|
210
|
+ ->update(
|
|
211
|
+ array(
|
|
212
|
+// 'name' => $name,
|
|
213
|
+// 'email' => $email,
|
|
214
|
+ 'school_code' => $school_code,
|
|
215
|
+ 'conc_code' => $conc_code,
|
|
216
|
+ 'program_id' => $program->id,
|
|
217
|
+ 'degree' => $degree,
|
|
218
|
+ 'level' => $level,
|
|
219
|
+ 'year' => $year,
|
|
220
|
+ 'updated_at' => date("Y-m-d H:i:s"),
|
|
221
|
+ )
|
|
222
|
+ );
|
|
223
|
+ $this->command->info($read.' - Updated '.$number.': '.$program->id.' ['.$school_code.' '.$conc_code.']');
|
|
224
|
+ $updated++;
|
|
225
|
+
|
|
226
|
+ DB::table('program_student_semester')->insert(
|
|
227
|
+ array('student_id' => $student_id->id,
|
|
228
|
+ 'program_id' => $program->id,
|
|
229
|
+ 'semester_id' => $semester_id->id
|
|
230
|
+ )
|
|
231
|
+ );
|
|
232
|
+
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ // Otherwise, add student and add to added
|
|
236
|
+ else
|
|
237
|
+ {
|
|
238
|
+ $this->command->info($read.' - Student not in system'.$number.': '.$name);
|
|
239
|
+ $warning++;
|
|
240
|
+ }
|
|
241
|
+
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ // If an exception is raised, show the message and add to error
|
|
245
|
+ catch(Exception $e)
|
|
246
|
+ {
|
|
247
|
+ $this->command->info($e->getMessage());
|
|
248
|
+ $error++;
|
|
249
|
+ };
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ // Stop time
|
|
253
|
+ $time_end = microtime(true);
|
|
254
|
+
|
|
255
|
+ // Display results
|
|
256
|
+ $this->command->info('------------------------------------------------------------');
|
|
257
|
+ $this->command->info('Results on '.date('M d, Y, h:i:s a'));
|
|
258
|
+ $this->command->info('- Runtime: '.(round($time_end - $time_start, 3)).' seconds');
|
|
259
|
+ $this->command->info('- Read: '.$read);
|
|
260
|
+ $this->command->info('- Updated (active): '.$updated);
|
|
261
|
+ $this->command->info('- Added (new active, all): '.$added);
|
|
262
|
+ $this->command->info('- Added (new active, without email): '.$warning);
|
|
263
|
+ $this->command->info('- Not updated (inactive): '.(Student::count() - $updated - $added));
|
|
264
|
+ $this->command->info('- Not added/updated (errors or missing information): '.($error));
|
|
265
|
+
|
|
266
|
+ // Close file
|
|
267
|
+ fclose($file);
|
|
268
|
+ }
|
|
269
|
+ // File cannot be opened, display error and exit
|
|
270
|
+ else
|
|
271
|
+ {
|
|
272
|
+ $this->command->info('File '.$file_name.' could not be opened. Make sure it is located in the app/database/csv directory of this project.');
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
140
|
277
|
}
|
141
|
278
|
|
142
|
279
|
}
|