Stable 2-ago-2023
This commit is contained in:
76
service/backend/carreras.php
Normal file
76
service/backend/carreras.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?
|
||||
$ruta = "../../";
|
||||
require_once "$ruta/include/bd_pdo.php";
|
||||
header('Content-Type: application/json');
|
||||
global $db;
|
||||
// json data from service\periodos.v1.php (input)
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
// check if the input is empty
|
||||
|
||||
if (is_response_empty($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No se recibieron datos',
|
||||
'data' => $data
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// check if data is array
|
||||
if (!is_array($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'La información recibida no es válida',
|
||||
'data' => $data
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* [{
|
||||
* carrera_nombre
|
||||
* carrera_clave
|
||||
* id_nivel
|
||||
* },]
|
||||
*/
|
||||
// check for this schema
|
||||
array_walk($data, function ($item) {
|
||||
if (!isset($item['ClaveCarrera']) || !isset($item['NombreCarrera']) || !isset($item['IdNivel'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Los datos recibidos no son validos',
|
||||
'data' => $item
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
array_walk($data, function ($item) use ($db) {
|
||||
|
||||
if ($db->where('carrera_nombre', "%{$item['NombreCarrera']}", 'ILIKE')->has('carrera'))
|
||||
$db
|
||||
->where('carrera_nombre', "%{$item['NombreCarrera']}", 'ILIKE')
|
||||
->update('carrera', [
|
||||
'carrera_nombre' => $item['NombreCarrera'],
|
||||
'id_referencia' => $item['ClaveCarrera'],
|
||||
]);
|
||||
else {
|
||||
try {
|
||||
$db->insert('carrera', [
|
||||
'carrera_nombre' => $item['NombreCarrera'],
|
||||
'id_referencia' => $item['ClaveCarrera'],
|
||||
'nivel_id' => $item['IdNivel'],
|
||||
]);
|
||||
} catch (PDOException $th) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
'last_query' => $db->getLastQuery(),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
});
|
||||
60
service/backend/periodos.php
Normal file
60
service/backend/periodos.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?
|
||||
$ruta = "../../";
|
||||
require_once "$ruta/include/bd_pdo.php";
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// json data from service\periodos.v1.php (input)
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
// check if the input is empty
|
||||
|
||||
if (is_response_empty($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No se recibieron datos',
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"IdNivel": 1,
|
||||
"IdPeriodo": 635,
|
||||
"NombreNivel": "LICENCIATURA",
|
||||
"NombrePeriodo": "241",
|
||||
"in_db": false
|
||||
inicio,
|
||||
fin
|
||||
}
|
||||
*/
|
||||
|
||||
// insert into database
|
||||
setlocale(LC_TIME, 'es_MX.UTF-8');
|
||||
$formatter = new IntlDateFormatter('es_MX', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Mexico_City', IntlDateFormatter::GREGORIAN, 'MMMM');
|
||||
$inicio = strtotime($data['inicio']);
|
||||
$fin = strtotime($data['fin']);
|
||||
try {
|
||||
|
||||
$result = $db->insert('periodo', [
|
||||
'id_reference' => $data['IdPeriodo'],
|
||||
'periodo_nombre' => "{$data['NombreNivel']}: {$formatter->format($inicio)} - {$formatter->format($fin)} " . date('Y', $inicio),
|
||||
'nivel_id' => $data['IdNivel'],
|
||||
'periodo_fecha_inicio' => $data['inicio'],
|
||||
'periodo_fecha_fin' => $data['fin'],
|
||||
'estado_id' => 4,
|
||||
'periodo_clave' => $data['NombrePeriodo']
|
||||
], ['id_reference']);
|
||||
} catch (PDOException $th) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $th->getMessage()
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
echo json_encode($result ? [
|
||||
'success' => true,
|
||||
'message' => 'Periodo agregado correctamente'
|
||||
] : [
|
||||
'success' => false,
|
||||
'message' => 'Error al agregar el periodo'
|
||||
]);
|
||||
Reference in New Issue
Block a user