From e556a0faa6ff4e8d9b78a0cb6ff923bddd3a95e0 Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 1 Mar 2021 13:26:59 +0100 Subject: [PATCH] Version 20.36.37: Mar 01, 2021 Query moved to module swad_timeline_database. --- swad_changelog.h | 3 ++- swad_timeline_database.c | 33 ++++++++++++++++++++++++++++++--- swad_timeline_database.h | 1 + swad_timeline_notification.c | 9 ++------- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index cdb92571..7385dda9 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.36.36 (2021-03-01)" +#define Log_PLATFORM_VERSION "SWAD 20.36.37 (2021-03-01)" #define CSS_FILE "swad20.33.9.css" #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: Salvador Romero Cortés: @acanas opción para editar posts + Version 20.36.37: Mar 01, 2021 Query moved to module swad_timeline_database. (305449 lines) Version 20.36.36: Mar 01, 2021 Query moved to module swad_timeline_database. (305429 lines) Version 20.36.35: Mar 01, 2021 Code refactoring in timeline favourites. (305411 lines) Version 20.36.34: Mar 01, 2021 Function moved to module swad_timeline_database. (305446 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 273e2e0e..3e08b653 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -338,17 +338,22 @@ void TL_DB_RemoveNote (long NotCod) } /*****************************************************************************/ -/************** Get publication codes of comments of a note from database *****************/ +/********************* Get data of post using its code ***********************/ /*****************************************************************************/ // Returns the number of rows got unsigned TL_DB_GetPostByCod (long PstCod,MYSQL_RES **mysql_res) { + /***** Trivial check: post code should be > 0 *****/ + if (PstCod <= 0) + return 0; + + /***** Get data of post from database *****/ return (unsigned) DB_QuerySELECT (mysql_res,"can not get the content" " of a post", - "SELECT Txt," // row[0] - "MedCod" // row[1] + "SELECT Txt," // row[0] + "MedCod" // row[1] " FROM tl_posts" " WHERE PstCod=%ld", PstCod); @@ -721,6 +726,28 @@ unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQuerie SubQueries->AlreadyExists); } +/*****************************************************************************/ +/****************** Get data of publication using its code *******************/ +/*****************************************************************************/ +// Returns the number of rows got + +unsigned TL_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res) + { + /***** Trivial check: publication code should be > 0 *****/ + if (PubCod <= 0) + return 0; + + /***** Get data of note from database *****/ + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get data of publication", + "SELECT PubCod," // row[0] + "NotCod," // row[1] + "PublisherCod," // row[2] + "PubType" // row[3] + " FROM tl_pubs WHERE PubCod=%ld", + PubCod); + } + /*****************************************************************************/ /*********************** Get code of note of a publication *******************/ /*****************************************************************************/ diff --git a/swad_timeline_database.h b/swad_timeline_database.h index edd23782..16863f5b 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -104,6 +104,7 @@ void TL_DB_CreateSubQueryRangeTop (const struct TL_Pub_RangePubsToGet *RangePubs struct TL_Pub_SubQueries *SubQueries); unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries, MYSQL_RES **mysql_res); +unsigned TL_DB_GetDataOfPubByCod (long PubCod,MYSQL_RES **mysql_res); long TL_DB_GetNotCodFromPubCod (long PubCod); long TL_DB_GetPubCodFromSession (const char *FieldName); unsigned long TL_DB_GetNumPubsUsr (long UsrCod); diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c index 6313fbb8..b6f23fa8 100644 --- a/swad_timeline_notification.c +++ b/swad_timeline_notification.c @@ -31,6 +31,7 @@ #include "swad_database.h" #include "swad_global.h" #include "swad_timeline.h" +#include "swad_timeline_database.h" #include "swad_timeline_note.h" #include "swad_timeline_notification.h" #include "swad_timeline_post.h" @@ -119,13 +120,7 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1], Content.Txt[0] = '\0'; /***** Get summary and content from post from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get data of publication", - "SELECT PubCod," // row[0] - "NotCod," // row[1] - "PublisherCod," // row[2] - "PubType" // row[3] - " FROM tl_pubs WHERE PubCod=%ld", - PubCod) == 1) // Result should have a unique row + if (TL_DB_GetDataOfPubByCod (PubCod,&mysql_res) == 1) // Result should have a unique row /* Get data of publication from row */ TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,&Pub);