diff --git a/Makefile b/Makefile
index dc44a75f..a59f28c8 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_pagination.o swad_parameter.o swad_password.o \
swad_password_database.o swad_photo.o swad_photo_database.o \
swad_place.o swad_place_database.o swad_plugin.o swad_plugin_database.o \
- swad_privacy.o swad_profile.o swad_program.o swad_project.o \
+ swad_privacy.o swad_profile.o swad_profile_database.o swad_program.o \
+ swad_project.o \
swad_QR.o \
swad_record.o swad_report.o swad_role.o swad_room.o swad_RSS.o \
swad_scope.o swad_search.o swad_session.o swad_setting.o \
diff --git a/swad_account.c b/swad_account.c
index be94ae73..3383f4b3 100644
--- a/swad_account.c
+++ b/swad_account.c
@@ -62,6 +62,7 @@
#include "swad_parameter.h"
#include "swad_photo_database.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_project.h"
#include "swad_report.h"
#include "swad_setting.h"
diff --git a/swad_browser.c b/swad_browser.c
index 8ae4466a..bd9c2d73 100644
--- a/swad_browser.c
+++ b/swad_browser.c
@@ -63,6 +63,7 @@
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_project.h"
#include "swad_role.h"
#include "swad_setting.h"
diff --git a/swad_changelog.h b/swad_changelog.h
index 9e9d77cd..5741237f 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
*/
-#define Log_PLATFORM_VERSION "SWAD 21.26 (2021-10-06)"
+#define Log_PLATFORM_VERSION "SWAD 21.27 (2021-10-07)"
#define CSS_FILE "swad20.45.css"
#define JS_FILE "swad20.69.1.js"
/*
TODO: Rename CENTRE to CENTER in help wiki.
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
+ Version 21.27: Oct 07, 2021 New module swad_profile_database for database queries related to user's public profile. (318846 lines)
Version 21.26: Oct 06, 2021 New module swad_plugin_database for database queries related to plugins. (318680 lines)
Version 21.25: Oct 05, 2021 New module swad_place_database for database queries related to places. (318514 lines)
Version 21.24.1: Oct 05, 2021 Queries moved to module swad_photo_database. (318406 lines)
diff --git a/swad_database.c b/swad_database.c
index 190b33c3..1e3604a9 100644
--- a/swad_database.c
+++ b/swad_database.c
@@ -3518,10 +3518,10 @@ mysql> DESCRIBE usr_figures;
"UsrCod INT NOT NULL,"
"FirstClickTime DATETIME NOT NULL,"
"NumClicks INT NOT NULL DEFAULT -1,"
- "NumSocPub INT NOT NULL DEFAULT -1,"
+ "NumSocPub INT NOT NULL DEFAULT -1," // TODO: Rename to NumTimelinePubs
"NumFileViews INT NOT NULL DEFAULT -1,"
- "NumForPst INT NOT NULL DEFAULT -1,"
- "NumMsgSnt INT NOT NULL DEFAULT -1,"
+ "NumForPst INT NOT NULL DEFAULT -1," // TODO: Rename to NumForumPosts
+ "NumMsgSnt INT NOT NULL DEFAULT -1," // TODO: Rename to NumMessagesSent
"PRIMARY KEY(UsrCod),"
"INDEX(FirstClickTime),"
"INDEX(NumClicks))");
diff --git a/swad_figure.c b/swad_figure.c
index ef53489f..93788433 100644
--- a/swad_figure.c
+++ b/swad_figure.c
@@ -548,7 +548,7 @@ static void Fig_GetAndShowUsersRanking (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LT\"");
- Prf_GetAndShowRankingSocPub ();
+ Prf_GetAndShowRankingTimelinePubs ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LT\"");
@@ -560,11 +560,11 @@ static void Fig_GetAndShowUsersRanking (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LT\"");
- Prf_GetAndShowRankingForPst ();
+ Prf_GetAndShowRankingForPsts ();
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LT\"");
- Prf_GetAndShowRankingMsgSnt ();
+ Prf_GetAndShowRankingMsgsSnt ();
HTM_TD_End ();
HTM_TR_End ();
diff --git a/swad_forum.c b/swad_forum.c
index 0f9603ce..7ed25515 100644
--- a/swad_forum.c
+++ b/swad_forum.c
@@ -53,6 +53,7 @@
#include "swad_pagination.h"
#include "swad_parameter.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_role.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
diff --git a/swad_log.c b/swad_log.c
index 54ae9afa..b28309f8 100644
--- a/swad_log.c
+++ b/swad_log.c
@@ -42,6 +42,7 @@
#include "swad_log.h"
#include "swad_log_database.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_role.h"
#include "swad_statistic.h"
diff --git a/swad_log_database.c b/swad_log_database.c
index 91026742..a2fc2d1b 100644
--- a/swad_log_database.c
+++ b/swad_log_database.c
@@ -197,6 +197,34 @@ unsigned Log_DB_GetLastClicks (MYSQL_RES **mysql_res)
" LIMIT 20");
}
+/*****************************************************************************/
+/*** Get first click of a user from log table and store in user's figures ****/
+/*****************************************************************************/
+
+unsigned Log_DB_GetUsrFirstClick (MYSQL_RES **mysql_res,long UsrCod)
+ {
+ return (unsigned)
+ DB_QuerySELECT (mysql_res,"can not get user's first click",
+ "SELECT UNIX_TIMESTAMP((SELECT MIN(ClickTime)"
+ " FROM log"
+ " WHERE UsrCod=%ld))",
+ UsrCod);
+ }
+
+/*****************************************************************************/
+/********************** Get number of clicks of a user ***********************/
+/*****************************************************************************/
+
+unsigned Log_DB_GetUsrNumClicks (long UsrCod)
+ {
+ return (unsigned)
+ DB_QueryCOUNT ("can not get number of clicks",
+ "SELECT COUNT(*)"
+ " FROM log"
+ " WHERE UsrCod=%ld",
+ UsrCod);
+ }
+
/*****************************************************************************/
/************ Sometimes, we delete old entries in recent log table ***********/
/*****************************************************************************/
diff --git a/swad_log_database.h b/swad_log_database.h
index e11157b7..473730b6 100644
--- a/swad_log_database.h
+++ b/swad_log_database.h
@@ -47,6 +47,8 @@ void Log_DB_LogAPI (long LogCod);
void Log_DB_LogBanner (long LogCod,long BanCodClicked);
unsigned Log_DB_GetLastClicks (MYSQL_RES **mysql_res);
+unsigned Log_DB_GetUsrFirstClick (MYSQL_RES **mysql_res,long UsrCod);
+unsigned Log_DB_GetUsrNumClicks (long UsrCod);
void Log_DB_RemoveOldEntriesRecentLog (void);
diff --git a/swad_message.c b/swad_message.c
index 1844d6ed..91cf9a3c 100644
--- a/swad_message.c
+++ b/swad_message.c
@@ -57,6 +57,7 @@
#include "swad_parameter.h"
#include "swad_photo.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_user.h"
/*****************************************************************************/
diff --git a/swad_profile.c b/swad_profile.c
index a605a0ff..3216e8fa 100644
--- a/swad_profile.c
+++ b/swad_profile.c
@@ -44,6 +44,7 @@
#include "swad_hierarchy_level.h"
#include "swad_HTML.h"
#include "swad_language.h"
+#include "swad_log_database.h"
#include "swad_message.h"
#include "swad_message_database.h"
#include "swad_network.h"
@@ -54,6 +55,7 @@
#include "swad_photo.h"
#include "swad_privacy.h"
#include "swad_profile.h"
+#include "swad_profile_database.h"
#include "swad_role.h"
#include "swad_role_type.h"
#include "swad_setting.h"
@@ -97,8 +99,8 @@ static void Prf_ShowNumClicks (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
-static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
- const struct UsrFigures *UsrFigures);
+static void Prf_ShowNumTimelinePubs (const struct UsrData *UsrDat,
+ const struct UsrFigures *UsrFigures);
static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
const struct UsrFigures *UsrFigures);
static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
@@ -107,15 +109,11 @@ static void Prf_BeginListItem (const char *Title,const char *Icon);
static void Prf_EndListItem (void);
static void Prf_PutLinkCalculateFigures (const char *EncryptedUsrCod);
-static unsigned Prf_DB_GetRankingFigure (long UsrCod,const char *FieldName);
-static unsigned Prf_DB_GetNumUsrsWithFigure (const char *FieldName);
-static unsigned Prf_DB_GetRankingNumClicksPerDay (long UsrCod);
-static unsigned Prf_DB_GetNumUsrsWithNumClicksPerDay (void);
static void Prf_ShowRanking (unsigned Rank,unsigned NumUsrs);
static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod);
-static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod);
+static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod);
static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod);
@@ -123,7 +121,6 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod);
static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures);
static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigures,
bool CreatingMyOwnAccount);
-static bool Prf_DB_CheckIfUsrFiguresExists (long UsrCod);
static void Prf_GetAndShowRankingFigure (const char *FieldName);
static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank,bool ItsMe);
@@ -243,7 +240,6 @@ void Prf_RequestUserProfile (void)
void Prf_GetUsrDatAndShowUserProfile (void)
{
struct Tml_Timeline Timeline;
- bool ItsMe;
bool ProfileShown = false;
/***** Get user's data *****/
@@ -282,11 +278,10 @@ void Prf_GetUsrDatAndShowUserProfile (void)
}
/***** If it's not me, mark possible notification as seen *****/
- ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
- if (!ItsMe) // Not me
+ if (!Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod)) // Not me
Ntf_DB_MarkNotifAsSeen (Ntf_EVENT_FOLLOWER,
- Gbl.Usrs.Other.UsrDat.UsrCod,-1L,
- Gbl.Usrs.Me.UsrDat.UsrCod);
+ Gbl.Usrs.Other.UsrDat.UsrCod,-1L,
+ Gbl.Usrs.Me.UsrDat.UsrCod);
}
/*****************************************************************************/
@@ -364,20 +359,12 @@ bool Prf_ShowUserProfile (struct UsrData *UsrDat)
void Prf_ChangeBasicProfileVis (void)
{
- extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
-
/***** Get param with public/private photo *****/
Gbl.Usrs.Me.UsrDat.BaPrfVisibility = Pri_GetParamVisibility ("VisBasPrf",
Pri_BASIC_PROFILE_ALLOWED_VIS);
- /***** Store public/private photo in database *****/
- DB_QueryUPDATE ("can not update your setting"
- " about public profile visibility",
- "UPDATE usr_data"
- " SET BaPrfVisibility='%s'"
- " WHERE UsrCod=%ld",
- Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.BaPrfVisibility],
- Gbl.Usrs.Me.UsrDat.UsrCod);
+ /***** Store public/private basic profile visibility in database *****/
+ Set_DB_UpdateMySettingsAboutBasicProfile ();
/***** Show form again *****/
Set_EditSettings ();
@@ -385,20 +372,12 @@ void Prf_ChangeBasicProfileVis (void)
void Prf_ChangeExtendedProfileVis (void)
{
- extern const char *Pri_VisibilityDB[Pri_NUM_OPTIONS_PRIVACY];
-
/***** Get param with public/private photo *****/
Gbl.Usrs.Me.UsrDat.ExPrfVisibility = Pri_GetParamVisibility ("VisExtPrf",
Pri_EXTENDED_PROFILE_ALLOWED_VIS);
- /***** Store public/private photo in database *****/
- DB_QueryUPDATE ("can not update your setting"
- " about public profile visibility",
- "UPDATE usr_data"
- " SET ExPrfVisibility='%s'"
- " WHERE UsrCod=%ld",
- Pri_VisibilityDB[Gbl.Usrs.Me.UsrDat.ExPrfVisibility],
- Gbl.Usrs.Me.UsrDat.UsrCod);
+ /***** Store public/private extended profile visibility in database *****/
+ Set_DB_UpdateMySettingsAboutExtendedProfile ();
/***** Show form again *****/
Set_EditSettings ();
@@ -453,8 +432,8 @@ void Prf_ShowDetailsUserProfile (const struct UsrData *UsrDat)
/* Number of file views */
Prf_ShowNumFileViews (UsrDat,&UsrFigures);
- /* Number of social publications */
- Prf_ShowNumSocialPublications (UsrDat,&UsrFigures);
+ /* Number of timeline publications */
+ Prf_ShowNumTimelinePubs (UsrDat,&UsrFigures);
/* Number of posts in forums */
Prf_ShowNumForumPosts (UsrDat,&UsrFigures);
@@ -674,36 +653,36 @@ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
}
/*****************************************************************************/
-/*********** Show number of social publications in user's profile ************/
+/********* Show number of timeline publications in user's profile ************/
/*****************************************************************************/
-static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
- const struct UsrFigures *UsrFigures)
+static void Prf_ShowNumTimelinePubs (const struct UsrData *UsrDat,
+ const struct UsrFigures *UsrFigures)
{
extern const char *Txt_Timeline;
extern const char *Txt_TIMELINE_post;
extern const char *Txt_TIMELINE_posts;
extern const char *Txt_day;
- /***** Number of social publications *****/
+ /***** Number of timeline publications *****/
Prf_BeginListItem (Txt_Timeline,"comment-dots.svg");
- if (UsrFigures->NumSocPub >= 0)
+ if (UsrFigures->NumTimelinePubs >= 0)
{
- HTM_Int (UsrFigures->NumSocPub);
- HTM_TxtF (" %s ",UsrFigures->NumSocPub == 1 ? Txt_TIMELINE_post :
+ HTM_Int (UsrFigures->NumTimelinePubs);
+ HTM_TxtF (" %s ",UsrFigures->NumTimelinePubs == 1 ? Txt_TIMELINE_post :
Txt_TIMELINE_posts);
Prf_ShowRanking (Prf_DB_GetRankingFigure (UsrDat->UsrCod,"NumSocPub"),
Prf_DB_GetNumUsrsWithFigure ("NumSocPub"));
if (UsrFigures->NumDays > 0)
{
HTM_TxtF (" %s","(");
- HTM_DoubleFewDigits ((double) UsrFigures->NumSocPub /
+ HTM_DoubleFewDigits ((double) UsrFigures->NumTimelinePubs /
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
}
- else // Number of social publications is unknown
+ else // Number of timeline publications is unknown
/***** Button to fetch and store user's figures *****/
Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
@@ -711,7 +690,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
}
/*****************************************************************************/
-/*********** Show number of social publications in user's profile ************/
+/********** Show number of timeline publications in user's profile ***********/
/*****************************************************************************/
static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
@@ -725,17 +704,17 @@ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
/***** Number of posts in forums *****/
Prf_BeginListItem (Txt_Forums,"comments.svg");
- if (UsrFigures->NumForPst >= 0)
+ if (UsrFigures->NumForumPosts >= 0)
{
- HTM_Long (UsrFigures->NumForPst);
- HTM_TxtF (" %s ",UsrFigures->NumForPst == 1 ? Txt_FORUM_post :
+ HTM_Long (UsrFigures->NumForumPosts);
+ HTM_TxtF (" %s ",UsrFigures->NumForumPosts == 1 ? Txt_FORUM_post :
Txt_FORUM_posts);
Prf_ShowRanking (Prf_DB_GetRankingFigure (UsrDat->UsrCod,"NumForPst"),
Prf_DB_GetNumUsrsWithFigure ("NumForPst"));
if (UsrFigures->NumDays > 0)
{
HTM_TxtF (" %s","(");
- HTM_DoubleFewDigits ((double) UsrFigures->NumForPst /
+ HTM_DoubleFewDigits ((double) UsrFigures->NumForumPosts /
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
@@ -762,17 +741,17 @@ static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
/***** Number of messages sent *****/
Prf_BeginListItem (Txt_Messages,"envelope.svg");
- if (UsrFigures->NumMsgSnt >= 0)
+ if (UsrFigures->NumMessagesSent >= 0)
{
- HTM_Long (UsrFigures->NumMsgSnt);
- HTM_TxtF (" %s ",UsrFigures->NumMsgSnt == 1 ? Txt_message :
+ HTM_Long (UsrFigures->NumMessagesSent);
+ HTM_TxtF (" %s ",UsrFigures->NumMessagesSent == 1 ? Txt_message :
Txt_messages);
Prf_ShowRanking (Prf_DB_GetRankingFigure (UsrDat->UsrCod,"NumMsgSnt"),
Prf_DB_GetNumUsrsWithFigure ("NumMsgSnt"));
if (UsrFigures->NumDays > 0)
{
HTM_TxtF (" %s","(");
- HTM_DoubleFewDigits ((double) UsrFigures->NumMsgSnt /
+ HTM_DoubleFewDigits ((double) UsrFigures->NumMessagesSent /
(double) UsrFigures->NumDays);
HTM_TxtF ("/%s)",Txt_day);
}
@@ -828,22 +807,9 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
- unsigned NumRows;
/***** Get user's figures from database *****/
- NumRows = (unsigned)
- DB_QuerySELECT (&mysql_res,"can not get user's figures",
- "SELECT UNIX_TIMESTAMP(FirstClickTime)," // row[0]
- "DATEDIFF(NOW(),FirstClickTime)+1," // row[1]
- "NumClicks," // row[2]
- "NumSocPub," // row[3]
- "NumFileViews," // row[4]
- "NumForPst," // row[5]
- "NumMsgSnt" // row[6]
- " FROM usr_figures"
- " WHERE UsrCod=%ld",
- UsrCod);
- if (NumRows)
+ if (Prf_DB_GetUsrFigures (&mysql_res,UsrCod))
{
/***** Get user's figures *****/
row = mysql_fetch_row (mysql_res);
@@ -864,21 +830,21 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
if (sscanf (row[2],"%d",&UsrFigures->NumClicks) != 1)
UsrFigures->NumClicks = -1;
- /* Get number of social publications (row[3]) */
- if (sscanf (row[3],"%d",&UsrFigures->NumSocPub) != 1)
- UsrFigures->NumSocPub = -1;
+ /* Get number of timeline publications (row[3]) */
+ if (sscanf (row[3],"%d",&UsrFigures->NumTimelinePubs) != 1)
+ UsrFigures->NumTimelinePubs = -1;
/* Get number of file views (row[4]) */
if (sscanf (row[4],"%d",&UsrFigures->NumFileViews) != 1)
UsrFigures->NumFileViews = -1;
/* Get number of forum posts (row[5]) */
- if (sscanf (row[5],"%d",&UsrFigures->NumForPst) != 1)
- UsrFigures->NumForPst = -1;
+ if (sscanf (row[5],"%d",&UsrFigures->NumForumPosts) != 1)
+ UsrFigures->NumForumPosts = -1;
/* Get number of messages sent (row[6]) */
- if (sscanf (row[6],"%d",&UsrFigures->NumMsgSnt) != 1)
- UsrFigures->NumMsgSnt = -1;
+ if (sscanf (row[6],"%d",&UsrFigures->NumMessagesSent) != 1)
+ UsrFigures->NumMessagesSent = -1;
}
else
/***** Return special user's figures indicating "not present" *****/
@@ -888,84 +854,6 @@ void Prf_GetUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
DB_FreeMySQLResult (&mysql_res);
}
-/*****************************************************************************/
-/********** Get ranking of a user according to the number of clicks **********/
-/*****************************************************************************/
-
-static unsigned Prf_DB_GetRankingFigure (long UsrCod,const char *FieldName)
- {
- /***** Select number of rows with figure
- greater than the figure of this user *****/
- return (unsigned)
- DB_QueryCOUNT ("can not get ranking using a figure",
- "SELECT COUNT(*)+1"
- " FROM usr_figures"
- " WHERE UsrCod<>%ld" // Really not necessary here
- " AND %s>(SELECT %s"
- " FROM usr_figures"
- " WHERE UsrCod=%ld)",
- UsrCod,
- FieldName,
- FieldName,
- UsrCod);
- }
-
-/*****************************************************************************/
-/********************* Get number of users with a figure *********************/
-/*****************************************************************************/
-
-static unsigned Prf_DB_GetNumUsrsWithFigure (const char *FieldName)
- {
- /***** Select number of rows with values already calculated *****/
- return (unsigned)
- DB_QueryCOUNT ("can not get number of users with a figure",
- "SELECT COUNT(*)"
- " FROM usr_figures"
- " WHERE %s>=0",
- FieldName);
- }
-
-/*****************************************************************************/
-/****** Get ranking of a user according to the number of clicks per day ******/
-/*****************************************************************************/
-
-static unsigned Prf_DB_GetRankingNumClicksPerDay (long UsrCod)
- {
- /***** Select number of rows with number of clicks per day
- greater than the clicks per day of this user *****/
- return (unsigned)
- DB_QueryCOUNT ("can not get ranking using number of clicks per day",
- "SELECT COUNT(*)+1"
- " FROM (SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1) AS NumClicksPerDay"
- " FROM usr_figures"
- " WHERE UsrCod<>%ld" // Necessary because the following comparison is not exact in floating point
- " AND NumClicks>0"
- " AND FirstClickTime>FROM_UNIXTIME(0)) AS TableNumClicksPerDay"
- " WHERE NumClicksPerDay>"
- "(SELECT NumClicks/(DATEDIFF(NOW(),FirstClickTime)+1)"
- " FROM usr_figures"
- " WHERE UsrCod=%ld"
- " AND NumClicks>0"
- " AND FirstClickTime>FROM_UNIXTIME(0))",
- UsrCod,
- UsrCod);
- }
-
-/*****************************************************************************/
-/************** Get number of users with number of clicks per day ************/
-/*****************************************************************************/
-
-static unsigned Prf_DB_GetNumUsrsWithNumClicksPerDay (void)
- {
- /***** Select number of rows with values already calculated *****/
- return (unsigned)
- DB_QueryCOUNT ("can not get number of users with number of clicks per day",
- "SELECT COUNT(*)"
- " FROM usr_figures"
- " WHERE NumClicks>0"
- " AND FirstClickTime>FROM_UNIXTIME(0)");
- }
-
/*****************************************************************************/
/************************* Show position in ranking **************************/
/*****************************************************************************/
@@ -1030,10 +918,10 @@ bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
Prf_GetNumClicksAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
- if (UsrFigures->NumSocPub < 0)
+ if (UsrFigures->NumTimelinePubs < 0)
{
- /***** Get number of social publications and store as user's figure *****/
- Prf_GetNumSocialPubsAndStoreAsUsrFigure (UsrCod);
+ /***** Get number of timeline publications and store as user's figure *****/
+ Prf_GetNumTimelinePubsAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
if (UsrFigures->NumFileViews < 0)
@@ -1042,13 +930,13 @@ bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures)
Prf_GetNumFileViewsAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
- if (UsrFigures->NumForPst < 0)
+ if (UsrFigures->NumForumPosts < 0)
{
/***** Get number of forum posts and store as user's figure *****/
Prf_GetNumForumPostsAndStoreAsUsrFigure (UsrCod);
UsrFiguresModified = true;
}
- if (UsrFigures->NumMsgSnt < 0)
+ if (UsrFigures->NumMessagesSent < 0)
{
/***** Get number of messages sent and store as user's figure *****/
Prf_GetNumMessagesSentAndStoreAsUsrFigure (UsrCod);
@@ -1074,11 +962,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get first click from log table *****/
- if (DB_QuerySELECT (&mysql_res,"can not get user's first click",
- "SELECT UNIX_TIMESTAMP((SELECT MIN(ClickTime)"
- " FROM log"
- " WHERE UsrCod=%ld))",
- UsrCod))
+ if (Log_DB_GetUsrFirstClick (&mysql_res,UsrCod))
{
/* Get first click */
row = mysql_fetch_row (mysql_res);
@@ -1092,12 +976,7 @@ static void Prf_GetFirstClickFromLogAndStoreAsUsrFigure (long UsrCod)
/***** Update first click time in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET FirstClickTime=FROM_UNIXTIME(%ld)"
- " WHERE UsrCod=%ld",
- (long) UsrFigures.FirstClickTimeUTC,
- UsrCod);
+ Prf_DB_UpdateFirstClickTimeUsr (UsrCod,UsrFigures.FirstClickTimeUTC);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@@ -1117,31 +996,21 @@ static void Prf_GetNumClicksAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of clicks from database *****/
- UsrFigures.NumClicks = (int)
- DB_QueryCOUNT ("can not get number of clicks",
- "SELECT COUNT(*)"
- " FROM log"
- " WHERE UsrCod=%ld",
- UsrCod);
+ UsrFigures.NumClicks = (int) Log_DB_GetUsrNumClicks (UsrCod);
/***** Update number of clicks in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET NumClicks=%ld"
- " WHERE UsrCod=%ld",
- UsrFigures.NumClicks,
- UsrCod);
+ Prf_DB_UpdateNumClicksUsr (UsrCod,UsrFigures.NumClicks);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
}
/*****************************************************************************/
-/* Get number of social publications from a user and store in user's figures */
+/**** Get number of timeline pubs. from a user and store in user's figures ***/
/*****************************************************************************/
-static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
+static void Prf_GetNumTimelinePubsAndStoreAsUsrFigure (long UsrCod)
{
struct UsrFigures UsrFigures;
@@ -1151,16 +1020,11 @@ static void Prf_GetNumSocialPubsAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of forum posts from database *****/
- UsrFigures.NumSocPub = (int) Tml_DB_GetNumPubsUsr (UsrCod);
+ UsrFigures.NumTimelinePubs = (int) Tml_DB_GetNumPubsUsr (UsrCod);
- /***** Update number of forum posts in user's figures *****/
+ /***** Update number of timeline publications in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET NumSocPub=%d"
- " WHERE UsrCod=%ld",
- UsrFigures.NumSocPub,
- UsrCod);
+ Prf_DB_UpdateNumTimelinePubsUsr (UsrCod,UsrFigures.NumTimelinePubs);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@@ -1184,12 +1048,7 @@ static void Prf_GetNumFileViewsAndStoreAsUsrFigure (long UsrCod)
/***** Update number of file views in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET NumFileViews=%d"
- " WHERE UsrCod=%ld",
- UsrFigures.NumFileViews,
- UsrCod);
+ Prf_DB_UpdateNumFileViewsUsr (UsrCod,UsrFigures.NumFileViews);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@@ -1209,16 +1068,11 @@ static void Prf_GetNumForumPostsAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of forum posts from database *****/
- UsrFigures.NumForPst = For_DB_GetNumPostsUsr (UsrCod);
+ UsrFigures.NumForumPosts = For_DB_GetNumPostsUsr (UsrCod);
/***** Update number of forum posts in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET NumForPst=%d"
- " WHERE UsrCod=%ld",
- UsrFigures.NumForPst,
- UsrCod);
+ Prf_DB_UpdateNumForumPostsUsr (UsrCod,UsrFigures.NumForumPosts);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@@ -1238,16 +1092,11 @@ static void Prf_GetNumMessagesSentAndStoreAsUsrFigure (long UsrCod)
Prf_ResetUsrFigures (&UsrFigures);
/***** Get number of messages sent from database *****/
- UsrFigures.NumMsgSnt = (int) Msg_DB_GetNumMsgsSentByUsr (UsrCod);
+ UsrFigures.NumMessagesSent = (int) Msg_DB_GetNumMsgsSentByUsr (UsrCod);
/***** Update number of messages sent in user's figures *****/
if (Prf_DB_CheckIfUsrFiguresExists (UsrCod))
- DB_QueryUPDATE ("can not update user's figures",
- "UPDATE usr_figures"
- " SET NumMsgSnt=%d"
- " WHERE UsrCod=%ld",
- UsrFigures.NumMsgSnt,
- UsrCod);
+ Prf_DB_UpdateNumMessagesSentUsr (UsrCod,UsrFigures.NumMessagesSent);
else // User entry does not exist
Prf_CreateUsrFigures (UsrCod,&UsrFigures,false);
}
@@ -1263,11 +1112,11 @@ void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount)
/***** Reset user's figures *****/
Prf_ResetUsrFigures (&UsrFigures);
- UsrFigures.NumClicks = 0; // set number of clicks to 0
- UsrFigures.NumSocPub = 0; // set number of social publications to 0
- UsrFigures.NumFileViews = 0; // set number of file views to 0
- UsrFigures.NumForPst = 0; // set number of forum posts to 0
- UsrFigures.NumMsgSnt = 0; // set number of messages sent to 0
+ UsrFigures.NumClicks = 0; // set number of clicks to 0
+ UsrFigures.NumTimelinePubs = 0; // set number of timeline publications to 0
+ UsrFigures.NumFileViews = 0; // set number of file views to 0
+ UsrFigures.NumForumPosts = 0; // set number of forum posts to 0
+ UsrFigures.NumMessagesSent = 0; // set number of messages sent to 0
/***** Create user's figures *****/
Prf_CreateUsrFigures (UsrCod,&UsrFigures,CreatingMyOwnAccount);
@@ -1280,12 +1129,12 @@ void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount)
static void Prf_ResetUsrFigures (struct UsrFigures *UsrFigures)
{
UsrFigures->FirstClickTimeUTC = (time_t) 0; // unknown first click time or user never logged
- UsrFigures->NumDays = -1; // not applicable
- UsrFigures->NumClicks = -1; // unknown number of clicks
- UsrFigures->NumSocPub = -1; // unknown number of social publications
- UsrFigures->NumFileViews = -1; // unknown number of file views
- UsrFigures->NumForPst = -1; // unknown number of forum posts
- UsrFigures->NumMsgSnt = -1; // unknown number of messages sent
+ UsrFigures->NumDays = -1; // not applicable
+ UsrFigures->NumClicks = -1; // unknown number of clicks
+ UsrFigures->NumTimelinePubs = -1; // unknown number of timeline publications
+ UsrFigures->NumFileViews = -1; // unknown number of file views
+ UsrFigures->NumForumPosts = -1; // unknown number of forum posts
+ UsrFigures->NumMessagesSent = -1; // unknown number of messages sent
}
/*****************************************************************************/
@@ -1316,116 +1165,11 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure
"%d,%d,%d,%d,%d)",
UsrCod,
SubQueryFirstClickTime,
- UsrFigures->NumClicks, // -1 ==> unknown number of clicks
- UsrFigures->NumSocPub, // -1 ==> unknown number of social publications
- UsrFigures->NumFileViews, // -1 ==> unknown number of file views
- UsrFigures->NumForPst, // -1 ==> unknown number of forum posts
- UsrFigures->NumMsgSnt); // -1 ==> unknown number of messages sent
- }
-
-/*****************************************************************************/
-/**************************** Remove user's figures **************************/
-/*****************************************************************************/
-
-void Prf_DB_RemoveUsrFigures (long UsrCod)
- {
- DB_QueryDELETE ("can not delete user's figures",
- "DELETE FROM usr_figures"
- " WHERE UsrCod=%ld",
- UsrCod);
- }
-
-/*****************************************************************************/
-/*** Check if it exists an entry for this user in table of user's figures ****/
-/*****************************************************************************/
-
-static bool Prf_DB_CheckIfUsrFiguresExists (long UsrCod)
- {
- return (DB_QueryCOUNT ("can not get user's first click",
- "SELECT COUNT(*)"
- " FROM usr_figures"
- " WHERE UsrCod=%ld",
- UsrCod) != 0);
- }
-
-/*****************************************************************************/
-/*************** Increment number of clicks made by a user *******************/
-/*****************************************************************************/
-
-void Prf_DB_IncrementNumClicksUsr (long UsrCod)
- {
- /***** Increment number of clicks *****/
- // If NumClicks < 0 ==> not yet calculated, so do nothing
- DB_QueryUPDATE ("can not increment user's clicks",
- "UPDATE IGNORE usr_figures"
- " SET NumClicks=NumClicks+1"
- " WHERE UsrCod=%ld"
- " AND NumClicks>=0",
- UsrCod);
- }
-
-/*****************************************************************************/
-/********* Increment number of social publications sent by a user ************/
-/*****************************************************************************/
-
-void Prf_DB_IncrementNumPubsUsr (long UsrCod)
- {
- /***** Increment number of social publications *****/
- // If NumSocPub < 0 ==> not yet calculated, so do nothing
- DB_QueryUPDATE ("can not increment user's social publications",
- "UPDATE IGNORE usr_figures"
- " SET NumSocPub=NumSocPub+1"
- " WHERE UsrCod=%ld"
- " AND NumSocPub>=0",
- UsrCod);
- }
-
-/*****************************************************************************/
-/************** Increment number of file views sent by a user ****************/
-/*****************************************************************************/
-
-void Prf_DB_IncrementNumFileViewsUsr (long UsrCod)
- {
- /***** Increment number of file views *****/
- // If NumFileViews < 0 ==> not yet calculated, so do nothing
- DB_QueryUPDATE ("can not increment user's file views",
- "UPDATE IGNORE usr_figures"
- " SET NumFileViews=NumFileViews+1"
- " WHERE UsrCod=%ld"
- " AND NumFileViews>=0",
- UsrCod);
- }
-
-/*****************************************************************************/
-/************* Increment number of forum posts sent by a user ****************/
-/*****************************************************************************/
-
-void Prf_DB_IncrementNumForPstUsr (long UsrCod)
- {
- /***** Increment number of forum posts *****/
- // If NumForPst < 0 ==> not yet calculated, so do nothing
- DB_QueryUPDATE ("can not increment user's forum posts",
- "UPDATE IGNORE usr_figures"
- " SET NumForPst=NumForPst+1"
- " WHERE UsrCod=%ld"
- " AND NumForPst>=0",
- UsrCod);
- }
-
-/*****************************************************************************/
-/*************** Increment number of messages sent by a user *****************/
-/*****************************************************************************/
-
-void Prf_DB_IncrementNumMsgSntUsr (long UsrCod)
- {
- /***** Increment number of messages sent *****/
- // If NumMsgSnt < 0 ==> not yet calculated, so do nothing
- DB_QueryUPDATE ("can not increment user's messages sent",
- "UPDATE IGNORE usr_figures"
- " SET NumMsgSnt=NumMsgSnt+1"
- " WHERE UsrCod=%ld"
- " AND NumMsgSnt>=0",
- UsrCod);
+ UsrFigures->NumClicks, // -1 ==> unknown number of clicks
+ UsrFigures->NumTimelinePubs, // -1 ==> unknown number of timeline publications
+ UsrFigures->NumFileViews, // -1 ==> unknown number of file views
+ UsrFigures->NumForumPosts, // -1 ==> unknown number of forum posts
+ UsrFigures->NumMessagesSent); // -1 ==> unknown number of messages sent
}
/*****************************************************************************/
@@ -1437,7 +1181,7 @@ void Prf_GetAndShowRankingClicks (void)
Prf_GetAndShowRankingFigure ("NumClicks");
}
-void Prf_GetAndShowRankingSocPub (void)
+void Prf_GetAndShowRankingTimelinePubs (void)
{
Prf_GetAndShowRankingFigure ("NumSocPub");
}
@@ -1447,12 +1191,12 @@ void Prf_GetAndShowRankingFileViews (void)
Prf_GetAndShowRankingFigure ("NumFileViews");
}
-void Prf_GetAndShowRankingForPst (void)
+void Prf_GetAndShowRankingForPsts (void)
{
Prf_GetAndShowRankingFigure ("NumForPst");
}
-void Prf_GetAndShowRankingMsgSnt (void)
+void Prf_GetAndShowRankingMsgsSnt (void)
{
Prf_GetAndShowRankingFigure ("NumMsgSnt");
}
diff --git a/swad_profile.h b/swad_profile.h
index 9a34ba73..a1d5daac 100644
--- a/swad_profile.h
+++ b/swad_profile.h
@@ -40,10 +40,10 @@ struct UsrFigures
time_t FirstClickTimeUTC; // 0 ==> unknown first click time of user never logged
int NumDays; // -1 ==> not applicable
int NumClicks; // -1 ==> unknown number of clicks
- int NumSocPub; // -1 ==> unknown number of social publications
+ int NumTimelinePubs; // -1 ==> unknown number of timeline publications
int NumFileViews; // -1 ==> unknown number of file views
- int NumForPst; // -1 ==> unknown number of forum posts
- int NumMsgSnt; // -1 ==> unknown number of messages sent
+ int NumForumPosts; // -1 ==> unknown number of forum posts
+ int NumMessagesSent; // -1 ==> unknown number of messages sent
};
/*****************************************************************************/
@@ -69,18 +69,12 @@ void Prf_CalculateFigures (void);
bool Prf_GetAndStoreAllUsrFigures (long UsrCod,struct UsrFigures *UsrFigures);
void Prf_CreateNewUsrFigures (long UsrCod,bool CreatingMyOwnAccount);
-void Prf_DB_RemoveUsrFigures (long UsrCod);
-void Prf_DB_IncrementNumClicksUsr (long UsrCod);
-void Prf_DB_IncrementNumPubsUsr (long UsrCod);
-void Prf_DB_IncrementNumFileViewsUsr (long UsrCod);
-void Prf_DB_IncrementNumForPstUsr (long UsrCod);
-void Prf_DB_IncrementNumMsgSntUsr (long UsrCod);
void Prf_GetAndShowRankingClicks (void);
-void Prf_GetAndShowRankingSocPub (void);
+void Prf_GetAndShowRankingTimelinePubs (void);
void Prf_GetAndShowRankingFileViews (void);
-void Prf_GetAndShowRankingForPst (void);
-void Prf_GetAndShowRankingMsgSnt (void);
+void Prf_GetAndShowRankingForPsts (void);
+void Prf_GetAndShowRankingMsgsSnt (void);
void Prf_ShowRankingFigure (MYSQL_RES **mysql_res,unsigned NumUsrs);
void Prf_GetAndShowRankingClicksPerDay (void);
diff --git a/swad_profile_database.c b/swad_profile_database.c
new file mode 100644
index 00000000..0289984d
--- /dev/null
+++ b/swad_profile_database.c
@@ -0,0 +1,342 @@
+// swad_profile_database.c: user's public profile, operations with database
+
+/*
+ SWAD (Shared Workspace At a Distance),
+ is a web platform developed at the University of Granada (Spain),
+ and used to support university teaching.
+
+ This file is part of SWAD core.
+ Copyright (C) 1999-2021 Antonio Caņas Vargas
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General 3 License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see