From 7b70bb82628488af1968a4e1a391c14e89ea37c9 Mon Sep 17 00:00:00 2001 From: acanas Date: Sun, 28 Feb 2021 23:03:45 +0100 Subject: [PATCH] Version 20.36.30: Feb 28, 2021 Code refactoring in timeline favourites. --- swad_changelog.h | 3 +- swad_timeline_database.c | 30 ++----------- swad_timeline_database.h | 10 ++--- swad_timeline_favourite.c | 95 +++++++++++++-------------------------- 4 files changed, 42 insertions(+), 96 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 6b77aa40..4b755539 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.36.29 (2021-02-28)" +#define Log_PLATFORM_VERSION "SWAD 20.36.30 (2021-02-28)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts + Version 20.36.30: Feb 28, 2021 Code refactoring in timeline favourites. (305411 lines) Version 20.36.29: Feb 28, 2021 Code refactoring in module swad_timeline_database. (305457 lines) Version 20.36.28: Feb 28, 2021 Functions moved to module swad_timeline_database. (305426 lines) Version 20.36.27: Feb 28, 2021 Functions moved to module swad_timeline_database. (305424 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 3acb7504..6198bb76 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -62,10 +62,6 @@ static bool TL_DB_CheckIfFavedByUsr (const char *Table,const char *Field, long Cod,long UsrCod); static unsigned TL_DB_GetNumTimesHasBeenFav (const char *Table,const char *Field, long Cod,long UsrCod); -static unsigned TL_DB_GetListUsrsHaveFaved (const char *Table,const char *Field, - long Cod,long UsrCod, - unsigned MaxUsrs, - MYSQL_RES **mysql_res); static void TL_DB_MarkAsFav (const char *Table,const char *Field,long Cod); static void TL_DB_UnmarkAsFav (const char *Table,const char *Field,long Cod); @@ -921,28 +917,10 @@ static unsigned TL_DB_GetNumTimesHasBeenFav (const char *Table,const char *Field /******* Get list of users who have marked a note/comment as favourite *******/ /*****************************************************************************/ -unsigned TL_DB_GetListUsrsHaveFavedANote (const struct TL_Not_Note *Not, - unsigned MaxUsrs, - MYSQL_RES **mysql_res) - { - return TL_DB_GetListUsrsHaveFaved ("tl_notes_fav","NotCod", - Not->NotCod,Not->UsrCod,MaxUsrs, - mysql_res); - } - -unsigned TL_DB_GetListUsrsHaveFavedAComm (const struct TL_Com_Comment *Com, - unsigned MaxUsrs, - MYSQL_RES **mysql_res) - { - return TL_DB_GetListUsrsHaveFaved ("tl_comments_fav","PubCod", - Com->PubCod,Com->UsrCod,MaxUsrs, - mysql_res); - } - -static unsigned TL_DB_GetListUsrsHaveFaved (const char *Table,const char *Field, - long Cod,long UsrCod, - unsigned MaxUsrs, - MYSQL_RES **mysql_res) +unsigned TL_DB_GetListUsrsHaveFaved (const char *Table,const char *Field, + long Cod,long UsrCod, + unsigned MaxUsrs, + MYSQL_RES **mysql_res) { /***** Get list of users who have marked a note/comment as favourite from database *****/ return (unsigned) diff --git a/swad_timeline_database.h b/swad_timeline_database.h index acb7eaca..bfc0c0ff 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -116,12 +116,10 @@ bool TL_DB_CheckIfNoteIsFavedByUsr (long NotCod,long UsrCod); bool TL_DB_CheckIfCommIsFavedByUsr (long PubCod,long UsrCod); unsigned TL_DB_GetNumTimesANoteHasBeenFav (const struct TL_Not_Note *Not); unsigned TL_DB_GetNumTimesACommHasBeenFav (const struct TL_Com_Comment *Com); -unsigned TL_DB_GetListUsrsHaveFavedANote (const struct TL_Not_Note *Not, - unsigned MaxUsrs, - MYSQL_RES **mysql_res); -unsigned TL_DB_GetListUsrsHaveFavedAComm (const struct TL_Com_Comment *Com, - unsigned MaxUsrs, - MYSQL_RES **mysql_res); +unsigned TL_DB_GetListUsrsHaveFaved (const char *Table,const char *Field, + long Cod,long UsrCod, + unsigned MaxUsrs, + MYSQL_RES **mysql_res); void TL_DB_MarkNoteAsFav (long NotCod); void TL_DB_MarkCommAsFav (long PubCod); void TL_DB_UnmarkNoteAsFav (long NotCod); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index 3b1f4d81..cebfa38d 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -69,10 +69,12 @@ static void TL_Fav_PutDisabledIconFav (unsigned NumFavs); static void TL_Fav_PutFormToFavUnfNote (long NotCod); static void TL_Fav_PutFormToFavUnfComm (long PubCod); -static void TL_Fav_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Not_Note *Not, - TL_Usr_HowManyUsrs_t HowManyUsrs); -static void TL_Fav_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Com_Comment *Com, - TL_Usr_HowManyUsrs_t HowManyUsrs); +static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (const char *Table,const char *Field, + TL_Frm_Action_t Action, + const char *ParamFormat, + long Cod,long UsrCod, + unsigned NumFavs, + TL_Usr_HowManyUsrs_t HowManyUsrs); /*****************************************************************************/ /********************** Mark/unmark a note as favourite **********************/ @@ -153,7 +155,10 @@ void TL_Fav_PutIconToFavUnfNote (const struct TL_Not_Note *Not, HTM_DIV_End (); /***** Show who have marked this note as favourite *****/ - TL_Fav_ShowUsrsWhoHaveMarkedNoteAsFav (Not,HowManyUsrs); + TL_Fav_ShowUsrsWhoHaveMarkedAsFav ("tl_notes_fav","NotCod", + TL_Frm_ALL_FAV_NOTE,"NotCod=%ld", + Not->NotCod,Not->UsrCod,Not->NumFavs, + HowManyUsrs); } static void TL_Fav_FavNote (struct TL_Not_Note *Not) @@ -295,7 +300,10 @@ void TL_Fav_PutIconToFavUnfComment (const struct TL_Com_Comment *Com, HTM_DIV_End (); /***** Show who have marked this comment as favourite *****/ - TL_Fav_ShowUsrsWhoHaveMarkedCommAsFav (Com,HowManyUsrs); + TL_Fav_ShowUsrsWhoHaveMarkedAsFav ("tl_comments_fav","PubCod", + TL_Frm_ALL_FAV_COMM,"PubCod=%ld", + Com->PubCod,Com->UsrCod,Com->NumFavs, + HowManyUsrs); } static void TL_Fav_FavComment (struct TL_Com_Comment *Com) @@ -310,7 +318,7 @@ static void TL_Fav_FavComment (struct TL_Com_Comment *Com) if (Com->PubCod > 0) if (!Usr_ItsMe (Com->UsrCod)) // I am not the author if (!TL_DB_CheckIfCommIsFavedByUsr (Com->PubCod, - Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment + Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the comment { /***** Mark comment as favourite in database *****/ TL_DB_MarkCommAsFav (Com->PubCod); @@ -445,83 +453,44 @@ static void TL_Fav_PutFormToFavUnfComm (long PubCod) } /*****************************************************************************/ -/************ Show users who have marked this note as favourite **************/ +/********** Show users who have marked a note/comment as favourite ***********/ /*****************************************************************************/ -static void TL_Fav_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Not_Note *Not, - TL_Usr_HowManyUsrs_t HowManyUsrs) +static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (const char *Table,const char *Field, + TL_Frm_Action_t Action, + const char *ParamFormat, + long Cod,long UsrCod, + unsigned NumFavs, + TL_Usr_HowManyUsrs_t HowManyUsrs) { MYSQL_RES *mysql_res; unsigned NumFirstUsrs; /***** Get users who have marked this note as favourite *****/ - if (Not->NumFavs) + if (NumFavs) /***** Get list of users from database *****/ - NumFirstUsrs = TL_DB_GetListUsrsHaveFavedANote (Not, - HowManyUsrs == TL_Usr_SHOW_FEW_USRS ? TL_Usr_DEF_USRS_SHOWN : - TL_Usr_MAX_USRS_SHOWN, - &mysql_res); + NumFirstUsrs = TL_DB_GetListUsrsHaveFaved (Table,Field,Cod,UsrCod, + HowManyUsrs == TL_Usr_SHOW_FEW_USRS ? TL_Usr_DEF_USRS_SHOWN : + TL_Usr_MAX_USRS_SHOWN, + &mysql_res); else NumFirstUsrs = 0; /***** Show users *****/ /* Number of users */ HTM_DIV_Begin ("class=\"TL_NUM_USRS\""); - TL_Usr_ShowNumSharersOrFavers (Not->NumFavs); + TL_Usr_ShowNumSharersOrFavers (NumFavs); HTM_DIV_End (); /* List users one by one */ HTM_DIV_Begin ("class=\"TL_USRS\""); - TL_Usr_ShowSharersOrFavers (&mysql_res,Not->NumFavs,NumFirstUsrs); - if (NumFirstUsrs < Not->NumFavs) // Not all are shown + TL_Usr_ShowSharersOrFavers (&mysql_res,NumFavs,NumFirstUsrs); + if (NumFirstUsrs < NumFavs) // Not all are shown /* Clickable ellipsis to show all users */ - TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_ALL_FAV_NOTE, - "NotCod=%ld",Not->NotCod, - HowManyUsrs); + TL_Frm_PutFormToSeeAllFaversSharers (Action,ParamFormat,Cod,HowManyUsrs); HTM_DIV_End (); /***** Free structure that stores the query result *****/ - if (Not->NumFavs) - DB_FreeMySQLResult (&mysql_res); - } - -/*****************************************************************************/ -/************ Show users who have marked this note as favourite **************/ -/*****************************************************************************/ - -static void TL_Fav_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Com_Comment *Com, - TL_Usr_HowManyUsrs_t HowManyUsrs) - { - MYSQL_RES *mysql_res; - unsigned NumFirstUsrs; - - /***** Get users who have marked this comment as favourite *****/ - if (Com->NumFavs) - /***** Get list of users from database *****/ - NumFirstUsrs = TL_DB_GetListUsrsHaveFavedAComm (Com, - HowManyUsrs == TL_Usr_SHOW_FEW_USRS ? TL_Usr_DEF_USRS_SHOWN : - TL_Usr_MAX_USRS_SHOWN, - &mysql_res); - else - NumFirstUsrs = 0; - - /***** Show users *****/ - /* Number of users */ - HTM_DIV_Begin ("class=\"TL_NUM_USRS\""); - TL_Usr_ShowNumSharersOrFavers (Com->NumFavs); - HTM_DIV_End (); - - /* List users one by one */ - HTM_DIV_Begin ("class=\"TL_USRS\""); - TL_Usr_ShowSharersOrFavers (&mysql_res,Com->NumFavs,NumFirstUsrs); - if (NumFirstUsrs < Com->NumFavs) - /* Clickable ellipsis to show all users */ - TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_ALL_FAV_COMM, - "PubCod=%ld",Com->PubCod, - HowManyUsrs); - HTM_DIV_End (); - - /***** Free structure that stores the query result *****/ - if (Com->NumFavs) + if (NumFavs) DB_FreeMySQLResult (&mysql_res); }