Version 20.36.6: Feb 27, 2021 Queries moved to module swad_timeline_database.

This commit is contained in:
acanas 2021-02-27 13:17:15 +01:00
parent fd781508a2
commit 850fb99b00
4 changed files with 72 additions and 56 deletions

View File

@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.36.5 (2021-02-26)" #define Log_PLATFORM_VERSION "SWAD 20.36.6 (2021-02-07)"
#define CSS_FILE "swad20.33.9.css" #define CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err
TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede.
TODO: Salvador Romero Cortés: @acanas opción para editar posts TODO: Salvador Romero Cortés: @acanas opción para editar posts
Version 20.36.6: Feb 27, 2021 Queries moved to module swad_timeline_database. (305195 lines)
Version 20.36.5: Feb 26, 2021 Queries moved to module swad_timeline_database. (305179 lines) Version 20.36.5: Feb 26, 2021 Queries moved to module swad_timeline_database. (305179 lines)
Version 20.36.4: Feb 26, 2021 Query moved to module swad_timeline_database. (305156 lines) Version 20.36.4: Feb 26, 2021 Query moved to module swad_timeline_database. (305156 lines)
Version 20.36.3: Feb 26, 2021 Query moved to module swad_timeline_database. (305140 lines) Version 20.36.3: Feb 26, 2021 Query moved to module swad_timeline_database. (305140 lines)

View File

@ -88,8 +88,8 @@ static void TL_Com_WriteAuthorTimeAndContent (struct TL_Com_Comment *Com,
static void TL_Com_WriteAuthorName (const struct UsrData *UsrDat); static void TL_Com_WriteAuthorName (const struct UsrData *UsrDat);
static void TL_Com_WriteContent (struct TL_Com_Comment *Com); static void TL_Com_WriteContent (struct TL_Com_Comment *Com);
static void TL_Com_WriteButtons (const struct TL_Timeline *Timeline, static void TL_Com_WriteButtons (const struct TL_Timeline *Timeline,
const struct TL_Com_Comment *Com, const struct TL_Com_Comment *Com,
const struct UsrData *UsrDat); const struct UsrData *UsrDat);
static void TL_Com_PutFormToRemoveComment (const struct TL_Timeline *Timeline, static void TL_Com_PutFormToRemoveComment (const struct TL_Timeline *Timeline,
long PubCod); long PubCod);
@ -100,7 +100,8 @@ static void TL_Com_RequestRemovalComment (struct TL_Timeline *Timeline);
static void TL_Com_PutParamsRemoveComment (void *Timeline); static void TL_Com_PutParamsRemoveComment (void *Timeline);
static void TL_Com_RemoveComment (void); static void TL_Com_RemoveComment (void);
static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Com_Comment *Com); static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,
struct TL_Com_Comment *Com);
static void TL_Com_ResetComment (struct TL_Com_Comment *Com); static void TL_Com_ResetComment (struct TL_Com_Comment *Com);
@ -599,8 +600,8 @@ static void TL_Com_WriteContent (struct TL_Com_Comment *Com)
/*****************************************************************************/ /*****************************************************************************/
static void TL_Com_WriteButtons (const struct TL_Timeline *Timeline, static void TL_Com_WriteButtons (const struct TL_Timeline *Timeline,
const struct TL_Com_Comment *Com, const struct TL_Com_Comment *Com,
const struct UsrData *UsrDat) // Author const struct UsrData *UsrDat) // Author
{ {
static unsigned NumDiv = 0; // Used to create unique div id for fav static unsigned NumDiv = 0; // Used to create unique div id for fav
@ -952,7 +953,7 @@ void TL_Com_RemoveCommentMediaAndDBEntries (long PubCod)
/***** Remove content of this comment *****/ /***** Remove content of this comment *****/
TL_DB_RemoveCommentContent (PubCod); TL_DB_RemoveCommentContent (PubCod);
/***** Remove this comment *****/ /***** Remove this comment publication *****/
TL_DB_RemoveCommentPub (PubCod,Gbl.Usrs.Me.UsrDat.UsrCod); TL_DB_RemoveCommentPub (PubCod,Gbl.Usrs.Me.UsrDat.UsrCod);
} }
@ -968,18 +969,7 @@ void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com)
if (Com->PubCod > 0) if (Com->PubCod > 0)
{ {
/***** Get data of comment from database *****/ /***** Get data of comment from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of comment", if (TL_DB_GetDataOfCommByCod (Com->PubCod,&mysql_res))
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2]
"UNIX_TIMESTAMP(tl_pubs.TimePublish)," // row[3]
"tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments"
" WHERE tl_pubs.PubCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
Com->PubCod,(unsigned) TL_Pub_COMMENT_TO_NOTE))
{ {
/***** Get data of comment *****/ /***** Get data of comment *****/
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -1001,37 +991,33 @@ void TL_Com_GetDataOfCommByCod (struct TL_Com_Comment *Com)
/********************** Get data of comment from row *************************/ /********************** Get data of comment from row *************************/
/*****************************************************************************/ /*****************************************************************************/
static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Com_Comment *Com) static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,
struct TL_Com_Comment *Com)
{ {
/* /*
row[0]: PubCod row[0]: PubCod
row[1]: PublisherCod row[1]: PublisherCod]
row[2]: NotCod row[2]: NotCod
row[3]: TimePublish row[3]: TimePublish
row[4]: Txt row[4]: Txt
row[5]: MedCod row[5]: MedCod
*/ */
/***** Get code of comment (row[0]) *****/ /***** Get code of comment (row[0]), publisher code (row[1])
Com->PubCod = Str_ConvertStrCodToLongCod (row[0]); and note code (row[2) *****/
Com->PubCod = Str_ConvertStrCodToLongCod (row[0]);
Com->UsrCod = Str_ConvertStrCodToLongCod (row[1]);
Com->NotCod = Str_ConvertStrCodToLongCod (row[2]);
/***** Get (from) user code (row[1]) *****/ /***** Get date-time of the note (row[3]) *****/
Com->UsrCod = Str_ConvertStrCodToLongCod (row[1]);
/***** Get code of note (row[2]) *****/
Com->NotCod = Str_ConvertStrCodToLongCod (row[2]);
/***** Get time of the note (row[3]) *****/
Com->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[3]); Com->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[3]);
/***** Get text content (row[4]) *****/ /***** Get text content (row[4]) and media content (row[5]) *****/
Str_Copy (Com->Content.Txt,row[4],sizeof (Com->Content.Txt) - 1); Str_Copy (Com->Content.Txt,row[4],sizeof (Com->Content.Txt) - 1);
Com->Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[5]);
Med_GetMediaDataByCod (&Com->Content.Media);
/***** Get number of times this comment has been favourited *****/ /***** Get number of times this comment has been favourited *****/
TL_Fav_GetNumTimesACommHasBeenFav (Com); TL_Fav_GetNumTimesACommHasBeenFav (Com);
/***** Get media content (row[5]) *****/
Com->Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[5]);
Med_GetMediaDataByCod (&Com->Content.Media);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -1040,9 +1026,10 @@ static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Com_Comment
static void TL_Com_ResetComment (struct TL_Com_Comment *Com) static void TL_Com_ResetComment (struct TL_Com_Comment *Com)
{ {
Com->PubCod = -1L; Com->PubCod =
Com->UsrCod = -1L; Com->UsrCod =
Com->NotCod = -1L; Com->NotCod = -1L;
Com->DateTimeUTC = (time_t) 0; Com->DateTimeUTC = (time_t) 0;
Com->Content.Txt[0] = '\0'; Com->Content.Txt[0] = '\0';
Com->NumFavs = 0;
} }

View File

@ -74,12 +74,12 @@ unsigned TL_DB_GetInitialComments (long NotCod,
{ {
return (unsigned) return (unsigned)
DB_QuerySELECT (mysql_res,"can not get comments", DB_QuerySELECT (mysql_res,"can not get comments",
"SELECT tl_pubs.PubCod," // row[0] "SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1] "tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2] "tl_pubs.NotCod," // row[2]
"UNIX_TIMESTAMP(tl_pubs.TimePublish)," // row[3] "UNIX_TIMESTAMP(tl_pubs.TimePublish),"// row[3]
"tl_comments.Txt," // row[4] "tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5] "tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments" " FROM tl_pubs,tl_comments"
" WHERE tl_pubs.NotCod=%ld" " WHERE tl_pubs.NotCod=%ld"
" AND tl_pubs.PubType=%u" " AND tl_pubs.PubType=%u"
@ -104,12 +104,12 @@ unsigned TL_DB_GetFinalComments (long NotCod,
DB_QuerySELECT (mysql_res,"can not get comments", DB_QuerySELECT (mysql_res,"can not get comments",
"SELECT * FROM " "SELECT * FROM "
"(" "("
"SELECT tl_pubs.PubCod," // row[0] "SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1] "tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2] "tl_pubs.NotCod," // row[2]
"UNIX_TIMESTAMP(tl_pubs.TimePublish)," // row[3] "UNIX_TIMESTAMP(tl_pubs.TimePublish),"// row[3]
"tl_comments.Txt," // row[4] "tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5] "tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments" " FROM tl_pubs,tl_comments"
" WHERE tl_pubs.NotCod=%ld" " WHERE tl_pubs.NotCod=%ld"
" AND tl_pubs.PubType=%u" " AND tl_pubs.PubType=%u"
@ -121,6 +121,33 @@ unsigned TL_DB_GetFinalComments (long NotCod,
NumFinalCommentsToGet); NumFinalCommentsToGet);
} }
/*****************************************************************************/
/******************* Get data of comment using its code **********************/
/*****************************************************************************/
// Returns the number of rows got
unsigned TL_DB_GetDataOfCommByCod (long PubCod,MYSQL_RES **mysql_res)
{
/***** Trivial check: publication code should be > 0 *****/
if (PubCod <= 0)
return 0;
/***** Get data of comment from database *****/
return (unsigned)
DB_QuerySELECT (&mysql_res,"can not get data of comment",
"SELECT tl_pubs.PubCod," // row[0]
"tl_pubs.PublisherCod," // row[1]
"tl_pubs.NotCod," // row[2]
"UNIX_TIMESTAMP(tl_pubs.TimePublish),"// row[3]
"tl_comments.Txt," // row[4]
"tl_comments.MedCod" // row[5]
" FROM tl_pubs,tl_comments"
" WHERE tl_pubs.PubCod=%ld"
" AND tl_pubs.PubType=%u"
" AND tl_pubs.PubCod=tl_comments.PubCod",
PubCod,(unsigned) TL_Pub_COMMENT_TO_NOTE);
}
/*****************************************************************************/ /*****************************************************************************/
/******************* Insert comment content in database **********************/ /******************* Insert comment content in database **********************/
/*****************************************************************************/ /*****************************************************************************/
@ -140,7 +167,7 @@ void TL_DB_InsertCommentContent (long PubCod,
} }
/*****************************************************************************/ /*****************************************************************************/
/******************* Insert comment content in database **********************/ /**************** Get code of media associated to comment ********************/
/*****************************************************************************/ /*****************************************************************************/
long TL_DB_GetMedCodFromComment (long PubCod) long TL_DB_GetMedCodFromComment (long PubCod)
@ -187,7 +214,7 @@ void TL_DB_RemoveCommentFavs (long PubCod)
void TL_DB_RemoveCommentContent (long PubCod) void TL_DB_RemoveCommentContent (long PubCod)
{ {
/***** Remove content of comment *****/ /***** Remove content of comment *****/
DB_QueryDELETE ("can not remove a comment", DB_QueryDELETE ("can not remove comment content",
"DELETE FROM tl_comments" "DELETE FROM tl_comments"
" WHERE PubCod=%ld", " WHERE PubCod=%ld",
PubCod); PubCod);
@ -200,10 +227,10 @@ void TL_DB_RemoveCommentContent (long PubCod)
void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod) void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod)
{ {
/***** Remove comment publication *****/ /***** Remove comment publication *****/
DB_QueryDELETE ("can not remove a comment", DB_QueryDELETE ("can not remove comment",
"DELETE FROM tl_pubs" "DELETE FROM tl_pubs"
" WHERE PubCod=%ld" " WHERE PubCod=%ld"
" AND PublisherCod=%ld" // Extra check: I am the author " AND PublisherCod=%ld" // Extra check: author
" AND PubType=%u", // Extra check: it's a comment " AND PubType=%u", // Extra check: it's a comment
PubCod, PubCod,
PublisherCod, PublisherCod,

View File

@ -49,6 +49,7 @@ unsigned TL_DB_GetInitialComments (long NotCod,
unsigned TL_DB_GetFinalComments (long NotCod, unsigned TL_DB_GetFinalComments (long NotCod,
unsigned NumFinalCommentsToGet, unsigned NumFinalCommentsToGet,
MYSQL_RES **mysql_res); MYSQL_RES **mysql_res);
unsigned TL_DB_GetDataOfCommByCod (long PubCod,MYSQL_RES **mysql_res);
void TL_DB_InsertCommentContent (long PubCod, void TL_DB_InsertCommentContent (long PubCod,
const struct TL_Pst_PostContent *Content); const struct TL_Pst_PostContent *Content);
long TL_DB_GetMedCodFromComment (long PubCod); long TL_DB_GetMedCodFromComment (long PubCod);