From 21e670b8e51fd8e7309fedbfd21ce4b8f6861280 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 23 Mar 2023 19:56:18 +0100 Subject: [PATCH] Version 22.78.14: Mar 23, 2023 Code refactoring in timeline. --- swad_announcement.c | 2 +- swad_assignment.c | 2 +- swad_attendance.c | 2 +- swad_banner.c | 2 +- swad_browser.c | 2 +- swad_building.c | 2 +- swad_center.c | 4 +-- swad_changelog.h | 3 +- swad_course.c | 2 +- swad_degree.c | 2 +- swad_department.c | 2 +- swad_exam_print.c | 1 + swad_exam_session.c | 2 +- swad_exam_set.c | 2 +- swad_holiday.c | 2 +- swad_institution.c | 2 +- swad_link.c | 2 +- swad_mail.c | 2 +- swad_match.c | 2 +- swad_notice.c | 2 +- swad_place.c | 2 +- swad_plugin.c | 2 +- swad_rubric.c | 6 +--- swad_rubric_criteria.c | 16 ++++----- swad_survey.c | 2 +- swad_test_config.c | 2 +- swad_timeline.c | 67 +++++++++++++++++------------------- swad_timeline_comment.c | 2 +- swad_timeline_note.c | 2 +- swad_timeline_notification.c | 2 +- swad_timeline_publication.c | 6 ++-- swad_timeline_publication.h | 4 +-- 32 files changed, 74 insertions(+), 81 deletions(-) diff --git a/swad_announcement.c b/swad_announcement.c index 3cfdc91b..7036ace4 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -195,7 +195,7 @@ static void Ann_GetAnnouncementDataFromRow (MYSQL_RES *mysql_res, MYSQL_ROW row; unsigned UnsignedNum; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get announcement code (row[0]) *****/ diff --git a/swad_assignment.c b/swad_assignment.c index a9f57523..6133aa87 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -886,7 +886,7 @@ static void Asg_GetAssignmentDataFromRow (MYSQL_RES **mysql_res, /***** Get data of assignment from database *****/ if (NumAsgs) // Assignment found... { - /* Get row */ + /* Get next row from result */ row = mysql_fetch_row (*mysql_res); /* row[0] AsgCod diff --git a/swad_attendance.c b/swad_attendance.c index 9ca7b457..b6c43d34 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -743,7 +743,7 @@ bool Att_GetEventDataByCod (struct Att_Event *Event) /***** Get data of attendance event from database *****/ if ((Found = (NumAttEvents != 0))) // Attendance event found... { - /* Get row */ + /* Get next row from result */ row = mysql_fetch_row (mysql_res); /* Get attendance event (except Txt) */ diff --git a/swad_banner.c b/swad_banner.c index 78d62b9e..be32e938 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -341,7 +341,7 @@ static void Ban_GetBannerDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get banner code (row[0]) *****/ diff --git a/swad_browser.c b/swad_browser.c index a00ec02b..5e435c40 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -8487,7 +8487,7 @@ static void Brw_GetFileMetadataFromRow (MYSQL_RES *mysql_res, MYSQL_ROW row; unsigned UnsignedNum; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get file code (row[0]) *****/ diff --git a/swad_building.c b/swad_building.c index e5926244..29e8dd57 100644 --- a/swad_building.c +++ b/swad_building.c @@ -373,7 +373,7 @@ static void Bld_GetBuildingDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get building code (row[0]) *****/ diff --git a/swad_center.c b/swad_center.c index 3c44d527..2eea42ee 100644 --- a/swad_center.c +++ b/swad_center.c @@ -536,7 +536,7 @@ void Ctr_GetBasicListOfCenters (long InsCod) NumCtr++) /* Get center data */ Ctr_GetCenterDataFromRow (mysql_res,&(Gbl.Hierarchy.Ctrs.Lst[NumCtr]), - false); // Don't get number of users who claim to belong to this center + false); // Don't get number of users who claim to belong to this center } /***** Free structure that stores the query result *****/ @@ -626,7 +626,7 @@ static void Ctr_GetCenterDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get center code (row[0]) *****/ diff --git a/swad_changelog.h b/swad_changelog.h index bad8079c..b0ac0452 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.13 (2023-03-23)" +#define Log_PLATFORM_VERSION "SWAD 22.78.14 (2023-03-23)" #define CSS_FILE "swad22.57.1.css" #define JS_FILE "swad22.49.js" /* + Version 22.78.14: Mar 23, 2023 Code refactoring in timeline. (337635 lines) 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) diff --git a/swad_course.c b/swad_course.c index e2e2a4f6..f6a9a52a 100644 --- a/swad_course.c +++ b/swad_course.c @@ -1652,7 +1652,7 @@ static void Crs_GetCourseDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get course code (row[0]) *****/ diff --git a/swad_degree.c b/swad_degree.c index 3540b76d..eae7ab61 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -1205,7 +1205,7 @@ static void Deg_GetDegreeDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /**** Get row ****/ + /**** Get next row from result ****/ row = mysql_fetch_row (mysql_res); /***** Get degree code (row[0]) *****/ diff --git a/swad_department.c b/swad_department.c index 6c232cb9..ea86f5b2 100644 --- a/swad_department.c +++ b/swad_department.c @@ -411,7 +411,7 @@ static void Dpt_GetDepartmentDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get department code (row[0]) *****/ diff --git a/swad_exam_print.c b/swad_exam_print.c index 8f21365b..0dabf6f4 100644 --- a/swad_exam_print.c +++ b/swad_exam_print.c @@ -275,6 +275,7 @@ static void ExaPrn_GetPrintDataFromRow (MYSQL_RES **mysql_res, if (NumPrints) { + /* Get next row from result */ row = mysql_fetch_row (*mysql_res); /* Get print code (row[0]) */ diff --git a/swad_exam_session.c b/swad_exam_session.c index 30d36598..29442777 100644 --- a/swad_exam_session.c +++ b/swad_exam_session.c @@ -733,7 +733,7 @@ static void ExaSes_GetSessionDataFromRow (MYSQL_RES *mysql_res, MYSQL_ROW row; Dat_StartEndTime_t StartEndTime; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0] SesCod diff --git a/swad_exam_set.c b/swad_exam_set.c index 09f5fa97..4a60bf67 100644 --- a/swad_exam_set.c +++ b/swad_exam_set.c @@ -816,7 +816,7 @@ void ExaSet_GetSetDataFromRow (MYSQL_RES *mysql_res,struct ExaSet_Set *Set) { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0] SetCod diff --git a/swad_holiday.c b/swad_holiday.c index 8920d978..e5a4bec3 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -380,7 +380,7 @@ static void Hld_GetHolidayDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0]: HldCod diff --git a/swad_institution.c b/swad_institution.c index e813df2f..360549d6 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -732,7 +732,7 @@ static void Ins_GetInstitDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0]: InsCod diff --git a/swad_link.c b/swad_link.c index cdedb583..0e6ebea4 100644 --- a/swad_link.c +++ b/swad_link.c @@ -360,7 +360,7 @@ static void Lnk_GetLinkDataFromRow (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk) { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0] LnkCod diff --git a/swad_mail.c b/swad_mail.c index 4e3cf007..f3e067f7 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -403,7 +403,7 @@ static void Mai_GetMailDomainDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get mail code (row[0]) *****/ diff --git a/swad_match.c b/swad_match.c index c8c8f559..459ee076 100644 --- a/swad_match.c +++ b/swad_match.c @@ -884,7 +884,7 @@ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res, Dat_StartEndTime_t StartEndTime; long LongNum; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[ 0] MchCod diff --git a/swad_notice.c b/swad_notice.c index 5839cb66..a091d312 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -477,7 +477,7 @@ static void Not_GetNoticeDataFromRow (MYSQL_RES *mysql_res, MYSQL_ROW row; unsigned UnsignedNum; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get notice code (row[0]) *****/ diff --git a/swad_place.c b/swad_place.c index e8c49f5f..4131bead 100644 --- a/swad_place.c +++ b/swad_place.c @@ -419,7 +419,7 @@ static void Plc_GetPlaceDataFromRow (MYSQL_RES *mysql_res,struct Plc_Place *Plc) { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get place code (row[0]) *****/ diff --git a/swad_plugin.c b/swad_plugin.c index dac478d9..e8059f0e 100644 --- a/swad_plugin.c +++ b/swad_plugin.c @@ -304,7 +304,7 @@ static void Plg_GetPluginDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get plugin code (row[0]) *****/ diff --git a/swad_rubric.c b/swad_rubric.c index ee4130d4..95e65f42 100644 --- a/swad_rubric.c +++ b/swad_rubric.c @@ -573,13 +573,9 @@ void Rub_GetRubricDataByCod (struct Rub_Rubric *Rubric) /* Get row */ row = mysql_fetch_row (mysql_res); - /* Get code of the rubric (row[0]) */ + /* Get code of the rubric (row[0]), course (row[1] and author (row[2]) */ Rubric->RubCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Get code of the course (row[1]) */ Rubric->CrsCod = Str_ConvertStrCodToLongCod (row[1]); - - /* Get author of the rubric (row[2]) */ Rubric->UsrCod = Str_ConvertStrCodToLongCod (row[2]); /* Get the title of the rubric (row[3]) */ diff --git a/swad_rubric_criteria.c b/swad_rubric_criteria.c index e1f55fe0..4945e33b 100644 --- a/swad_rubric_criteria.c +++ b/swad_rubric_criteria.c @@ -701,7 +701,7 @@ static void RubCri_GetCriterionDataFromRow (MYSQL_RES *mysql_res, MYSQL_ROW row; RubCri_ValueRange_t ValueRange; - /* Get row */ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0] CriCod @@ -714,29 +714,27 @@ static void RubCri_GetCriterionDataFromRow (MYSQL_RES *mysql_res, row[7] Weight row[8] Title */ - /* Get criterion code (row[0]) */ + /***** Get criterion code (row[0]) and rubric code (row[1]) *****/ Criterion->CriCod = Str_ConvertStrCodToLongCod (row[0]); - - /* Get rubric code (row[0]) */ Criterion->RubCod = Str_ConvertStrCodToLongCod (row[1]); - /* Get criterion index (row[2]) */ + /***** Get criterion index (row[2]) *****/ Criterion->CriInd = Str_ConvertStrToUnsigned (row[2]); - /* Get source (row[3]) and code (row[4]) */ + /***** Get source (row[3]) and code (row[4]) *****/ Criterion->Source = RubCri_GetSourceFromDBStr (row[3]); Criterion->Cod = Str_ConvertStrCodToLongCod (row[4]); - /* Get criterion minimum and maximum values (row[5], row[6]) */ + /***** Get criterion minimum and maximum values (row[5], row[6]) *****/ for (ValueRange = (RubCri_ValueRange_t) 0; ValueRange <= (RubCri_ValueRange_t) (RubCri_NUM_VALUES - 1); ValueRange++) Criterion->Values[ValueRange] = Str_GetDoubleFromStr (row[5 + ValueRange]); - /* Get criterion weight (row[7]) */ + /***** Get criterion weight (row[7]) *****/ Criterion->Weight = Str_GetDoubleFromStr (row[5 + RubCri_NUM_VALUES]); - /* Get the title of the criterion (row[8]) */ + /***** Get the title of the criterion (row[8]) *****/ Str_Copy (Criterion->Title,row[5 + RubCri_NUM_VALUES + 1],sizeof (Criterion->Title) - 1); } diff --git a/swad_survey.c b/swad_survey.c index 7d998a09..4a942bb8 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -2845,7 +2845,7 @@ static void Svy_GetQstDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get the code of the question (row[0]) *****/ diff --git a/swad_test_config.c b/swad_test_config.c index d4f3b4ba..b91aa87d 100644 --- a/swad_test_config.c +++ b/swad_test_config.c @@ -338,7 +338,7 @@ static void TstCfg_GetConfigDataFromRow (MYSQL_RES *mysql_res) long LongNum; TstCfg_Pluggable_t Pluggable; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /***** Get whether test are visible via plugins or not *****/ diff --git a/swad_timeline.c b/swad_timeline.c index e3066fc2..efcbf052 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -164,6 +164,10 @@ static unsigned Tml_ListRecentPubs (const struct Tml_Timeline *Timeline, static void Tml_PutHiddenList (const char *Id); +static void Tml_GetNumNotesAndUsrsFromRow (MYSQL_RES *mysql_res, + unsigned *NumNotes, + unsigned *NumUsrs); + /*****************************************************************************/ /************************ Initialize global timeline *************************/ /*****************************************************************************/ @@ -588,24 +592,9 @@ void Tml_GetAndShowTimelineActivityStats (void) { /***** Get number of timeline notes and users for this type *****/ if (Tml_DB_GetNumNotesAndUsrsByType (&mysql_res,NoteType)) - { - row = mysql_fetch_row (mysql_res); - - /* Get number of timeline notes */ - if (row[0]) - if (sscanf (row[0],"%u",&NumNotes) != 1) - NumNotes = 0; - - /* Get number of users */ - if (row[1]) - if (sscanf (row[1],"%u",&NumUsrs) != 1) - NumUsrs = 0; - } + Tml_GetNumNotesAndUsrsFromRow (mysql_res,&NumNotes,&NumUsrs); else - { - NumNotes = 0; - NumUsrs = 0; - } + NumNotes = NumUsrs = 0; /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -642,25 +631,9 @@ void Tml_GetAndShowTimelineActivityStats (void) /***** Get and write totals *****/ if (Tml_DB_GetNumNotesAndUsrsTotal (&mysql_res)) - { - /* Get number of social notes and number of users */ - row = mysql_fetch_row (mysql_res); - - /* Get number of social notes */ - if (row[0]) - if (sscanf (row[0],"%u",&NumNotes) != 1) - NumNotes = 0; - - /* Get number of users */ - if (row[1]) - if (sscanf (row[1],"%u",&NumUsrs) != 1) - NumUsrs = 0; - } + Tml_GetNumNotesAndUsrsFromRow (mysql_res,&NumNotes,&NumUsrs); else - { - NumNotes = 0; - NumUsrs = 0; - } + NumNotes = NumUsrs = 0; /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -701,3 +674,27 @@ void Tml_GetAndShowTimelineActivityStats (void) /***** End table and box *****/ Box_BoxTableEnd (); } + +/*****************************************************************************/ +/************** Get number of notes and users from database row **************/ +/*****************************************************************************/ + +static void Tml_GetNumNotesAndUsrsFromRow (MYSQL_RES *mysql_res, + unsigned *NumNotes, + unsigned *NumUsrs) + { + MYSQL_ROW row; + + /***** Get next row from result *****/ + row = mysql_fetch_row (mysql_res); + + /***** Get number of notes *****/ + if (row[0]) + if (sscanf (row[0],"%u",NumNotes) != 1) + *NumNotes = 0; + + /***** Get number of users *****/ + if (row[1]) + if (sscanf (row[1],"%u",NumUsrs) != 1) + *NumUsrs = 0; + } diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index d1e27533..1f5cb2c8 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -1072,7 +1072,7 @@ static void TmlCom_GetCommDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0]: PubCod diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 8526271d..4f0e2e02 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -1201,7 +1201,7 @@ static void TmlNot_GetNoteDataFromRow (MYSQL_RES *mysql_res, { MYSQL_ROW row; - /***** Get row *****/ + /***** Get next row from result *****/ row = mysql_fetch_row (mysql_res); /* row[0]: NotCod diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index d3ceb81c..53c81fb4 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -108,7 +108,7 @@ void TmlNtf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], /***** Get summary and content from post from database *****/ if (Tml_DB_GetPubDataByCod (PubCod,&mysql_res) == 1) // Result should have a unique row /* Get data of publication from row */ - TmlPub_GetPubDataFromNextRow (mysql_res,&Pub); + TmlPub_GetPubDataFromRow (mysql_res,&Pub); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 114ae705..3fbe0d12 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -361,7 +361,7 @@ static struct TmlPub_Publication *TmlPub_SelectTheMostRecentPub (const struct Tm Err_NotEnoughMemoryExit (); /* Get data of publication */ - TmlPub_GetPubDataFromNextRow (mysql_res,Pub); + TmlPub_GetPubDataFromRow (mysql_res,Pub); Pub->Next = NULL; } else @@ -510,8 +510,8 @@ void TmlPub_PutLinkToViewOldPubs (void) /***************** Get data of publication using its code ********************/ /*****************************************************************************/ -void TmlPub_GetPubDataFromNextRow (MYSQL_RES *mysql_res, - struct TmlPub_Publication *Pub) +void TmlPub_GetPubDataFromRow (MYSQL_RES *mysql_res, + struct TmlPub_Publication *Pub) { MYSQL_ROW row; diff --git a/swad_timeline_publication.h b/swad_timeline_publication.h index 06a09ca7..01fee029 100644 --- a/swad_timeline_publication.h +++ b/swad_timeline_publication.h @@ -115,8 +115,8 @@ Tml_TopMessage_t TmlPub_GetTopMessage (TmlPub_Type_t PubType); void TmlPub_PutLinkToViewNewPubs (void); void TmlPub_PutLinkToViewOldPubs (void); -void TmlPub_GetPubDataFromNextRow (MYSQL_RES *mysql_res, - struct TmlPub_Publication *Pub); +void TmlPub_GetPubDataFromRow (MYSQL_RES *mysql_res, + struct TmlPub_Publication *Pub); void TmlPub_PublishPubInTimeline (struct TmlPub_Publication *Pub);