From 5106642ec15d524e09a27fa23f329cd76ed2062e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Wed, 27 Jan 2016 23:28:53 +0100 Subject: [PATCH] Version 15.133 --- swad_changelog.h | 3 +- swad_follow.c | 105 ++++++++++++++++++++++++++++++++++++----------- swad_text.c | 30 ++++++++++++++ 3 files changed, 114 insertions(+), 24 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index d2737bf5d..cf515d821 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -123,13 +123,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.132.1 (2016-01-27)" +#define Log_PLATFORM_VERSION "SWAD 15.133 (2016-01-27)" #define CSS_FILE "swad15.131.2.css" #define JS_FILE "swad15.131.3.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.133: Jan 27, 2016 List users to follow. (195236 lines) Version 15.132.1: Jan 27, 2016 Build query to get users to follow. (195158 lines) Version 15.132: Jan 27, 2016 Put link to suggest users to follow. (195116 lines) 2 changes necessary in database: diff --git a/swad_follow.c b/swad_follow.c index 33f38a37c..ab91d990b 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -46,6 +46,8 @@ #define Fol_NUM_COLUMNS_FOLLOW 3 +#define Fol_MAX_USRS_TO_FOLLOW_SUGGESTED (Fol_NUM_COLUMNS_FOLLOW * 3) + /*****************************************************************************/ /****************************** Internal types *******************************/ /*****************************************************************************/ @@ -89,12 +91,16 @@ void Fol_PutLinkWhoToFollow (void) /******************** Put link to suggest users to follow ********************/ /*****************************************************************************/ -#define Fol_MAX_USRS_SUGGESTED 1000 - void Fol_SuggestWhoToFollow (void) { extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY]; + extern const char *Txt_No_user_to_whom_you_can_follow_Try_again_later; char Query[2048]; + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumUsrs; + unsigned NumUsr; + struct UsrData UsrDat; /***** First try: build query to get users to follow *****/ sprintf (Query,"SELECT UsrCod FROM" @@ -147,7 +153,7 @@ void Fol_SuggestWhoToFollow (void) " (SELECT FollowedCod FROM usr_follow" " WHERE FollowerCod='%ld')" - // Get only Fol_MAX_USRS_SUGGESTED users + // Get only Fol_MAX_USRS_TO_FOLLOW_SUGGESTED users " ORDER BY RAND() LIMIT %u", Gbl.Usrs.Me.UsrDat.UsrCod, Gbl.Usrs.Me.UsrDat.UsrCod, @@ -159,31 +165,84 @@ void Fol_SuggestWhoToFollow (void) Gbl.Usrs.Me.UsrDat.UsrCod, Pri_VisibilityDB[Pri_VISIBILITY_USER], Gbl.Usrs.Me.UsrDat.UsrCod, - Fol_MAX_USRS_SUGGESTED); + Fol_MAX_USRS_TO_FOLLOW_SUGGESTED); - Lay_ShowAlert (Lay_INFO,Query); + // Lay_ShowAlert (Lay_INFO,Query); - /***** Second try: build query to get users to follow *****/ - sprintf (Query,// Users with privacy - // Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD - "SELECT UsrCod FROM usr_data" - " WHERE UsrCod<>'%ld'" - " AND ProfileVisibility IN ('%s','%s')" + /***** Try to get users *****/ + NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get followed users"); - // Not select my followed - " AND UsrCod NOT IN" - " (SELECT FollowedCod FROM usr_follow" - " WHERE FollowerCod='%ld')" + if (!NumUsrs) + { + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); - // Get only Fol_MAX_USRS_SUGGESTED users - " ORDER BY RAND() LIMIT %u", - Gbl.Usrs.Me.UsrDat.UsrCod, - Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM], - Pri_VisibilityDB[Pri_VISIBILITY_WORLD], - Gbl.Usrs.Me.UsrDat.UsrCod, - Fol_MAX_USRS_SUGGESTED); + /***** Second try: build query to get users to follow *****/ + sprintf (Query,// Users with privacy + // Pri_VISIBILITY_SYSTEM or Pri_VISIBILITY_WORLD + "SELECT UsrCod FROM usr_data" + " WHERE UsrCod<>'%ld'" + " AND ProfileVisibility IN ('%s','%s')" - Lay_ShowAlert (Lay_INFO,Query); + // Not select my followed + " AND UsrCod NOT IN" + " (SELECT FollowedCod FROM usr_follow" + " WHERE FollowerCod='%ld')" + + // Get only Fol_MAX_USRS_TO_FOLLOW_SUGGESTED users + " ORDER BY RAND() LIMIT %u", + Gbl.Usrs.Me.UsrDat.UsrCod, + Pri_VisibilityDB[Pri_VISIBILITY_SYSTEM], + Pri_VisibilityDB[Pri_VISIBILITY_WORLD], + Gbl.Usrs.Me.UsrDat.UsrCod, + Fol_MAX_USRS_TO_FOLLOW_SUGGESTED); + + // Lay_ShowAlert (Lay_INFO,Query); + + /***** Get users *****/ + NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get followed users"); + } + + if (NumUsrs) + { + /***** Initialize structure with user's data *****/ + Usr_UsrDataConstructor (&UsrDat); + + /***** Start listing *****/ + fprintf (Gbl.F.Out,""); + + for (NumUsr = 0; + NumUsr < NumUsrs; + NumUsr++) + { + /***** Get user *****/ + row = mysql_fetch_row (mysql_res); + + /* Get user's code (row[0]) */ + UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); + + /***** Show user *****/ + if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == 0) + fprintf (Gbl.F.Out,""); + if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat)) + Fol_ShowFollowedOrFollower (&UsrDat); + if ((NumUsr % Fol_NUM_COLUMNS_FOLLOW) == (Fol_NUM_COLUMNS_FOLLOW-1) || + NumUsr == NumUsrs - 1) + fprintf (Gbl.F.Out,""); + } + + /***** End listing *****/ + fprintf (Gbl.F.Out,"
"); + + /***** Free memory used for user's data *****/ + Usr_UsrDataDestructor (&UsrDat); + } + else + Lay_ShowAlert (Lay_INFO,Txt_No_user_to_whom_you_can_follow_Try_again_later); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); } /*****************************************************************************/ diff --git a/swad_text.c b/swad_text.c index e7783259f..57760daed 100644 --- a/swad_text.c +++ b/swad_text.c @@ -24223,6 +24223,36 @@ const char *Txt_No_user_has_been_removed = "No user has been removed."; // Necessita de tradução #endif +const char *Txt_No_user_to_whom_you_can_follow_Try_again_later = +#if L==1 + "No hi ha cap usuari a qui vostè pugui seguir." + " Intenteu-ho més endavant."; +#elif L==2 + "Kein Benutzer dem Sie folgen können." + " Versuchen Sie es später noch einmal."; +#elif L==3 + "No user to whom you can follow." + " Try again later."; +#elif L==4 + "No hay ningún usuario a quien usted pueda seguir." + " Inténtelo más adelante."; +#elif L==5 + "Aucun utilisateur auquel vous pouvez suivre." + " Réessayez plus tard."; +#elif L==6 + "No hay ningún usuario a quien usted pueda seguir." + " Inténtelo más adelante."; // Okoteve traducción +#elif L==7 + "Nessun utente a cui è possibile seguire." + " Riprovare più tardi."; +#elif L==8 + "No użytkownika, do którego można śledzić." + " Spróbuj ponownie później."; +#elif L==9 + "Nenhum usuário a quem você pode seguir." + " Tente novamente mais tarde."; +#endif + const char *Txt_No_users_found[Rol_NUM_ROLES] = { #if L==1 // Rol_ROLE_UNKNOWN