diff --git a/swad_changelog.h b/swad_changelog.h index 00d72900..970825fe 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.31.1 (2021-10-13)" +#define Log_PLATFORM_VERSION "SWAD 21.31.2 (2021-10-13)" #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.31.2: Oct 13, 2021 Queries moved to module swad_log_database. (319542 lines) Version 21.31.1: Oct 13, 2021 Queries moved to module swad_log_database. (319520 lines) Version 21.31: Oct 13, 2021 New module swad_report_database for database queries related to user reports. (319475 lines) Version 21.30.1: Oct 13, 2021 Queries moved to module swad_record_database. (319411 lines) diff --git a/swad_log_database.c b/swad_log_database.c index a4328552..4df8e668 100644 --- a/swad_log_database.c +++ b/swad_log_database.c @@ -323,8 +323,8 @@ unsigned Log_DB_GetMyCrssAndHitsPerCrs (MYSQL_RES **mysql_res,Rol_Role_t Role) /************************** Get my historic courses **************************/ /*****************************************************************************/ -unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res,Rol_Role_t Role, - unsigned MinClicksCrs) +unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res, + Rol_Role_t Role,unsigned MinClicksCrs) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get courses of a user", @@ -342,6 +342,44 @@ unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res,Rol_Role_t Role, MinClicksCrs); } +/*****************************************************************************/ +/********************** Write my hits grouped by years ***********************/ +/*****************************************************************************/ + +unsigned Log_DB_GetMyHitsPerYear (MYSQL_RES **mysql_res, + bool AnyCourse,long CrsCod,Rol_Role_t Role, + time_t FirstClickTimeUTC) + { + char SubQueryCrs[128]; + char SubQueryRol[128]; + + if (AnyCourse) + SubQueryCrs[0] = '\0'; + else + sprintf (SubQueryCrs," AND CrsCod=%ld",CrsCod); + + if (Role == Rol_UNK) // Here Rol_UNK means any role + SubQueryRol[0] = '\0'; + else + sprintf (SubQueryRol," AND Role=%u",(unsigned) Role); + + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get clicks", + "SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0] + "COUNT(*)" // row[1] + " FROM log" + " WHERE ClickTime>=FROM_UNIXTIME(%ld)" + " AND UsrCod=%ld" + "%s" + "%s" + " GROUP BY Year" + " ORDER BY Year DESC", + (long) FirstClickTimeUTC, + Gbl.Usrs.Me.UsrDat.UsrCod, + SubQueryCrs, + SubQueryRol); + } + /*****************************************************************************/ /************ Sometimes, we delete old entries in recent log table ***********/ /*****************************************************************************/ diff --git a/swad_log_database.h b/swad_log_database.h index 219500ea..63d79099 100644 --- a/swad_log_database.h +++ b/swad_log_database.h @@ -55,8 +55,11 @@ unsigned Log_DB_GetMyClicksGroupedByAction (MYSQL_RES **mysql_res, unsigned Log_DB_GetMyMaxHitsPerYear (MYSQL_RES **mysql_res, time_t FirstClickTimeUTC); unsigned Log_DB_GetMyCrssAndHitsPerCrs (MYSQL_RES **mysql_res,Rol_Role_t Role); -unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res,Rol_Role_t Role, - unsigned MinClicksCrs); +unsigned Log_DB_GetMyHistoricCrss (MYSQL_RES **mysql_res, + Rol_Role_t Role,unsigned MinClicksCrs); +unsigned Log_DB_GetMyHitsPerYear (MYSQL_RES **mysql_res, + bool AnyCourse,long CrsCod,Rol_Role_t Role, + time_t FirstClickTimeUTC); void Log_DB_RemoveOldEntriesRecentLog (void); diff --git a/swad_report.c b/swad_report.c index 51a54bb3..fe784dec 100644 --- a/swad_report.c +++ b/swad_report.c @@ -1094,8 +1094,6 @@ static void Rep_WriteRowCrsData (long CrsCod,Rol_Role_t Role, static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, struct Rep_Report *Report) { - char SubQueryCrs[128]; - char SubQueryRol[128]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumHits; @@ -1106,31 +1104,8 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, unsigned Year; /***** Make the query *****/ - if (AnyCourse) - SubQueryCrs[0] = '\0'; - else - sprintf (SubQueryCrs," AND CrsCod=%ld",CrsCod); - - if (Role == Rol_UNK) // Here Rol_UNK means any role - SubQueryRol[0] = '\0'; - else - sprintf (SubQueryRol," AND Role=%u",(unsigned) Role); - - NumHits = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get clicks", - "SELECT SQL_NO_CACHE YEAR(CONVERT_TZ(ClickTime,@@session.time_zone,'UTC')) AS Year," // row[0] - "COUNT(*)" // row[1] - " FROM log" - " WHERE ClickTime>=FROM_UNIXTIME(%ld)" - " AND UsrCod=%ld" - "%s" - "%s" - " GROUP BY Year" - " ORDER BY Year DESC", - (long) Report->UsrFigures.FirstClickTimeUTC, - Gbl.Usrs.Me.UsrDat.UsrCod, - SubQueryCrs, - SubQueryRol); + NumHits = Log_DB_GetMyHitsPerYear (&mysql_res,AnyCourse,CrsCod,Role, + Report->UsrFigures.FirstClickTimeUTC); /***** Initialize first year *****/ FirstYear = 1900 + Report->tm_FirstClickTime.tm_year; @@ -1150,7 +1125,7 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role, } /***** Write rows *****/ - for (NumHit = 1; + for (NumHit = 1; NumHit <= NumHits; NumHit++) { @@ -1209,7 +1184,7 @@ static void Rep_ComputeMaxAndTotalHits (struct Rep_Hits *Hits, MYSQL_ROW row; /***** For each row... *****/ - for (NumHit = 1, Hits->Max = 0; + for (NumHit = 1, Hits->Max = 0; NumHit <= NumHits; NumHit++) { @@ -1302,13 +1277,7 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod) char PathUniqueDirReport[PATH_MAX + 1]; /***** Get directories for the reports *****/ - NumReports = (unsigned) - DB_QuerySELECT (&mysql_res,"can not get user's usage reports", - "SELECT UniqueDirL," // row[0] - "UniqueDirR" // row[1] - " FROM usr_reports" - " WHERE UsrCod=%ld", - UsrCod); + NumReports = Rep_DB_GetUsrReportsFiles (&mysql_res,UsrCod); /***** Remove the reports *****/ for (NumReport = 0; diff --git a/swad_report_database.c b/swad_report_database.c index cfeb288d..5baddb63 100644 --- a/swad_report_database.c +++ b/swad_report_database.c @@ -98,6 +98,21 @@ void Rep_DB_CreateNewReport (long UsrCod,const struct Rep_Report *Report, Report->Permalink); } +/*****************************************************************************/ +/********************** Get directories for the reports **********************/ +/*****************************************************************************/ + +unsigned Rep_DB_GetUsrReportsFiles (MYSQL_RES **mysql_res,long UsrCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get user's usage reports", + "SELECT UniqueDirL," // row[0] + "UniqueDirR" // row[1] + " FROM usr_reports" + " WHERE UsrCod=%ld", + UsrCod); + } + /*****************************************************************************/ /********** Remove all user's usage reports of a user from database **********/ /*****************************************************************************/ diff --git a/swad_report_database.h b/swad_report_database.h index 73846473..ebda1da3 100644 --- a/swad_report_database.h +++ b/swad_report_database.h @@ -45,6 +45,8 @@ void Rep_DB_CreateNewReport (long UsrCod,const struct Rep_Report *Report, const char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]); +unsigned Rep_DB_GetUsrReportsFiles (MYSQL_RES **mysql_res,long UsrCod); + void Rep_DB_RemoveUsrReports (long UsrCod); #endif