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,"