-
Notifications
You must be signed in to change notification settings - Fork 0
/
Horarios.class.php
106 lines (89 loc) · 3.66 KB
/
Horarios.class.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
class Horarios {
private $dom;
private $html;
private $horarios;
private $disciplinas;
public function __construct($html) {
$this->html = $html;
$this->dom = new DOMDocument();
@$this->dom->loadHTML($this->html);
$this->parse();
}
public function toJson() {
$arr = array(
'disciplinas' => $this->disciplinas,
'horarios' => $this->horarios,
);
return json_encode($arr);
}
private function parse() {
$this->parseDisciplinas();
$this->parseHorarios();
}
private function parseDisciplinas() {
$INDEX_TABELA_DISCIPLINAS = 3;
$table = $this->dom->getElementsByTagName('table')->item($INDEX_TABELA_DISCIPLINAS);
for($i = 1; $i < $table->getElementsByTagName('tr')->length - 1; $i++) {
$tr = $table->getElementsByTagName('tr')->item($i);
$codigo = $tr->getElementsByTagName('td')->item(0)->getElementsByTagName('font')->item(0)->nodeValue;
$nome = $tr->getElementsByTagName('td')->item(0)->getElementsByTagName('font')->item(1)->nodeValue;
$creditos = $tr->getElementsByTagName('td')->item(2)->nodeValue;
$pratica = $tr->getElementsByTagName('td')->item(3)->nodeValue;
$teorica = $tr->getElementsByTagName('td')->item(4)->nodeValue;
$this->disciplinas[] = array(
'codigo' => $codigo,
'nome' => $nome,
'creditos' => $creditos,
'turma' => array(
'pratica' => $pratica,
'teorica' => $teorica
)
);
}
//var_dump($this->disciplinas);
}
private function parseHorarios() {
$INDEX_TABELA_HORARIOS = 5;
$PRIMEIRO_TR_HORARIOS = 1;
$INDEX_TD_HORA = 0;
$INDEX_TD_SEGUNDA = 1;
$INDEX_TD_TERCA = 2;
$INDEX_TD_QUARTA = 3;
$INDEX_TD_QUINTA = 4;
$INDEX_TD_SEXTA = 5;
$INDEX_TD_SABADO = 6;
$table = $this->dom->getElementsByTagName('table')->item($INDEX_TABELA_HORARIOS);
for($i = $PRIMEIRO_TR_HORARIOS; $i < $table->getElementsByTagName('tr')->length; $i++) {
$tr = $table->getElementsByTagName('tr')->item($i);
$this->horarios[] = array(
'hora' => $tr->getElementsByTagName('td')->item($INDEX_TD_HORA)->nodeValue,
'segunda' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_SEGUNDA)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_SEGUNDA)->getElementsByTagName('font')->item(1)->nodeValue,
),
'terca' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_TERCA)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_TERCA)->getElementsByTagName('font')->item(1)->nodeValue,
),
'quarta' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_QUARTA)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_QUARTA)->getElementsByTagName('font')->item(1)->nodeValue,
),
'quinta' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_QUINTA)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_QUINTA)->getElementsByTagName('font')->item(1)->nodeValue,
),
'sexta' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_SEXTA)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_SEXTA)->getElementsByTagName('font')->item(1)->nodeValue,
),
'sabado' => array(
'codigo' => $tr->getElementsByTagName('td')->item($INDEX_TD_SABADO)->getElementsByTagName('font')->item(0)->nodeValue,
'sala' => $tr->getElementsByTagName('td')->item($INDEX_TD_SABADO)->getElementsByTagName('font')->item(1)->nodeValue
)
);
}
}
}
?>