76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?
|
|
$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;
|
|
}
|
|
}
|
|
}); |