mirror of https://github.com/acanas/swad-core.git
Version 21.5.3: Sep 16, 2021 Queries moved to module swad_forum_database.
This commit is contained in:
parent
b3dad62d7a
commit
01b03ada43
|
@ -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.5.2 (2021-09-16)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.5.3 (2021-09-16)"
|
||||
#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.5.3: Sep 16, 2021 Queries moved to module swad_forum_database. (315431 lines)
|
||||
Version 21.5.2: Sep 16, 2021 Queries moved to module swad_forum_database. (315403 lines)
|
||||
Version 21.5.1: Sep 15, 2021 Queries moved to module swad_forum_database. (315348 lines)
|
||||
Version 21.5: Sep 15, 2021 New module swad_forum_database for database queries related to forums. (315354 lines)
|
||||
|
|
59
swad_forum.c
59
swad_forum.c
|
@ -1077,36 +1077,15 @@ static void For_WriteNumberOfPosts (const struct For_Forums *Forums,long UsrCod)
|
|||
{
|
||||
extern const char *Txt_FORUM_post;
|
||||
extern const char *Txt_FORUM_posts;
|
||||
char SubQuery[256];
|
||||
unsigned NumPsts;
|
||||
|
||||
/***** Star table cell *****/
|
||||
HTM_DIV_Begin ("class=\"AUTHOR_TXT LT\"");
|
||||
|
||||
/***** Get number of posts from database *****/
|
||||
if (Forums->Forum.Location > 0)
|
||||
sprintf (SubQuery," AND for_threads.Location=%ld",
|
||||
Forums->Forum.Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
NumPsts = (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of posts of a user in a forum",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM for_posts,"
|
||||
"for_threads"
|
||||
" WHERE for_posts.UsrCod=%ld"
|
||||
" AND for_posts.ThrCod=for_threads.ThrCod"
|
||||
" AND for_threads.ForumType=%u"
|
||||
"%s",
|
||||
UsrCod,
|
||||
(unsigned) Forums->Forum.Type,
|
||||
SubQuery);
|
||||
NumPsts = For_DB_GetNumPstsOfUsrInForum (&Forums->Forum,UsrCod);
|
||||
|
||||
/***** Write number of threads and number of posts *****/
|
||||
HTM_TxtF ("[%u %s]",NumPsts,NumPsts == 1 ? Txt_FORUM_post :
|
||||
Txt_FORUM_posts);
|
||||
|
||||
/***** End table cell *****/
|
||||
/***** Write number of posts *****/
|
||||
HTM_DIV_Begin ("class=\"AUTHOR_TXT LT\"");
|
||||
HTM_TxtF ("[%u %s]",NumPsts,NumPsts == 1 ? Txt_FORUM_post :
|
||||
Txt_FORUM_posts);
|
||||
HTM_DIV_End ();
|
||||
}
|
||||
|
||||
|
@ -1901,32 +1880,16 @@ void For_SetForumName (const struct For_Forum *Forum,
|
|||
static unsigned For_GetNumThrsWithNewPstsInForum (const struct For_Forum *Forum,
|
||||
unsigned NumThreads)
|
||||
{
|
||||
char SubQuery[256];
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
unsigned NumThrsWithNewPosts = NumThreads; // By default, all the threads are new to me
|
||||
|
||||
/***** Get last time I read this forum from database *****/
|
||||
if (Forum->Location > 0)
|
||||
sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the date of reading of a forum",
|
||||
"SELECT IFNULL(MAX(for_read.ReadTime)," // row[0]
|
||||
"FROM_UNIXTIME(0))" // row[1]
|
||||
" FROM for_read,"
|
||||
"for_threads"
|
||||
" WHERE for_read.UsrCod=%ld"
|
||||
" AND for_read.ThrCod=for_threads.ThrCod"
|
||||
" AND for_threads.ForumType=%u"
|
||||
"%s",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) Forum->Type,
|
||||
SubQuery))
|
||||
if (For_DB_GetLastTimeIReadForum (&mysql_res,Forum))
|
||||
{
|
||||
/***** Get number of threads with a last message modify time > newest read time (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
NumThrsWithNewPosts = For_DB_GetNumOfThreadsInForumNewerThan (Forum,row[0]);
|
||||
NumThrsWithNewPosts = For_DB_GetNumThrsInForumNewerThan (Forum,row[0]);
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
|
@ -1946,13 +1909,7 @@ static unsigned For_GetNumOfUnreadPostsInThr (long ThrCod,unsigned NumPostsInThr
|
|||
unsigned NumUnreadPosts = NumPostsInThr; // By default, all the posts are unread by me
|
||||
|
||||
/***** Get last time I read this thread from database *****/
|
||||
if (DB_QuerySELECT (&mysql_res,"can not get the date of reading of a thread",
|
||||
"SELECT ReadTime" // row[0]
|
||||
" FROM for_read"
|
||||
" WHERE ThrCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
ThrCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod))
|
||||
if (For_DB_GetLastTimeIReadThread (&mysql_res,ThrCod))
|
||||
{
|
||||
/***** Get the number of posts in thread with a modify time > newest read time for me (row[0]) *****/
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
|
|
@ -79,8 +79,8 @@ unsigned For_DB_GetNumThrsInForum (const struct For_Forum *Forum)
|
|||
/**** Get number of threads in forum with a modify time > a specified time ***/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned For_DB_GetNumOfThreadsInForumNewerThan (const struct For_Forum *Forum,
|
||||
const char *Time)
|
||||
unsigned For_DB_GetNumThrsInForumNewerThan (const struct For_Forum *Forum,
|
||||
const char *Time)
|
||||
{
|
||||
char SubQuery[256];
|
||||
|
||||
|
@ -105,6 +105,35 @@ unsigned For_DB_GetNumOfThreadsInForumNewerThan (const struct For_Forum *Forum,
|
|||
Time);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************** Get number of posts of a user in a forum ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned For_DB_GetNumPstsOfUsrInForum (const struct For_Forum *Forum,
|
||||
long UsrCod)
|
||||
{
|
||||
char SubQuery[256];
|
||||
|
||||
/***** Get number of posts from database *****/
|
||||
if (Forum->Location > 0)
|
||||
sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get the number of posts of a user in a forum",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM for_posts,"
|
||||
"for_threads"
|
||||
" WHERE for_posts.UsrCod=%ld"
|
||||
" AND for_posts.ThrCod=for_threads.ThrCod"
|
||||
" AND for_threads.ForumType=%u"
|
||||
"%s",
|
||||
UsrCod,
|
||||
(unsigned) Forum->Type,
|
||||
SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Remove all the threads and posts in forums of a scope ***********/
|
||||
/*****************************************************************************/
|
||||
|
@ -675,6 +704,50 @@ unsigned For_DB_GetThrReadTime (MYSQL_RES **mysql_res,long ThrCod)
|
|||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get last time I read a forum ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned For_DB_GetLastTimeIReadForum (MYSQL_RES **mysql_res,
|
||||
const struct For_Forum *Forum)
|
||||
{
|
||||
char SubQuery[256];
|
||||
|
||||
if (Forum->Location > 0)
|
||||
sprintf (SubQuery," AND for_threads.Location=%ld",Forum->Location);
|
||||
else
|
||||
SubQuery[0] = '\0';
|
||||
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get the date of reading of a forum",
|
||||
"SELECT IFNULL(MAX(for_read.ReadTime),FROM_UNIXTIME(0))" // row[0]
|
||||
" FROM for_read,"
|
||||
"for_threads"
|
||||
" WHERE for_read.UsrCod=%ld"
|
||||
" AND for_read.ThrCod=for_threads.ThrCod"
|
||||
" AND for_threads.ForumType=%u"
|
||||
"%s",
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
(unsigned) Forum->Type,
|
||||
SubQuery);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get last time I read a thread ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned For_DB_GetLastTimeIReadThread (MYSQL_RES **mysql_res,long ThrCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get the date of reading of a thread",
|
||||
"SELECT ReadTime" // row[0]
|
||||
" FROM for_read"
|
||||
" WHERE ThrCod=%ld"
|
||||
" AND UsrCod=%ld",
|
||||
ThrCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Remove thread read status for a thread ****************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -39,8 +39,10 @@
|
|||
|
||||
//------------------------------- Forums --------------------------------------
|
||||
unsigned For_DB_GetNumThrsInForum (const struct For_Forum *Forum);
|
||||
unsigned For_DB_GetNumOfThreadsInForumNewerThan (const struct For_Forum *Forum,
|
||||
const char *Time);
|
||||
unsigned For_DB_GetNumThrsInForumNewerThan (const struct For_Forum *Forum,
|
||||
const char *Time);
|
||||
unsigned For_DB_GetNumPstsOfUsrInForum (const struct For_Forum *Forum,
|
||||
long UsrCod);
|
||||
void For_DB_RemoveForums (HieLvl_Level_t Scope,long ForumLocation);
|
||||
|
||||
//------------------------------- Posts ---------------------------------------
|
||||
|
@ -81,6 +83,9 @@ void For_DB_UpdateThrReadTime (long ThrCod,
|
|||
time_t CreatTimeUTCOfTheMostRecentPostRead);
|
||||
unsigned For_DB_GetNumReadersOfThr (long ThrCod);
|
||||
unsigned For_DB_GetThrReadTime (MYSQL_RES **mysql_res,long ThrCod);
|
||||
unsigned For_DB_GetLastTimeIReadForum (MYSQL_RES **mysql_res,
|
||||
const struct For_Forum *Forum);
|
||||
unsigned For_DB_GetLastTimeIReadThread (MYSQL_RES **mysql_res,long ThrCod);
|
||||
void For_DB_RemoveThrFromReadThrs (long ThrCod);
|
||||
void For_DB_RemoveUsrFromReadThrs (long UsrCod);
|
||||
|
||||
|
|
Loading…
Reference in New Issue