Version 22.78.2: Mar 22, 2023 Code refactoring in attendance.

This commit is contained in:
acanas 2023-03-22 11:00:48 +01:00
parent 0d76ca2af1
commit 467c4bca9e
5 changed files with 65 additions and 68 deletions

View File

@ -2248,10 +2248,8 @@ int swad__getAttendanceEvents (struct soap *soap,
MYSQL_ROW row;
unsigned NumAttEvents;
unsigned NumAttEvent;
long AttCod;
struct Att_Event Event;
char PhotoURL[Cns_MAX_BYTES_WWW + 1];
long StartTime;
long EndTime;
size_t Length;
/***** Initializations *****/
@ -2308,16 +2306,13 @@ int swad__getAttendanceEvents (struct soap *soap,
/* Get next group */
row = mysql_fetch_row (mysql_res);
/* Get attendance event code (row[0]) */
AttCod = Str_ConvertStrCodToLongCod (row[0]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].attendanceEventCode = (int) AttCod;
/* Get attendance event (except Txt) */
Att_GetAttendanceEventFromRow (row,&Event);
/* Get whether the attendance event is hidden or not (row[1]) */
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].hidden = (row[1][0] == 'Y') ? 1 :
0;
/* Get user's code of the user who created the event (row[2]) */
Gbl.Usrs.Other.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[2]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].attendanceEventCode = (int) Event.AttCod;
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].hidden = Event.Hidden ? 1 :
0;
Gbl.Usrs.Other.UsrDat.UsrCod = Event.UsrCod;
if (API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Gbl.Hierarchy.Crs.CrsCod)) // Get some user's data from database
{
Length = strlen (Gbl.Usrs.Other.UsrDat.Surname1);
@ -2353,39 +2348,26 @@ int swad__getAttendanceEvents (struct soap *soap,
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userPhoto = NULL;
}
/* Get event start time (row[3]) */
StartTime = 0L;
if (row[3])
sscanf (row[3],"%ld",&StartTime);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].startTime = StartTime;
/* Get event end time (row[4]) */
EndTime = 0L;
if (row[4])
sscanf (row[4],"%ld",&EndTime);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].endTime = EndTime;
/* Get whether teachers comments are visible ('Y') or hidden ('N') (row[5]) */
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].commentsTeachersVisible = (row[5][0] == 'Y') ? 1 :
0;
/* Get title of the event (row[6]) */
Length = strlen (row[6]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].startTime = (int) Event.TimeUTC[Dat_STR_TIME];
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].endTime = (int) Event.TimeUTC[Dat_END_TIME];
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].commentsTeachersVisible = Event.Open ? 1 :
0;
Length = strlen (Event.Title);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].title =
soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].title,
row[6],Length);
Event.Title,Length);
/* Get Txt (row[7]) */
Length = strlen (row[7]);
/* Get Txt (row[9]) */
Length = strlen (row[9]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].text =
soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].text,
row[7],Length);
row[9],Length);
/* Get list of groups for this attendance event */
API_GetListGrpsInAttendanceEventFromDB (soap,
AttCod,
Event.AttCod,
&(getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].groups));
}
}

View File

@ -105,6 +105,7 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
Att_OrderNewestOldest_t OrderNewestOldest);
static void Att_GetDataOfAttEventByCodAndCheckCrs (struct Att_Event *Event);
static void Att_ResetAttendanceEvent (struct Att_Event *Event);
static void Att_FreeListAttEvents (struct Att_Events *Events);
static void Att_PutParAttCod (void *Events);
@ -745,28 +746,8 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event)
/* Get row */
row = mysql_fetch_row (mysql_res);
/* Get code of attendance event (row[0]) and code of course (row[1]) */
Event->AttCod = Str_ConvertStrCodToLongCod (row[0]);
Event->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get whether the attendance event is hidden or not (row[2]) */
Event->Hidden = (row[2][0] == 'Y');
/* Get author of the attendance event (row[3]) */
Event->UsrCod = Str_ConvertStrCodToLongCod (row[3]);
/* Get start date (row[4]) and end date (row[5]) in UTC time */
Event->TimeUTC[Dat_STR_TIME] = Dat_GetUNIXTimeFromStr (row[4]);
Event->TimeUTC[Dat_END_TIME] = Dat_GetUNIXTimeFromStr (row[5]);
/* Get whether the attendance event is open or closed (row(6)) */
Event->Open = (row[6][0] == '1');
/* Get whether the attendance event is visible or not (row[7]) */
Event->CommentTchVisible = (row[7][0] == 'Y');
/* Get the title of the attendance event (row[8]) */
Str_Copy (Event->Title,row[8],sizeof (Event->Title) - 1);
/* Get attendance event (except Txt) */
Att_GetAttendanceEventFromRow (row,Event);
}
/***** Free structure that stores the query result *****/
@ -793,8 +774,38 @@ static void Att_ResetAttendanceEvent (struct Att_Event *Event)
Event->TimeUTC[Dat_STR_TIME] =
Event->TimeUTC[Dat_END_TIME] = (time_t) 0;
Event->Open = false;
Event->Title[0] = '\0';
Event->CommentTchVisible = false;
Event->Title[0] = '\0';
}
/*****************************************************************************/
/************************* Get attendance event data *************************/
/*****************************************************************************/
void Att_GetAttendanceEventFromRow (MYSQL_ROW row,struct Att_Event *Event)
{
/***** Get code of attendance event (row[0]) and code of course (row[1]) *****/
Event->AttCod = Str_ConvertStrCodToLongCod (row[0]);
Event->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get whether the attendance event is hidden or not (row[2]) *****/
Event->Hidden = (row[2][0] == 'Y');
/***** Get author of the attendance event (row[3]) *****/
Event->UsrCod = Str_ConvertStrCodToLongCod (row[3]);
/***** Get start date (row[4]) and end date (row[5]) in UTC time *****/
Event->TimeUTC[Dat_STR_TIME] = Dat_GetUNIXTimeFromStr (row[4]);
Event->TimeUTC[Dat_END_TIME] = Dat_GetUNIXTimeFromStr (row[5]);
/***** Get whether the attendance event is open or closed (row(6)) *****/
Event->Open = (row[6][0] == '1');
/***** Get whether the attendance event is visible or not (row[7]) *****/
Event->CommentTchVisible = (row[7][0] == 'Y');
/***** Get the title of the attendance event (row[8]) *****/
Str_Copy (Event->Title,row[8],sizeof (Event->Title) - 1);
}
/*****************************************************************************/

View File

@ -55,8 +55,8 @@ struct Att_Event
long UsrCod;
time_t TimeUTC[Dat_NUM_START_END_TIME];
bool Open;
char Title[Att_MAX_BYTES_ATTENDANCE_EVENT_TITLE + 1];
bool CommentTchVisible;
char Title[Att_MAX_BYTES_ATTENDANCE_EVENT_TITLE + 1];
/* Field computed, not associated to the event in database */
unsigned NumStdsTotal; // Number total of students who have assisted to the event
@ -89,6 +89,7 @@ bool Att_CheckIfICanEditAttEvents (void);
void Att_ReqCreatOrEditAttEvent (void);
bool Att_GetDataOfAttEventByCod (struct Att_Event *Event);
void Att_GetAttendanceEventFromRow (MYSQL_ROW row,struct Att_Event *Event);
void Att_AskRemAttEvent (void);
void Att_GetAndRemAttEvent (void);

View File

@ -148,14 +148,16 @@ unsigned Att_DB_GetDataOfAllAttEvents (MYSQL_RES **mysql_res,long CrsCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get attendance events",
"SELECT AttCod," // row[0]
"Hidden," // row[1]
"UsrCod," // row[2]
"UNIX_TIMESTAMP(StartTime) AS ST," // row[3]
"UNIX_TIMESTAMP(EndTime) AS ET," // row[4]
"CommentTchVisible," // row[5]
"Title," // row[6]
"Txt" // row[7]
"SELECT AttCod," // row[0]
"CrsCod," // row[1]
"Hidden," // row[2]
"UsrCod," // row[3]
"UNIX_TIMESTAMP(StartTime) AS ST," // row[4]
"UNIX_TIMESTAMP(EndTime) AS ET," // row[5]
"NOW() BETWEEN StartTime AND EndTime," // row[6]
"CommentTchVisible," // row[7]
"Title," // row[8]
"Txt" // row[9]
" FROM att_events"
" WHERE CrsCod=%d"
" ORDER BY ST DESC,"

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.1 (2023-03-22)"
#define Log_PLATFORM_VERSION "SWAD 22.78.2 (2023-03-22)"
#define CSS_FILE "swad22.57.1.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.78.2: Mar 22, 2023 Code refactoring in attendance. (337779 lines)
Version 22.78.1: Mar 22, 2023 Code refactoring in exam sets and announcements. (337781 lines)
Version 22.78: Mar 22, 2023 New fields Source and Cod in rubric criteria. (337770 lines)
3 changes necessary in database: