-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudents_controller_class.php
More file actions
63 lines (53 loc) · 1.84 KB
/
students_controller_class.php
File metadata and controls
63 lines (53 loc) · 1.84 KB
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
<?php
/**
* students_controller.php
* Implementa los servicios para realizar altas, bajas, modificaciones y lectura
* de datos de estudiantes
*/
require 'student_dao.php';
$requestMethod = $_SERVER['REQUEST_METHOD'];
class StudentsController {
private $studentDAO;
public function __construct() {
$this->studentDAO = new StudentDAO();
}
public function getStudents() {
return $this->studentDAO->findStudents();
}
public function getStudentById($id) {
return $this->studentDAO->findStudentById($id);
}
public function postStudentForm($form) {
$student = new Student(
$form['firstName'],
$form['lastName'],
$form['city'],
$form['semester']
);
return $this->studentDAO->save($student);
}
public function postStudent($jsonStudent) {
$studentArray = json_decode($jsonStudent, true);
$student = new Student(
$studentArray['firstName'],
$studentArray['lastName'],
$studentArray['city'],
$studentArray['semester']
);
return $this->studentDAO->save($student);
}
public function putStudent($jsonStudent) {
$studentArray = json_decode($jsonStudent, true);
$student = new Student(
$studentArray['firstName'],
$studentArray['lastName'],
$studentArray['city'],
$studentArray['semester'],
$studentArray['id']
);
return $this->studentDAO->update($student);
}
public function deleteStudent($id) {
return $this->studentDAO->delete($id);
}
}