Version 22.78.8: Mar 22, 2023 Code refactoring in holidays.

This commit is contained in:
acanas 2023-03-23 14:09:45 +01:00
parent f12f4a97e9
commit 8855c50300
3 changed files with 71 additions and 99 deletions

View File

@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr
TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen.
*/
#define Log_PLATFORM_VERSION "SWAD 22.78.7 (2023-03-23)"
#define Log_PLATFORM_VERSION "SWAD 22.78.8 (2023-03-23)"
#define CSS_FILE "swad22.57.1.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.78.8: Mar 22, 2023 Code refactoring in holidays. (337648 lines)
Version 22.78.7: Mar 22, 2023 Code refactoring in exam sets. (337671 lines)
Version 22.78.6: Mar 22, 2023 Code refactoring in departments. (337691 lines)
Version 22.78.5: Mar 22, 2023 Code refactoring in buildings. (337696 lines)

View File

@ -66,6 +66,8 @@ static void Hld_PutIconsSeeHolidays (__attribute__((unused)) void *Args);
static void Hld_EditHolidaysInternal (void);
static void Hld_GetHolidayDataByCod (struct Hld_Holiday *Hld);
static void Hld_GetHolidayDataFromRow (MYSQL_RES *mysql_res,
struct Hld_Holiday *Hld);
static Hld_HolidayType_t Hld_GetParHldType (void);
static Hld_HolidayType_t Hld_GetTypeOfHoliday (const char *UnsignedStr);
@ -312,9 +314,7 @@ static void Hld_EditHolidaysInternal (void)
void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumHld;
struct Hld_Holiday *Hld;
if (DB_CheckIfDatabaseIsOpen ())
{
@ -333,47 +333,7 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
for (NumHld = 0;
NumHld < Holidays->Num;
NumHld++)
{
Hld = &(Holidays->Lst[NumHld]);
/* Get next holiday */
row = mysql_fetch_row (mysql_res);
/* Get holiday code (row[0]) */
if ((Hld->HldCod = Str_ConvertStrCodToLongCod (row[0])) <= 0)
Err_WrongHolidayExit ();
/* Get place code (row[1]) */
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get the full name of the place (row[2]) */
Str_Copy (Hld->PlaceFullName,row[2],
sizeof (Hld->PlaceFullName) - 1);
/* Get type (row[3]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[3]);
/* Get start date (row[4] holds the start date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[4])))
Err_WrongDateExit ();
/* Set / get end date */
switch (Hld->HldTyp)
{
case Hld_HOLIDAY: // Only one day
/* Set end date = start date */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break;
case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[5] holds the end date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[5])))
Err_WrongDateExit ();
break;
}
/* Get the name of the holiday/non school period (row[6]) */
Str_Copy (Hld->Name,row[6],sizeof (Hld->Name) - 1);
}
Hld_GetHolidayDataFromRow (mysql_res,&(Holidays->Lst[NumHld]));
}
/***** Free structure that stores the query result *****/
@ -390,7 +350,6 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
static void Hld_GetHolidayDataByCod (struct Hld_Holiday *Hld)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
/***** Clear data *****/
Hld->PlcCod = -1L;
@ -406,50 +365,60 @@ static void Hld_GetHolidayDataByCod (struct Hld_Holiday *Hld)
/***** Get data of holiday from database *****/
if (Hld_DB_GetHolidayDataByCod (&mysql_res,Hld->HldCod)) // Holiday found...
Hld_GetHolidayDataFromRow (mysql_res,Hld);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/******************** Get holiday data from database row *********************/
/*****************************************************************************/
static void Hld_GetHolidayDataFromRow (MYSQL_RES *mysql_res,
struct Hld_Holiday *Hld)
{
MYSQL_ROW row;
/***** Get row *****/
row = mysql_fetch_row (mysql_res);
/*
row[0]: PlcCod
row[1]: Place
row[2]: HldTyp
row[3]: StartDate
row[4]: EndDate
row[5]: Name
*/
/***** Get place code (row[0]) *****/
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]);
/***** Get the full name of the place (row[1]) *****/
Str_Copy (Hld->PlaceFullName,row[1],sizeof (Hld->PlaceFullName) - 1);
/***** Get type (row[2]) *****/
Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]);
/***** Get start date (row[3] holds the date in YYYYMMDD format) *****/
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[3])))
Err_WrongDateExit ();
/***** Set / get end date *****/
switch (Hld->HldTyp)
{
/* Get row */
row = mysql_fetch_row (mysql_res);
/*
row[0]: PlcCod
row[1]: Place
row[2]: HldTyp
row[3]: StartDate
row[4]: EndDate
row[5]: Name
*/
/* Get place code (row[0]) */
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get the full name of the place (row[1]) */
Str_Copy (Hld->PlaceFullName,row[1],sizeof (Hld->PlaceFullName) - 1);
/* Get type (row[2]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]);
/* Get start date (row[3] holds the start date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->StartDate),row[3])))
Err_WrongDateExit ();
/* Set / get end date */
switch (Hld->HldTyp)
{
case Hld_HOLIDAY: // Only one day
/* Assign end date = start date */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break;
case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[4] holds the end date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[4])))
Err_WrongDateExit ();
break;
}
/* Get the name of the holiday/non school period (row[5]) */
Str_Copy (Hld->Name,row[5],sizeof (Hld->Name) - 1);
case Hld_HOLIDAY: // Only one day
/* Assign end date = start date */
Dat_AssignDate (&Hld->EndDate,&Hld->StartDate);
break;
case Hld_NON_SCHOOL_PERIOD: // One or more days
/* Get end date (row[4] holds the date in YYYYMMDD format) */
if (!(Dat_GetDateFromYYYYMMDD (&(Hld->EndDate),row[4])))
Err_WrongDateExit ();
break;
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
/***** Get the name of the holiday/non school period (row[5]) *****/
Str_Copy (Hld->Name,row[5],sizeof (Hld->Name) - 1);
}
/*****************************************************************************/

View File

@ -152,7 +152,7 @@ unsigned Hld_DB_GetListHolidays (MYSQL_RES **mysql_res,Hld_Order_t SelectedOrder
"PlcCod," // row[1]
"'' as Place," // row[2]
"HldTyp," // row[3]
"DATE_FORMAT(StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
"DATE_FORMAT(StartDate,'%%Y%%m%%d') AS StartDate," // row[4]
"DATE_FORMAT(EndDate,'%%Y%%m%%d') AS EndDate," // row[5]
"Name" // row[6]
" FROM hld_holidays"
@ -178,12 +178,13 @@ unsigned Hld_DB_GetHolidayDataByCod (MYSQL_RES **mysql_res,long HldCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of a holiday",
"(SELECT hld_holidays.PlcCod," // row[0]
"plc_places.FullName as Place," // row[1]
"hld_holidays.HldTyp," // row[2]
"DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d')," // row[3]
"DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d')," // row[4]
"hld_holidays.Name" // row[5]
"(SELECT hld_holidays.HldCod," // row[0]
"hld_holidays.PlcCod," // row[1]
"plc_places.FullName as Place," // row[2]
"hld_holidays.HldTyp," // row[3]
"DATE_FORMAT(hld_holidays.StartDate,'%%Y%%m%%d')," // row[4]
"DATE_FORMAT(hld_holidays.EndDate,'%%Y%%m%%d')," // row[5]
"hld_holidays.Name" // row[6]
" FROM hld_holidays,"
"plc_places"
" WHERE hld_holidays.HldCod=%ld"
@ -191,12 +192,13 @@ unsigned Hld_DB_GetHolidayDataByCod (MYSQL_RES **mysql_res,long HldCod)
" AND hld_holidays.PlcCod=plc_places.PlcCod"
" AND plc_places.InsCod=%ld)"
" UNION "
"(SELECT PlcCod,"
"'' as Place,"
"HldTyp,"
"DATE_FORMAT(StartDate,'%%Y%%m%%d'),"
"DATE_FORMAT(EndDate,'%%Y%%m%%d'),"
"Name"
"(SELECT HldCod," // row[0]
"PlcCod," // row[1]
"'' as Place," // row[2]
"HldTyp," // row[3]
"DATE_FORMAT(StartDate,'%%Y%%m%%d')," // row[4]
"DATE_FORMAT(EndDate,'%%Y%%m%%d')," // row[5]
"Name" // row[6]
" FROM hld_holidays"
" WHERE HldCod=%ld"
" AND InsCod=%ld"