From 54bec4644d9b3c9a70883eddec7fe1e9861fc453 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 23 Mar 2023 19:31:53 +0100 Subject: [PATCH] Version 22.78.13: Mar 23, 2023 Code refactoring in rooms. --- swad_changelog.h | 3 +- swad_exam_set.c | 2 +- swad_game.c | 2 +- swad_match.c | 2 +- swad_program_database.c | 2 +- swad_program_resource.c | 20 +++---- swad_question.c | 12 ++-- swad_question.h | 2 +- swad_question_database.c | 2 +- swad_question_database.h | 2 +- swad_question_import.c | 2 +- swad_report.c | 2 +- swad_room.c | 120 +++++++++++++++++---------------------- swad_room_database.c | 15 ++--- swad_test_print.c | 6 +- 15 files changed, 90 insertions(+), 104 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index b6134796..bad8079c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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.12 (2023-03-23)" +#define Log_PLATFORM_VERSION "SWAD 22.78.13 (2023-03-23)" #define CSS_FILE "swad22.57.1.css" #define JS_FILE "swad22.49.js" /* + Version 22.78.13: Mar 23, 2023 Code refactoring in rooms. (337641 lines) Version 22.78.12: Mar 23, 2023 Code refactoring in plugins. (337651 lines) Version 22.78.11: Mar 23, 2023 Code refactoring in places. (337652 lines) Version 22.78.10: Mar 23, 2023 Code refactoring in notices. (337650 lines) diff --git a/swad_exam_set.c b/swad_exam_set.c index c78d50fc..09f5fa97 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -1245,7 +1245,7 @@ static void ExaSet_CopyQstFromBankToExamSet (const struct ExaSet_Set *Set,long Q Question.QstCod = QstCod; /***** Get data of question from database *****/ - if (Qst_GetQstDataFromDB (&Question)) + if (Qst_GetQstDataByCod (&Question)) { /***** Clone media *****/ CloneMedCod = Med_CloneMedia (&Question.Media); diff --git a/swad_game.c b/swad_game.c index f70ca773..fe1633d2 100644 --- a/swad_game.c +++ b/swad_game.c @@ -1756,7 +1756,7 @@ static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games, HTM_TD_End (); /***** Question *****/ - QuestionExists = Qst_GetQstDataFromDB (&Question); + QuestionExists = Qst_GetQstDataByCod (&Question); Qst_ListQuestionForEdition (&Question,QstInd,QuestionExists,Anchor); /***** End row *****/ diff --git a/swad_match.c b/swad_match.c index 147d888b..c8c8f559 100644 --- a/swad_match.c +++ b/swad_match.c @@ -2789,7 +2789,7 @@ static void Mch_ShowQuestionAndAnswersTch (const struct Mch_Match *Match) } /***** Get data of question from database *****/ - if (Qst_GetQstDataFromDB (&Question)) + if (Qst_GetQstDataByCod (&Question)) { /***** Show question *****/ /* Check answer type */ diff --git a/swad_program_database.c b/swad_program_database.c index 65aaa88a..cd402782 100644 --- a/swad_program_database.c +++ b/swad_program_database.c @@ -225,7 +225,7 @@ unsigned Prg_DB_GetListItems (MYSQL_RES **mysql_res) "Hidden" // row[3] " FROM prg_items" " WHERE CrsCod=%ld" - "%s" + "%s" " ORDER BY ItmInd", Gbl.Hierarchy.Crs.CrsCod, HiddenSubQuery[Gbl.Usrs.Me.Role.Logged]); diff --git a/swad_program_resource.c b/swad_program_resource.c index a49931c7..69f00850 100644 --- a/swad_program_resource.c +++ b/swad_program_resource.c @@ -374,8 +374,7 @@ static void PrgRsc_GetResourceDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get data of item resource from database *****/ - /* Get row */ + /***** Get row *****/ row = mysql_fetch_row (mysql_res); /* ItmCod row[0] @@ -386,21 +385,21 @@ static void PrgRsc_GetResourceDataFromRow (MYSQL_RES *mysql_res, Cod row[5] Title row[6] */ - /* Get code of the program item (row[0]) */ + /***** Get code of the program item (row[0]) *****/ Item->Hierarchy.ItmCod = Str_ConvertStrCodToLongCod (row[0]); - /* Get code and index of the item resource (row[1], row[2]) */ + /***** Get code and index of the item resource (row[1], row[2]) *****/ Item->Resource.Hierarchy.RscCod = Str_ConvertStrCodToLongCod (row[1]); Item->Resource.Hierarchy.RscInd = Str_ConvertStrToUnsigned (row[2]); - /* Get whether the program item is hidden (row(3)) */ + /***** Get whether the program item is hidden (row(3)) *****/ Item->Resource.Hierarchy.Hidden = (row[3][0] == 'Y'); - /* Get link type and code (row[4], row[5]) */ + /***** Get link type and code (row[4], row[5]) *****/ Item->Resource.Link.Type = PrgRsc_GetTypeFromString (row[4]); Item->Resource.Link.Cod = Str_ConvertStrCodToLongCod (row[5]); - /* Get the title of the item resource (row[6]) */ + /***** Get the title of the item resource (row[6]) *****/ Str_Copy (Item->Resource.Title,row[6],sizeof (Item->Resource.Title) - 1); } @@ -1122,17 +1121,16 @@ static void PrgRsc_GetLinkDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get data of item resource from database *****/ - /* Get row */ + /***** Get row *****/ row = mysql_fetch_row (mysql_res); /* Type row[0] Cod row[1] */ - /* Get type (row[0]) */ + /***** Get type (row[0]) *****/ Link->Type = PrgRsc_GetTypeFromString (row[0]); - /* Get code (row[1]) */ + /***** Get code (row[1]) *****/ Link->Cod = Str_ConvertStrCodToLongCod (row[1]); } diff --git a/swad_question.c b/swad_question.c index 45ede390..40a85de7 100644 --- a/swad_question.c +++ b/swad_question.c @@ -952,7 +952,7 @@ void Qst_WriteQuestionListing (struct Qst_Questions *Questions,unsigned QstInd) char *Id; /***** Get and show question data *****/ - if (Qst_GetQstDataFromDB (&Questions->Question)) + if (Qst_GetQstDataByCod (&Questions->Question)) { /***** Begin table row *****/ HTM_TR_Begin (NULL); @@ -1267,7 +1267,7 @@ void Qst_WriteQuestionRowForSelection (unsigned QstInd, char *Id; /***** Get and show questvoidion data *****/ - if (Qst_GetQstDataFromDB (Question)) + if (Qst_GetQstDataByCod (Question)) { /***** Begin table row *****/ HTM_TR_Begin (NULL); @@ -1810,7 +1810,7 @@ void Qst_ShowFormEditOneQst (void) if (Question.QstCod <= 0) // New question PutFormToEditQuestion = true; else - PutFormToEditQuestion = Qst_GetQstDataFromDB (&Question); + PutFormToEditQuestion = Qst_GetQstDataByCod (&Question); /***** Put form to edit question *****/ if (PutFormToEditQuestion) @@ -2471,10 +2471,10 @@ void Qst_FreeMediaOfQuestion (struct Qst_Question *Question) } /*****************************************************************************/ -/****************** Get data of a question from database *********************/ +/********************* Get question data using its code **********************/ /*****************************************************************************/ -bool Qst_GetQstDataFromDB (struct Qst_Question *Question) +bool Qst_GetQstDataByCod (struct Qst_Question *Question) { MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -2484,7 +2484,7 @@ bool Qst_GetQstDataFromDB (struct Qst_Question *Question) unsigned NumOpt; /***** Get question data from database *****/ - if ((QuestionExists = (Qst_DB_GetQstData (&mysql_res,Question->QstCod) != 0))) + if ((QuestionExists = (Qst_DB_GetQstDataByCod (&mysql_res,Question->QstCod) != 0))) { row = mysql_fetch_row (mysql_res); diff --git a/swad_question.h b/swad_question.h index 4e1d4cc1..bfc9d8fe 100644 --- a/swad_question.h +++ b/swad_question.h @@ -236,7 +236,7 @@ void Qst_FreeTextChoiceAnswer (struct Qst_Question *Question,unsigned NumOpt); void Qst_ResetMediaOfQuestion (struct Qst_Question *Question); void Qst_FreeMediaOfQuestion (struct Qst_Question *Question); -bool Qst_GetQstDataFromDB (struct Qst_Question *Question); +bool Qst_GetQstDataByCod (struct Qst_Question *Question); long Qst_GetMedCodFromDB (long CrsCod,long QstCod,int NumOpt); void Qst_GetMediaFromDB (long CrsCod,long QstCod,int NumOpt, struct Med_Media *Media); diff --git a/swad_question_database.c b/swad_question_database.c index f431b8ae..f7c46c71 100644 --- a/swad_question_database.c +++ b/swad_question_database.c @@ -1220,7 +1220,7 @@ unsigned Qst_DB_GetRecentAnswers (MYSQL_RES **mysql_res, /****************** Get data of a question from database *********************/ /*****************************************************************************/ -unsigned Qst_DB_GetQstData (MYSQL_RES **mysql_res,long QstCod) +unsigned Qst_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get a question", diff --git a/swad_question_database.h b/swad_question_database.h index 7d43303f..c37b9ac1 100644 --- a/swad_question_database.h +++ b/swad_question_database.h @@ -58,7 +58,7 @@ unsigned Qst_DB_GetRecentQuestions (MYSQL_RES **mysql_res, unsigned Qst_DB_GetRecentAnswers (MYSQL_RES **mysql_res, long CrsCod,time_t BeginTime); -unsigned Qst_DB_GetQstData (MYSQL_RES **mysql_res,long QstCod); +unsigned Qst_DB_GetQstDataByCod (MYSQL_RES **mysql_res,long QstCod); Qst_AnswerType_t Qst_DB_GetQstAnswerType (long QstCod); long Qst_DB_GetQstMedCod (long CrsCod,long QstCod); unsigned Qst_DB_GetQstCodFromTypeAnsStem (MYSQL_RES **mysql_res, diff --git a/swad_question_import.c b/swad_question_import.c index d2cf1b6c..c3b18d29 100644 --- a/swad_question_import.c +++ b/swad_question_import.c @@ -234,7 +234,7 @@ static void QstImp_ExportQuestion (struct Qst_Question *Question,FILE *FileXML) extern const char *Qst_StrAnswerTypesXML[Qst_NUM_ANS_TYPES]; extern const char *Txt_NEW_LINE; - if (Qst_GetQstDataFromDB (Question)) + if (Qst_GetQstDataByCod (Question)) { /***** Write the answer type *****/ fprintf (FileXML,"%s", diff --git a/swad_report.c b/swad_report.c index a773ded3..0672ac42 100644 --- a/swad_report.c +++ b/swad_report.c @@ -739,7 +739,7 @@ static void Rep_WriteSectionHitsPerAction (struct Rep_Report *Report) mysql_data_seek (mysql_res,0); /***** Write rows *****/ - for (NumHit = 1, NumClicks = 0; + for (NumHit = 1, NumClicks = 0; NumHit <= NumHits; NumHit++) { diff --git a/swad_room.c b/swad_room.c index 1d575726..56d81690 100644 --- a/swad_room.c +++ b/swad_room.c @@ -103,6 +103,9 @@ static void Roo_PutIconToEditRooms (void); static void Roo_PutIconsEditingRooms (__attribute__((unused)) void *Args); static void Roo_GetRoomDataByCod (struct Roo_Room *Room); +static void Roo_GetRoomDataFromRow (MYSQL_RES *mysql_res, + struct Roo_Room *Room, + Roo_WhichData_t WhichData); static void Roo_GetBldShrtName (struct Roo_Room *Room,const char *BldShrtNameFromDB); static Roo_RoomType_t Roo_GetTypeFromString (const char *Str); @@ -489,9 +492,7 @@ void Roo_PutIconToViewRooms (void) void Roo_GetListRooms (struct Roo_Rooms *Rooms,Roo_WhichData_t WhichData) { MYSQL_RES *mysql_res; - MYSQL_ROW row; unsigned NumRoom; - struct Roo_Room *Room; /***** Get rooms from database *****/ if ((Rooms->Num = Roo_DB_GetListRooms (&mysql_res,Gbl.Hierarchy.Ctr.CtrCod, @@ -506,46 +507,7 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,Roo_WhichData_t WhichData) for (NumRoom = 0; NumRoom < Rooms->Num; NumRoom++) - { - Room = &Rooms->Lst[NumRoom]; - - /* Get next room */ - row = mysql_fetch_row (mysql_res); - - /* Get room code (row[0]) */ - if ((Room->RooCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) - Err_WrongRoomExit (); - - switch (WhichData) - { - case Roo_ALL_DATA: - /* Get building code (row[1]) */ - Room->BldCod = Str_ConvertStrCodToLongCod (row[1]); - - /* Get the short name of the building (row[2]) */ - Roo_GetBldShrtName (Room,row[2]); - - /* Get floor (row[3]) */ - Room->Floor = Str_ConvertStrCodToLongCod (row[3]); - - /* Get type (row[4]) */ - Room->Type = Roo_GetTypeFromString (row[4]); - - /* Get the short (row[5]) and full (row[6]) names of the room */ - Str_Copy (Room->ShrtName,row[5],sizeof (Room->ShrtName) - 1); - Str_Copy (Room->FullName,row[6],sizeof (Room->FullName) - 1); - - /* Get seating capacity in this room (row[7]) */ - if (sscanf (row[7],"%u",&Room->Capacity) != 1) - Room->Capacity = Roo_UNLIMITED_CAPACITY; - break; - case Roo_ONLY_SHRT_NAME: - default: - /* Get the short name of the room (row[1]) */ - Str_Copy (Room->ShrtName,row[1],sizeof (Room->ShrtName) - 1); - break; - } - } + Roo_GetRoomDataFromRow (mysql_res,&Rooms->Lst[NumRoom],WhichData); } /***** Free structure that stores the query result *****/ @@ -559,7 +521,6 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,Roo_WhichData_t WhichData) static void Roo_GetRoomDataByCod (struct Roo_Room *Room) { MYSQL_RES *mysql_res; - MYSQL_ROW row; /***** Trivial check *****/ if (Room->RooCod <= 0) @@ -567,35 +528,60 @@ static void Roo_GetRoomDataByCod (struct Roo_Room *Room) /***** Get data of a room from database *****/ if (Roo_DB_GetRoomDataByCod (&mysql_res,Room->RooCod)) // Room found... - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get building code (row[0]) */ - Room->BldCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Get the short name of the building (row[1]) */ - Roo_GetBldShrtName (Room,row[1]); - - /* Get floor (row[2]) */ - Room->Floor = Str_ConvertStrCodToLongCod (row[2]); - - /* Get type (row[3]) */ - Room->Type = Roo_GetTypeFromString (row[3]); - - /* Get the short (row[4]) and full (row[5]) names of the room */ - Str_Copy (Room->ShrtName,row[4],sizeof (Room->ShrtName) - 1); - Str_Copy (Room->FullName,row[5],sizeof (Room->FullName) - 1); - - /* Get seating capacity in this room (row[6]) */ - if (sscanf (row[6],"%u",&Room->Capacity) != 1) - Room->Capacity = Roo_UNLIMITED_CAPACITY; - } + Roo_GetRoomDataFromRow (mysql_res,Room,Roo_ALL_DATA); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } +/*****************************************************************************/ +/********************* Get room data from database row ***********************/ +/*****************************************************************************/ + +static void Roo_GetRoomDataFromRow (MYSQL_RES *mysql_res, + struct Roo_Room *Room, + Roo_WhichData_t WhichData) + { + MYSQL_ROW row; + + /***** Get row *****/ + row = mysql_fetch_row (mysql_res); + + /***** Get room code (row[0]) *****/ + if ((Room->RooCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) + Err_WrongRoomExit (); + + switch (WhichData) + { + case Roo_ALL_DATA: + /***** Get building code (row[1]) *****/ + Room->BldCod = Str_ConvertStrCodToLongCod (row[1]); + + /***** Get the short name of the building (row[2]) *****/ + Roo_GetBldShrtName (Room,row[2]); + + /***** Get floor (row[3]) *****/ + Room->Floor = Str_ConvertStrCodToLongCod (row[3]); + + /***** Get type (row[4]) *****/ + Room->Type = Roo_GetTypeFromString (row[4]); + + /***** Get the short (row[5]) and full (row[6]) names of the room *****/ + Str_Copy (Room->ShrtName,row[5],sizeof (Room->ShrtName) - 1); + Str_Copy (Room->FullName,row[6],sizeof (Room->FullName) - 1); + + /***** Get seating capacity in this room (row[7]) *****/ + if (sscanf (row[7],"%u",&Room->Capacity) != 1) + Room->Capacity = Roo_UNLIMITED_CAPACITY; + break; + case Roo_ONLY_SHRT_NAME: + default: + /***** Get the short name of the room (row[1]) *****/ + Str_Copy (Room->ShrtName,row[1],sizeof (Room->ShrtName) - 1); + break; + } + } + /*****************************************************************************/ /****************** Get building short name from database ********************/ /*****************************************************************************/ diff --git a/swad_room_database.c b/swad_room_database.c index ddc90129..def58e2c 100644 --- a/swad_room_database.c +++ b/swad_room_database.c @@ -287,13 +287,14 @@ unsigned Roo_DB_GetRoomDataByCod (MYSQL_RES **mysql_res,long RooCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get data of a room", - "SELECT roo_rooms.BldCod," // row[0] - "bld_buildings.ShortName," // row[1] - "roo_rooms.Floor," // row[2] - "roo_rooms.Type," // row[3] - "roo_rooms.ShortName," // row[4] - "roo_rooms.FullName," // row[5] - "roo_rooms.Capacity" // row[6] + "SELECT roo_rooms.RooCod," // row[0] + "roo_rooms.BldCod," // row[1] + "bld_buildings.ShortName," // row[2] + "roo_rooms.Floor," // row[3] + "roo_rooms.Type," // row[4] + "roo_rooms.ShortName," // row[5] + "roo_rooms.FullName," // row[6] + "roo_rooms.Capacity" // row[7] " FROM roo_rooms LEFT JOIN bld_buildings" " ON roo_rooms.BldCod=bld_buildings.BldCod" " WHERE roo_rooms.RooCod=%ld", diff --git a/swad_test_print.c b/swad_test_print.c index f12e5bc5..6df306df 100644 --- a/swad_test_print.c +++ b/swad_test_print.c @@ -243,7 +243,7 @@ void TstPrn_ShowTestPrintToFillIt (struct TstPrn_Print *Print, Question.QstCod = Print->PrintedQuestions[QstInd].QstCod; /* Show question */ - if (!Qst_GetQstDataFromDB (&Question)) // Question exists + if (!Qst_GetQstDataByCod (&Question)) // Question exists Err_WrongQuestionExit (); /* Write question and answers */ @@ -551,7 +551,7 @@ void TstPrn_ShowPrintAfterAssess (struct TstPrn_Print *Print) Question.QstCod = Print->PrintedQuestions[QstInd].QstCod; /***** Get question data *****/ - QuestionExists = Qst_GetQstDataFromDB (&Question); + QuestionExists = Qst_GetQstDataByCod (&Question); /***** Write question and answers *****/ TstPrn_WriteQstAndAnsExam (&Gbl.Usrs.Me.UsrDat, @@ -2484,7 +2484,7 @@ void TstPrn_ShowPrintAnswers (struct Usr_Data *UsrDat, Question.QstCod = PrintedQuestions[QstInd].QstCod; /***** Get question data *****/ - QuestionExists = Qst_GetQstDataFromDB (&Question); + QuestionExists = Qst_GetQstDataByCod (&Question); /***** Write questions and answers *****/ TstPrn_WriteQstAndAnsExam (UsrDat,