/
CRUD.php
81 lines (70 loc) · 2.51 KB
/
CRUD.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
<?php
namespace dao\empresaDatabase;
include("clases/dao/empresaDatabase/autoload.php");
include("Parm/vendor/autoload.php");
use \Parm\Config;
Config::setupConnection("empresa","empresa","root","","localhost");
$type = isset($_POST["type"])?$_POST["type"]:null;
switch($type) {
case "C":echo ClienteCRUD::Create(new Cliente($_POST["nombres"],$_POST["ciudad"],$_POST["sexo"],$_POST["telefono"],$_POST["fechaNacimiento"]));break;
case "R":echo ClienteCRUD::Read(new Cliente($_POST["id"]));break;
case "U":echo ClienteCRUD::Update(new Cliente($_POST["id"],$_POST["nombres"],$_POST["ciudad"],$_POST["sexo"],$_POST["telefono"],$_POST["fechaNacimiento"]));break;
case "D":echo ClienteCRUD::Delete(new Cliente($_POST["id"]));break;
case null:echo ClienteCRUD::All();break;
}
class Cliente {
var $clienteDAO;
function __construct() {
$params = func_get_args();
$num_params = func_num_args();
$constructor ='__construct'.$num_params;
if (method_exists($this,$constructor)) {
call_user_func_array(array($this,$constructor),$params);
}
}
function __construct1($id) {
$this->clienteDAO = ClienteDaoObject::findId($id);
}
function __construct5($nombre,$ciudad,$sexo,$telefono,$fecha_nacimiento) {
$this->clienteDAO = new ClienteDaoObject();
$this->clienteDAO->setNombres($nombre);
$this->clienteDAO->setCiudad($ciudad);
$this->clienteDAO->setSexo($sexo);
$this->clienteDAO->setTelefono($telefono);
$this->clienteDAO->setFechaNacimiento($fecha_nacimiento);
}
function __construct6($id,$nombre,$ciudad,$sexo,$telefono,$fecha_nacimiento) {
$this->clienteDAO = ClienteDaoObject::findId($id);
$this->clienteDAO->setNombres($nombre);
$this->clienteDAO->setCiudad($ciudad);
$this->clienteDAO->setSexo($sexo);
$this->clienteDAO->setTelefono($telefono);
$this->clienteDAO->setFechaNacimiento($fecha_nacimiento);
}
function toJSON() {
$json_array = $this->clienteDAO->toJSON();
return json_encode($json_array,JSON_FORCE_OBJECT);
}
}
class ClienteCRUD{
public static function Create($cliente) {
$cliente->clienteDAO->save();
return $cliente->toJSON();
}
public static function Read($cliente) {
return $cliente->toJSON();
}
public static function Update($cliente) {
$cliente->clienteDAO->save();
return $cliente->toJSON();
}
public static function Delete($cliente) {
return $cliente->clienteDAO->delete();
}
public static function All() {
$clienteFacotry = new ClienteDaoFactory();
$coll = $clienteFacotry->getCollection();
return json_encode($coll->toJson(),JSON_FORCE_OBJECT);
}
}
?>