diff --git a/swad_changelog.h b/swad_changelog.h index 4b755539..0c5b56a4 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.30 (2021-02-28)" +#define Log_PLATFORM_VERSION "SWAD 20.36.31 (2021-03-01)" #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.31: Mar 01, 2021 Code refactoring in timeline favourites. (305432 lines) 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) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 6198bb76..a4b2d7d3 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -917,11 +917,22 @@ 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_GetListUsrsHaveFaved (const char *Table,const char *Field, +unsigned TL_DB_GetListUsrsHaveFaved (TL_Fav_WhatToFav_t WhatToFav, long Cod,long UsrCod, unsigned MaxUsrs, MYSQL_RES **mysql_res) { + const char *Table[TL_Fav_NUM_WHAT_TO_FAV] = + { + "tl_notes_fav", + "tl_comments_fav", + }; + const char *Field[TL_Fav_NUM_WHAT_TO_FAV] = + { + "NotCod", + "PubCod", + }; + /***** Get list of users who have marked a note/comment as favourite from database *****/ return (unsigned) DB_QuerySELECT (mysql_res,"can not get favers", @@ -930,8 +941,8 @@ unsigned TL_DB_GetListUsrsHaveFaved (const char *Table,const char *Field, " WHERE %s=%ld" " AND UsrCod<>%ld" // Extra check " ORDER BY FavCod LIMIT %u", - Table, - Field,Cod, + Table[WhatToFav], + Field[WhatToFav],Cod, UsrCod, MaxUsrs); } diff --git a/swad_timeline_database.h b/swad_timeline_database.h index bfc0c0ff..f571b8c8 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -30,6 +30,7 @@ #include "swad_database.h" #include "swad_file_browser.h" #include "swad_timeline_comment.h" +#include "swad_timeline_favourite.h" #include "swad_timeline_note.h" #include "swad_timeline_post.h" #include "swad_timeline_publication.h" @@ -116,7 +117,7 @@ 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_GetListUsrsHaveFaved (const char *Table,const char *Field, +unsigned TL_DB_GetListUsrsHaveFaved (TL_Fav_WhatToFav_t WhatToFav, long Cod,long UsrCod, unsigned MaxUsrs, MYSQL_RES **mysql_res); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index cebfa38d..f01ac543 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -69,9 +69,7 @@ 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_ShowUsrsWhoHaveMarkedAsFav (const char *Table,const char *Field, - TL_Frm_Action_t Action, - const char *ParamFormat, +static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (TL_Fav_WhatToFav_t WhatToFav, long Cod,long UsrCod, unsigned NumFavs, TL_Usr_HowManyUsrs_t HowManyUsrs); @@ -155,8 +153,7 @@ void TL_Fav_PutIconToFavUnfNote (const struct TL_Not_Note *Not, HTM_DIV_End (); /***** Show who have marked this note as favourite *****/ - TL_Fav_ShowUsrsWhoHaveMarkedAsFav ("tl_notes_fav","NotCod", - TL_Frm_ALL_FAV_NOTE,"NotCod=%ld", + TL_Fav_ShowUsrsWhoHaveMarkedAsFav (TL_Fav_NOTE, Not->NotCod,Not->UsrCod,Not->NumFavs, HowManyUsrs); } @@ -300,8 +297,7 @@ void TL_Fav_PutIconToFavUnfComment (const struct TL_Com_Comment *Com, HTM_DIV_End (); /***** Show who have marked this comment as favourite *****/ - TL_Fav_ShowUsrsWhoHaveMarkedAsFav ("tl_comments_fav","PubCod", - TL_Frm_ALL_FAV_COMM,"PubCod=%ld", + TL_Fav_ShowUsrsWhoHaveMarkedAsFav (TL_Fav_NOTE, Com->PubCod,Com->UsrCod,Com->NumFavs, HowManyUsrs); } @@ -456,20 +452,28 @@ static void TL_Fav_PutFormToFavUnfComm (long PubCod) /********** Show users who have marked a note/comment as favourite ***********/ /*****************************************************************************/ -static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (const char *Table,const char *Field, - TL_Frm_Action_t Action, - const char *ParamFormat, +static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (TL_Fav_WhatToFav_t WhatToFav, long Cod,long UsrCod, unsigned NumFavs, TL_Usr_HowManyUsrs_t HowManyUsrs) { + TL_Frm_Action_t Action[TL_Fav_NUM_WHAT_TO_FAV] = + { + TL_Frm_ALL_FAV_NOTE, + TL_Frm_ALL_FAV_COMM, + }; + const char *ParamFormat[TL_Fav_NUM_WHAT_TO_FAV] = + { + "NotCod=%ld", + "PubCod=%ld", + }; MYSQL_RES *mysql_res; unsigned NumFirstUsrs; /***** Get users who have marked this note as favourite *****/ if (NumFavs) /***** Get list of users from database *****/ - NumFirstUsrs = TL_DB_GetListUsrsHaveFaved (Table,Field,Cod,UsrCod, + NumFirstUsrs = TL_DB_GetListUsrsHaveFaved (WhatToFav,Cod,UsrCod, HowManyUsrs == TL_Usr_SHOW_FEW_USRS ? TL_Usr_DEF_USRS_SHOWN : TL_Usr_MAX_USRS_SHOWN, &mysql_res); @@ -487,7 +491,9 @@ static void TL_Fav_ShowUsrsWhoHaveMarkedAsFav (const char *Table,const char *Fie TL_Usr_ShowSharersOrFavers (&mysql_res,NumFavs,NumFirstUsrs); if (NumFirstUsrs < NumFavs) // Not all are shown /* Clickable ellipsis to show all users */ - TL_Frm_PutFormToSeeAllFaversSharers (Action,ParamFormat,Cod,HowManyUsrs); + TL_Frm_PutFormToSeeAllFaversSharers (Action[WhatToFav], + ParamFormat[WhatToFav],Cod, + HowManyUsrs); HTM_DIV_End (); /***** Free structure that stores the query result *****/ diff --git a/swad_timeline_favourite.h b/swad_timeline_favourite.h index 2bdabb41..605b8cb7 100644 --- a/swad_timeline_favourite.h +++ b/swad_timeline_favourite.h @@ -31,15 +31,18 @@ #include "swad_timeline_note.h" /*****************************************************************************/ -/****************************** Public constants *****************************/ +/************************ Public constants and types *************************/ /*****************************************************************************/ -/*****************************************************************************/ -/******************************** Public types *******************************/ -/*****************************************************************************/ +#define TL_Fav_NUM_WHAT_TO_FAV 2 +typedef enum + { + TL_Fav_NOTE = 0, + TL_Fav_COMM = 1, + } TL_Fav_WhatToFav_t; /*****************************************************************************/ -/****************************** Public prototypes ****************************/ +/***************************** Public prototypes *****************************/ /*****************************************************************************/ void TL_Fav_PutFormToSeeAllFaversNote (long NotCod,