Improve PHP formatting

This commit is contained in:
coolneng 2020-07-16 03:19:08 +02:00
parent 6bc9db9117
commit b0238cc9b0
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
7 changed files with 83 additions and 61 deletions

View File

@ -1,7 +1,8 @@
<?php
include 'appointment_management.php';
function computeEndTime(&$data){
function computeEndTime(&$data)
{
foreach ($data as &$row) {
$time = new DateTime($row["hora"]);
$time->modify("+{$row["duracion"]} minutes");
@ -11,7 +12,8 @@ function computeEndTime(&$data){
}
function formatArray($data){
function formatArray($data)
{
computeEndTime($data);
$events = array();
foreach ($data as $row) {
@ -28,7 +30,8 @@ function formatArray($data){
return $events;
}
function fetchDatabase(){
function fetchDatabase()
{
$pdo = connectDatabase();
$data = listEvents($pdo);
closeDatabase($pdo);
@ -39,5 +42,3 @@ function fetchDatabase(){
$result = fetchDatabase();
$events = formatArray($result);
echo json_encode($events);
?>

View File

@ -3,7 +3,8 @@ include'database.php';
session_start();
function fetchDoctor($pdo){
function fetchDoctor($pdo)
{
if ($_SESSION["user_type"] == 2) {
$user = finduser($pdo, $_SESSION["user"]);
return $user[0][4];
@ -12,28 +13,32 @@ function fetchDoctor($pdo){
}
function listEvents($pdo){
function listEvents($pdo)
{
$doctor = fetchDoctor($pdo);
$events = fetchCalendarEvents($pdo, $doctor);
return $events;
}
function listHolidays($pdo){
function listHolidays($pdo)
{
$doctor = fetchDoctor($pdo);
$holidays = fetchDoctorHolidays($pdo, $doctor);
return $holidays;
}
function listCalendarSettings($pdo){
function listCalendarSettings($pdo)
{
$doctor = fetchDoctor($pdo);
$calendar_settings = fetchCalendarSettings($pdo, $doctor);
return $calendar_settings;
}
function appointmentCreation(){
function appointmentCreation()
{
$data = $_POST;
$pdo = connectDatabase();
createAppointment($pdo, $data);
@ -42,7 +47,8 @@ function appointmentCreation(){
}
function appointmentModification(){
function appointmentModification()
{
$data = $_POST;
$pdo = connectDatabase();
editAppointment($pdo, $data);
@ -51,7 +57,8 @@ function appointmentModification(){
}
function appointmentDeletion(){
function appointmentDeletion()
{
$id = $_POST["event_id"];
$pdo = connectDatabase();
deleteAppointment($pdo, $id);
@ -60,7 +67,8 @@ function appointmentDeletion(){
}
function getFloorCeiling($pdo){
function getFloorCeiling($pdo)
{
$data = listCalendarSettings($pdo);
if ($data["horario"] == "completo") {
$start = $data["hora_inicio_mañana"];
@ -80,7 +88,8 @@ function getFloorCeiling($pdo){
}
function getTimeDiff(){
function getTimeDiff()
{
$current = time();
$addTime = strtotime("+30 mins", $current);
$diff = $addTime - $current;
@ -88,7 +97,8 @@ function getTimeDiff(){
}
function computeTimeRanges($pdo){
function computeTimeRanges($pdo)
{
$range = getFloorCeiling($pdo);
$diff = getTimeDiff();
$start = strtotime($range["start"]);

View File

@ -30,7 +30,8 @@ function holidayDeletion()
}
function setWorkingHours(&$data){
function setWorkingHours(&$data)
{
if (isset($data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"], $data["hora_fin_tarde"])) {
$data["horario"] = "completo";
} elseif (isset($data["hora_inicio_mañana"], $data["hora_fin_mañana"])) {
@ -41,7 +42,8 @@ function setWorkingHours(&$data){
}
function setUncheckedBoxes(&$data){
function setUncheckedBoxes(&$data)
{
if (!isset($data["sabado_habil"])) {
$data["sabado_habil"] = 0;
}
@ -51,7 +53,8 @@ function setUncheckedBoxes(&$data){
}
function sanitizeInputs(&$data){
function sanitizeInputs(&$data)
{
setWorkingHours($data);
setUncheckedBoxes($data);
}

View File

@ -2,7 +2,8 @@
include 'appointment_management.php';
function formatArray($data){
function formatArray($data)
{
$settings = array();
if (!$data["sabado_habil"]) {
array_push($settings, 6);
@ -13,7 +14,8 @@ function formatArray($data){
return $settings;
}
function fetchDatabase(){
function fetchDatabase()
{
$pdo = connectDatabase();
$data = listCalendarSettings($pdo);
closeDatabase($pdo);
@ -24,5 +26,3 @@ function fetchDatabase(){
$result = fetchDatabase();
$events = formatArray($result);
echo json_encode($events);
?>

View File

@ -23,7 +23,8 @@ function listRows($pdo, $table)
return $result;
}
function fetchLatestRegion($pdo){
function fetchLatestRegion($pdo)
{
$query = "SELECT id_provincia FROM provincias ORDER BY id_provincia DESC LIMIT 1;";
$result = $pdo->prepare($query);
$result->execute();
@ -31,7 +32,8 @@ function fetchLatestRegion($pdo){
return $data;
}
function fetchLatestCity($pdo){
function fetchLatestCity($pdo)
{
$query = "SELECT id_municipio FROM municipios ORDER BY id_municipio DESC LIMIT 1;";
$result = $pdo->prepare($query);
$result->execute();
@ -39,7 +41,8 @@ function fetchLatestCity($pdo){
return $data;
}
function createRegion($pdo, $data){
function createRegion($pdo, $data)
{
$query = "INSERT INTO provincias (id_provincia, provincia) VALUES (?,?)";
$row = fetchLatestRegion($pdo);
$last_region = $row["id_provincia"];
@ -48,7 +51,8 @@ function createRegion($pdo, $data){
return $index;
}
function createCity($pdo, $data, $region){
function createCity($pdo, $data, $region)
{
$query = "INSERT INTO municipios (id_provincia, cod_municipio, DC, nombre) VALUES (?,?,?,?)";
$pdo->prepare($query)->execute([$region, 999, 999, $data["localidad2"]]);
$city = fetchLatestCity($pdo);
@ -407,7 +411,8 @@ function fetchDoctorHolidays($pdo, $doctor)
}
function createAppointment($pdo, $data){
function createAppointment($pdo, $data)
{
$query = "INSERT INTO cita (fecha, hora, duracion, medico, observaciones, paciente) VALUES (?,?,?,?,?,?)";
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"],
$data["doctor"], $data["observaciones"], $data["paciente"]]);
@ -415,7 +420,8 @@ function createAppointment($pdo, $data){
}
function editAppointment($pdo, $data){
function editAppointment($pdo, $data)
{
$query = "UPDATE cita SET fecha=?, hora=?, duracion=?, observaciones=?, paciente=?
WHERE id=?";
$pdo->prepare($query)->execute([$data["fecha"], $data["hora"], $data["duracion"],
@ -424,14 +430,16 @@ function editAppointment($pdo, $data){
}
function deleteAppointment($pdo, $id){
function deleteAppointment($pdo, $id)
{
$statement = "DELETE FROM cita WHERE id=?";
$pdo->prepare($statement)->execute([$id]);
return "Cita borrada con éxito";
}
function fetchAppointmentData($pdo, $id){
function fetchAppointmentData($pdo, $id)
{
$query = "SELECT id, fecha, hora, duracion, observaciones FROM cita WHERE id=?";
$result = $pdo->prepare($query);
$result->execute([$id]);

View File

@ -2,7 +2,8 @@
include 'appointment_management.php';
function formatArray($data){
function formatArray($data)
{
$events = array();
foreach ($data as $row) {
$events[] = array(
@ -17,7 +18,8 @@ function formatArray($data){
return $events;
}
function fetchDatabase(){
function fetchDatabase()
{
$pdo = connectDatabase();
$data = listHolidays($pdo);
closeDatabase($pdo);
@ -28,5 +30,3 @@ function fetchDatabase(){
$result = fetchDatabase();
$events = formatArray($result);
echo json_encode($events);
?>