diff --git a/icon/file64x64.gif b/icon/file64x64.gif new file mode 100644 index 00000000..615d372f Binary files /dev/null and b/icon/file64x64.gif differ diff --git a/sql/cambios.sql b/sql/cambios.sql index b05a5163..54b3ce50 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -10531,6 +10531,9 @@ Hecho: UPDATE usr_figures,((SELECT UsrCod,COUNT(*) AS N FROM forum_post WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM forum_post))) AS FP SET usr_figures.NumForPst=FP.N WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.NumForPst<0 AND usr_figures.UsrCod=FP.UsrCod; UPDATE usr_figures,((SELECT UsrCod,COUNT(*) AS N FROM log WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM log))) AS NC SET usr_figures.NumClicks=NC.N WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.NumClicks<0 AND usr_figures.UsrCod=NC.UsrCod; UPDATE usr_figures,((SELECT UsrCod,COUNT(*) AS N FROM msg_snt WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM msg_snt))) AS MS,((SELECT UsrCod,COUNT(*) AS N FROM msg_snt_deleted WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM msg_snt_deleted))) AS MSD SET usr_figures.NumMsgSnt=MS.N+MSD.N WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.NumMsgSnt<0 AND usr_figures.UsrCod=MS.UsrCod AND usr_figures.UsrCod=MSD.UsrCod; +SET @USRCODMIN=1; +SET @USRCODMAX=500000; +UPDATE usr_figures,((SELECT UsrCod,SUM(NumViews) AS N FROM file_view WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM file_view))) AS FV SET usr_figures.NumFileViews=FV.N WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.NumFileViews<0 AND usr_figures.UsrCod=FV.UsrCod; Haciendo: SET @USRCODMIN=0; @@ -10538,12 +10541,13 @@ SET @USRCODMAX=1000; UPDATE usr_figures,((SELECT UsrCod,MIN(ClickTime) AS FCT FROM log WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,0 AS FCT FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM log))) AS CT SET usr_figures.FirstClickTime=CT.FCT WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.FirstClickTime=0 AND usr_figures.UsrCod=CT.UsrCod; -SET @USRCODMIN=0; -SET @USRCODMAX=1000; -UPDATE usr_figures,((SELECT UsrCod,SUM(NumViews) AS N FROM file_view WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX GROUP BY UsrCod) UNION (SELECT UsrCod,'0' AS N FROM usr_figures WHERE UsrCod>=@USRCODMIN AND UsrCod<=@USRCODMAX AND UsrCod NOT IN (SELECT UsrCod FROM file_view))) AS FV SET usr_figures.NumFileViews=FV.N WHERE usr_figures.UsrCod>=@USRCODMIN AND usr_figures.UsrCod<=@USRCODMAX AND usr_figures.NumFileViews<0 AND usr_figures.UsrCod=FV.UsrCod; --------------- CREATE TABLE IF NOT EXISTS usr_follow (FollowerCod INT NOT NULL,FollowedCod NIT NOT NULL,FollowTime DATETIME NOT NULL,UNIQUE INDEX (FollowerCod,FollowedCod),UNIQUE INDEX (FollowedCod,FollowerCod),INDEX (FollowTime)); +--------------- +CREATE INDEX UsrCod ON file_view (UsrCod); + +SELECT FollowedCod,COUNT(FollowerCod) AS N FROM usr_follow GROUP BY FollowedCod ORDER BY N DESC,FollowedCod LIMIT 100; diff --git a/sql/swad.sql b/sql/swad.sql index d5df4277..7549160b 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -491,7 +491,7 @@ CREATE TABLE IF NOT EXISTS file_view ( FilCod INT NOT NULL, UsrCod INT NOT NULL, NumViews INT NOT NULL DEFAULT 0, - UNIQUE INDEX(FilCod,UsrCod)); + UNIQUE INDEX(FilCod,UsrCod),INDEX(UsrCod)); -- -- Table files: stores metadata about each file -- diff --git a/swad_changelog.h b/swad_changelog.h index 5d6ce738..d1a08355 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -103,11 +103,16 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 14.99 (2015/03/21)" +#define Log_PLATFORM_VERSION "SWAD 14.99.2 (2015/03/23)" // 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 14.99.2: Mar 23, 2015 Ranking attending to number of followers. (183614 lines) + Version 14.99.1: Mar 21, 2015 Change in file_view to accelerate queries. (183521 lines) + 1 change necessary in Makefile: +CREATE INDEX UsrCod ON file_view (UsrCod); + Version 14.99: Mar 21, 2015 Icons instead of text in user's profile. Lot of changes in layout of user's profile. (183519 lines) Version 14.98.5: Mar 21, 2015 New icons for some options. (183431 lines) diff --git a/swad_database.c b/swad_database.c index 32754ae1..ee9dcecf 100644 --- a/swad_database.c +++ b/swad_database.c @@ -1027,10 +1027,10 @@ mysql> DESCRIBE file_view; 3 rows in set (0.00 sec) */ DB_CreateTable ("CREATE TABLE IF NOT EXISTS file_view (" - "FilCod INT NOT NULL," - "UsrCod INT NOT NULL," - "NumViews INT NOT NULL DEFAULT 0," - "UNIQUE INDEX(FilCod,UsrCod))"); + "FilCod INT NOT NULL," + "UsrCod INT NOT NULL," + "NumViews INT NOT NULL DEFAULT 0," + "UNIQUE INDEX(FilCod,UsrCod),INDEX(UsrCod))"); /***** Table files *****/ /* diff --git a/swad_follow.c b/swad_follow.c index 606b00c3..c09978d7 100644 --- a/swad_follow.c +++ b/swad_follow.c @@ -499,3 +499,82 @@ void Fol_UnfollowUsr (void) if (Error) Lay_ShowAlert (Lay_WARNING,Txt_User_not_found_or_you_do_not_have_permission_); } + +/*****************************************************************************/ +/****** Get and show ranking of users attending to number of followers *******/ +/*****************************************************************************/ + +void Fol_GetAndShowRankingFollowers (void) + { + char Query[512]; + + /***** Get ranking from database *****/ + switch (Gbl.Scope.Current) + { + case Sco_SCOPE_SYS: + sprintf (Query,"SELECT FollowedCod,COUNT(FollowerCod) AS N" + " FROM usr_follow" + " GROUP BY FollowedCod" + " ORDER BY N DESC,FollowedCod LIMIT 100"); + break; + case Sco_SCOPE_CTY: + sprintf (Query,"SELECT DISTINCTROW usr_follow.FollowedCod,COUNT(usr_follow.FollowerCod) AS N" + " FROM institutions,centres,degrees,courses,crs_usr,usr_follow" + " WHERE institutions.CtyCod='%ld'" + " AND institutions.InsCod=centres.InsCod" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=usr_follow.FollowedCod" + " GROUP BY usr_follow.FollowedCod" + " ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", + Gbl.CurrentCty.Cty.CtyCod); + break; + case Sco_SCOPE_INS: + sprintf (Query,"SELECT DISTINCTROW usr_follow.FollowedCod,COUNT(usr_follow.FollowerCod) AS N" + " FROM centres,degrees,courses,crs_usr,usr_follow" + " WHERE centres.InsCod='%ld'" + " AND centres.CtrCod=degrees.CtrCod" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=usr_follow.FollowedCod" + " GROUP BY usr_follow.FollowedCod" + " ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", + Gbl.CurrentIns.Ins.InsCod); + break; + case Sco_SCOPE_CTR: + sprintf (Query,"SELECT DISTINCTROW usr_follow.FollowedCod,COUNT(usr_follow.FollowerCod) AS N" + " FROM degrees,courses,crs_usr,usr_follow" + " WHERE degrees.CtrCod='%ld'" + " AND degrees.DegCod=courses.DegCod" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=usr_follow.FollowedCod" + " GROUP BY usr_follow.FollowedCod" + " ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", + Gbl.CurrentCtr.Ctr.CtrCod); + break; + case Sco_SCOPE_DEG: + sprintf (Query,"SELECT DISTINCTROW usr_follow.FollowedCod,COUNT(usr_follow.FollowerCod) AS N" + " FROM courses,crs_usr,usr_follow" + " WHERE courses.DegCod='%ld'" + " AND courses.CrsCod=crs_usr.CrsCod" + " AND crs_usr.UsrCod=usr_follow.FollowedCod" + " GROUP BY usr_follow.FollowedCod" + " ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", + Gbl.CurrentDeg.Deg.DegCod); + break; + case Sco_SCOPE_CRS: + sprintf (Query,"SELECT DISTINCTROW usr_follow.FollowedCod,COUNT(usr_follow.FollowerCod) AS N" + " FROM crs_usr,usr_follow" + " WHERE crs_usr.CrsCod='%ld'" + " AND crs_usr.UsrCod=usr_follow.FollowedCod" + " GROUP BY usr_follow.FollowedCod" + " ORDER BY N DESC,usr_follow.FollowedCod LIMIT 100", + Gbl.CurrentCrs.Crs.CrsCod); + break; + default: + Lay_ShowErrorAndExit ("Wrong scope."); + break; + } + Prf_ShowRankingFigure (Query); + } diff --git a/swad_follow.h b/swad_follow.h index 996ea4f3..5be6aa82 100644 --- a/swad_follow.h +++ b/swad_follow.h @@ -49,4 +49,6 @@ void Fol_ListFollowers (void); void Fol_FollowUsr (void); void Fol_UnfollowUsr (void); +void Fol_GetAndShowRankingFollowers (void); + #endif diff --git a/swad_profile.c b/swad_profile.c index b6f2b302..8e93bdd3 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -100,7 +100,6 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure static bool Prf_CheckIfUsrFiguresExists (long UsrCod); static void Prf_GetAndShowRankingFigure (const char *FieldName); -static void Prf_ShowUsrInRanking (const struct UsrData *UsrDat,unsigned Rank); /*****************************************************************************/ /************************** Get public profile URL ***************************/ @@ -1163,14 +1162,6 @@ void Prf_GetAndShowRankingMsgSnt (void) static void Prf_GetAndShowRankingFigure (const char *FieldName) { char Query[512]; - MYSQL_RES *mysql_res; - MYSQL_ROW row; - unsigned NumUsrs; - unsigned NumUsr; - unsigned Rank; - struct UsrData UsrDat; - long FigureHigh = LONG_MAX; - long Figure; /***** Get ranking from database *****/ switch (Gbl.Scope.Current) @@ -1252,6 +1243,20 @@ static void Prf_GetAndShowRankingFigure (const char *FieldName) Lay_ShowErrorAndExit ("Wrong scope."); break; } + Prf_ShowRankingFigure (Query); + } + +void Prf_ShowRankingFigure (const char *Query) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumUsrs; + unsigned NumUsr; + unsigned Rank; + struct UsrData UsrDat; + long FigureHigh = LONG_MAX; + long Figure; + NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get ranking"); if (NumUsrs) { @@ -1442,15 +1447,14 @@ void Prf_GetAndShowRankingClicksPerDay (void) /************** Show user's photo and nickname in ranking list ***************/ /*****************************************************************************/ -static void Prf_ShowUsrInRanking (const struct UsrData *UsrDat,unsigned Rank) +void Prf_ShowUsrInRanking (const struct UsrData *UsrDat,unsigned Rank) { extern const char *Txt_View_public_profile; bool ShowPhoto; char PhotoURL[PATH_MAX+1]; bool Visible = Pri_ShowIsAllowed (UsrDat->ProfileVisibility,UsrDat->UsrCod); - fprintf (Gbl.F.Out,"" - "" "#%u" "" diff --git a/swad_profile.h b/swad_profile.h index f848a19c..15a981d3 100644 --- a/swad_profile.h +++ b/swad_profile.h @@ -59,6 +59,8 @@ void Prf_GetAndShowRankingClicks (void); void Prf_GetAndShowRankingFileViews (void); void Prf_GetAndShowRankingForPst (void); void Prf_GetAndShowRankingMsgSnt (void); +void Prf_ShowRankingFigure (const char *Query); void Prf_GetAndShowRankingClicksPerDay (void); +void Prf_ShowUsrInRanking (const struct UsrData *UsrDat,unsigned Rank); #endif diff --git a/swad_statistic.c b/swad_statistic.c index 53664909..0d0eb842 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -38,6 +38,7 @@ #include "swad_course.h" #include "swad_database.h" #include "swad_file_browser.h" +#include "swad_follow.h" #include "swad_forum.h" #include "swad_global.h" #include "swad_ID.h" @@ -3809,6 +3810,7 @@ static void Sta_GetAndShowUsersRanking (void) extern const char *Txt_Downloads; extern const char *Txt_Forums; extern const char *Txt_Messages; + extern const char *Txt_Followers; Lay_StartRoundFrameTable10 (NULL,2,Txt_STAT_USE_STAT_TYPES[Sta_USRS_RANKING]); @@ -3829,12 +3831,16 @@ static void Sta_GetAndShowUsersRanking (void) "" "%s" "" + "" + "%s" + "" "", Txt_Clicks, Txt_Clicks_per_day, Txt_Downloads, Txt_Forums, - Txt_Messages); + Txt_Messages, + Txt_Followers); /***** Rankings *****/ fprintf (Gbl.F.Out,"" @@ -3857,6 +3863,10 @@ static void Sta_GetAndShowUsersRanking (void) ""); Prf_GetAndShowRankingMsgSnt (); + fprintf (Gbl.F.Out,"" + ""); + Fol_GetAndShowRankingFollowers (); fprintf (Gbl.F.Out,"" "");