-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendanceFileParser.php
48 lines (33 loc) · 1.37 KB
/
attendanceFileParser.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
<?php
require_once __DIR__ . '/models/student.php';
require_once __DIR__ . '/models/lectureportion.php';
function readLecturePortion(String $file){
$txt_file = file_get_contents($file);
$rows = explode("\n", $txt_file);
$date;
$students = [];
foreach($rows as $row => $data)
{
if($row == 0){
$row_data = explode(' ', $data);
$dateData = $row_data[count($row_data) - 2];
$dateData = preg_split( "/[:\/]/", $dateData );
$dateString = strval($dateData[2])."/".strval($dateData[0])."/".strval($dateData[1])." ".strval($dateData[3]).":".strval($dateData[4]).":".strval($dateData[5]);
$date = new DateTime($dateString);
}else{
if(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $data) === "Sorted by last name:"){
break;
}
$row_data = explode(' ', $data);
if (sizeof($row_data)===2){
$firstName = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $row_data[0]);
$lastName = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $row_data[1]);
$student = new Student(0, $firstName,$lastName);
$students[] = $student;
}
}
}
$newLecturePortion = [$students,$date];
return $newLecturePortion;
}
?>