1: <?php
2: class PlnRegistro
3: {
4: function __construct($libs=null)
5: {
6: if(empty($libs)){
7: require_once('../core/incluir.php');
8: $nivel_dir = 3;
9: $this->libs = new Incluir($nivel_dir);
10: }
11: else{
12: $this->libs = $libs;
13: }
14: $this->bd = $this->libs->incluir('db');
15: }
16:
17: 18: 19: 20: 21: 22:
23: public function abrir_registro($arr_filtro, $dependientes=false)
24: {
25: $respuesta = array();
26: $query = "select * from pln_registro ";
27: if(is_array($arr_filtro)){
28: $query .= " where 1=1 ";
29: foreach ($arr_filtro as $key => $filtro) {
30: $query .= " and ".$key."=".$filtro;
31: }
32: }
33: $stmt = $this->bd->ejecutar($query);
34: while ($registro = $this->bd->obtener_fila($stmt)) {
35: $registro['arr_funsepa'] = ($dependientes ? $this->abrir_contenido_funsepa(array('id_registro'=> $registro['_id']), 'id_funsepa') : null );
36: $registro['arr_metodo'] = ($dependientes ? $this->abrir_metodo(array('id_registro'=> $registro['_id']), 'id_metodo') : null );
37: array_push($respuesta, $registro);
38: }
39: return $respuesta;
40: }
41:
42: 43: 44: 45: 46:
47: public function abrir_contenido_funsepa($arr_filtro, $campos='*')
48: {
49: $respuesta = array();
50: $query = "select ".$campos." from pln_contenido_funsepa ";
51: if(is_array($arr_filtro)){
52: $query .= " where _id>0 ";
53: foreach ($arr_filtro as $key => $filtro) {
54: $query .= " and ".$key."=".$filtro;
55: }
56: }
57: $stmt = $this->bd->ejecutar($query);
58: while ($funsepa = $this->bd->obtener_fila($stmt)) {
59: array_push($respuesta, $funsepa);
60: }
61:
62:
63: return $respuesta;
64: }
65:
66: 67: 68: 69: 70: 71:
72: public function abrir_metodo($arr_filtro, $campos='*')
73: {
74: $respuesta = array();
75: $query = "select ".$campos." from pln_metodo ";
76: if(is_array($arr_filtro)){
77: $query .= " where _id>0 ";
78: foreach ($arr_filtro as $key => $filtro) {
79: $query .= " and ".$key."=".$filtro;
80: }
81: }
82: $stmt = $this->bd->ejecutar($query);
83: while ($metodo = $this->bd->obtener_fila($stmt)) {
84: array_push($respuesta, $metodo);
85: }
86:
87:
88: return $respuesta;
89: }
90:
91: 92: 93: 94: 95: 96:
97: public function actualizar_metodo($id_registro, $arr_metodo)
98: {
99: $this->libs->incluir_clase('app/src/model/PlnMetodo.class.php');
100: $pln_metodo = new PlnMetodo($this->libs);
101: $pln_metodo->eliminar_pln_metodo('id_registro', $id_registro);
102: $crear = $pln_metodo->crear_pln_metodo($id_registro, $arr_metodo);
103: return $crear['arr_id'];
104: }
105:
106: 107: 108: 109: 110: 111:
112: public function actualizar_funsepa($id_registro, $arr_funsepa)
113: {
114: $this->libs->incluir_clase('app/src/model/PlnContenidoFunsepa.class.php');
115: $pln_funsepa = new PlnContenidoFunsepa($this->libs);
116: $pln_funsepa->eliminar_pln_funsepa('id_registro', $id_registro);
117: $crear = $pln_funsepa->crear_pln_funsepa($id_registro, $arr_funsepa);
118: return $crear['arr_id'];
119: }
120:
121: 122: 123: 124: 125:
126: public function crear_registro(Array $args)
127: {
128: $respuesta = array();
129: $respuesta['msj'] = 'no';
130: $this->libs->incluir_clase('app/src/model/PlnContenidoFunsepa.class.php');
131: $this->libs->incluir_clase('app/src/model/PlnMetodo.class.php');
132:
133: $pln_contenido_funsepa = new PlnContenidoFunsepa($this->libs);
134: $pln_metodo = new PlnMetodo($this->libs);
135:
136: $actividad = $this->bd->escapar_string($args['n_actividad']);
137: $recursos = $this->bd->escapar_string($args['n_recursos']);
138: $query = "insert into pln_registro (id_plan, id_contenido, fecha, actividad, recurso) values ('".$args['id_plan']."', '".$args['n_contenido']."', '".implode("-",array_reverse(explode("/",$args['n_fecha'])))."', '".$actividad."', '".$recursos."')";
139: if($this->bd->ejecutar($query, true)){
140: $id_registro = $this->bd->lastID();
141:
142: !empty($args['n_funsepa']) ? $pln_contenido_funsepa->crear_pln_funsepa($id_registro, $args['n_funsepa']) : '';
143: !empty($args['n_metodo']) ? $pln_metodo->crear_pln_metodo($id_registro, $args['n_metodo']) : '';
144:
145: $respuesta['msj'] = 'si';
146: $respuesta['_id'] = $id_registro;
147: }
148: return $respuesta;
149: }
150:
151: 152: 153: 154: 155:
156: public function borrar_registro($id_registro)
157: {
158: $respuesta = array('msj' => 'no');
159: $query = 'delete from pln_registro where _id='.$id_registro;
160: if($this->bd->ejecutar($query)){
161: $respuesta['msj'] = 'si';
162: }
163: return $respuesta;
164: }
165:
166: public function editar_registro($id_registro, $campo, $value='')
167: {
168: $value = $this->bd->escapar_string($value);
169: $query = "update pln_registro set ".$campo."='".$value."' where _id=".$id_registro;
170: if($this->bd->ejecutar($query, true)){
171: return true;
172: }
173: }
174: }
175: ?>