From bb8957e5841a2ab77fdbef21d482ac6b80d9f185 Mon Sep 17 00:00:00 2001 From: acanas Date: Sat, 27 Feb 2021 22:13:05 +0100 Subject: [PATCH] Version 20.36.21: Feb 27, 2021 Function moved to module swad_timeline_database. --- swad_changelog.h | 4 ++- swad_timeline.c | 3 +- swad_timeline_database.c | 51 ++++++++++++++++++++++++++++++++++ swad_timeline_database.h | 4 +++ swad_timeline_publication.c | 55 +------------------------------------ swad_timeline_publication.h | 12 ++++++-- 6 files changed, 71 insertions(+), 58 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index d5b241d5..10f0bf64 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.19 (2021-02-27)" +#define Log_PLATFORM_VERSION "SWAD 20.36.21 (2021-02-27)" #define CSS_FILE "swad20.33.9.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,8 @@ 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.21: Feb 27, 2021 Function moved to module swad_timeline_database. (305376 lines) + Version 20.36.20: Feb 27, 2021 Query moved to module swad_timeline_database. (305374 lines) Version 20.36.19: Feb 27, 2021 Queries moved to module swad_timeline_database. (305363 lines) Version 20.36.18: Feb 27, 2021 Function moved to module swad_timeline_database. (305334 lines) Version 20.36.17: Feb 27, 2021 Query moved to module swad_timeline_database. (305328 lines) diff --git a/swad_timeline.c b/swad_timeline.c index 2bf9c8cf..ebc13a78 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -135,6 +135,7 @@ mysql> SHOW TABLES LIKE 'tl_%'; #include "swad_photo.h" #include "swad_profile.h" #include "swad_timeline.h" +#include "swad_timeline_database.h" #include "swad_timeline_favourite.h" #include "swad_timeline_note.h" #include "swad_timeline_notification.h" @@ -238,7 +239,7 @@ void TL_ShowNoteAndTimelineGbl (struct TL_Timeline *Timeline) /***** If a note should be highlighted ==> get code of note from database *****/ if (PubCod > 0) - Not.NotCod = TL_Pub_GetNotCodFromPubCod (PubCod); + Not.NotCod = TL_DB_GetNotCodFromPubCod (PubCod); /***** If a note should be highlighted ==> show it above the timeline *****/ if (Not.NotCod > 0) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index 598810e5..31da1463 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -590,6 +590,57 @@ static long TL_DB_GetMedCodFromPub (long PubCod,const char *DBTable) return MedCod; } +/*****************************************************************************/ +/******************** Select the most recent publication *********************/ +/*****************************************************************************/ +// Returns the number of rows got + +unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries, + MYSQL_RES **mysql_res) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get publication", + "SELECT tl_pubs.PubCod," // row[0] + "tl_pubs.NotCod," // row[1] + "tl_pubs.PublisherCod," // row[2] + "tl_pubs.PubType" // row[3] + " FROM tl_pubs%s" + " WHERE %s%s%s%s" + " ORDER BY tl_pubs.PubCod DESC LIMIT 1", + SubQueries->TablePublishers, + SubQueries->RangeBottom, + SubQueries->RangeTop, + SubQueries->Publishers, + SubQueries->AlreadyExists); + } + +/*****************************************************************************/ +/*********************** Get code of note of a publication *******************/ +/*****************************************************************************/ + +long TL_DB_GetNotCodFromPubCod (long PubCod) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + long NotCod = -1L; // Default value + + /***** Get code of note from database *****/ + if (DB_QuerySELECT (&mysql_res,"can not get code of note", + "SELECT NotCod FROM tl_pubs" + " WHERE PubCod=%ld", + PubCod) == 1) // Result should have a unique row + { + /* Get code of note */ + row = mysql_fetch_row (mysql_res); + NotCod = Str_ConvertStrCodToLongCod (row[0]); + } + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + + return NotCod; + } + /*****************************************************************************/ /************* Get last/first publication code stored in session *************/ /*****************************************************************************/ diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 8ce595c8..23dd5a8a 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -31,6 +31,7 @@ #include "swad_file_browser.h" #include "swad_timeline_note.h" #include "swad_timeline_post.h" +#include "swad_timeline_publication.h" /*****************************************************************************/ /****************************** Public constants *****************************/ @@ -91,6 +92,9 @@ void TL_DB_RemoveCommentContent (long PubCod); void TL_DB_RemoveCommentPub (long PubCod,long PublisherCod); /* Publications */ +unsigned TL_DB_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries, + MYSQL_RES **mysql_res); +long TL_DB_GetNotCodFromPubCod (long PubCod); long TL_DB_GetPubCodFromSession (const char *FieldName, const char SessionId[Cns_BYTES_SESSION_ID + 1]); void TL_DB_UpdateFirstPubCodInSession (long FirstPubCod, diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index ce18db2a..592694ae 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -47,16 +47,6 @@ /************************* Private constants and types ***********************/ /*****************************************************************************/ -#define TL_Pub_MAX_BYTES_SUBQUERY (128 - 1) -struct TL_Pub_SubQueries - { - char *TablePublishers; - char Publishers [TL_Pub_MAX_BYTES_SUBQUERY + 1]; - char RangeBottom [TL_Pub_MAX_BYTES_SUBQUERY + 1]; - char RangeTop [TL_Pub_MAX_BYTES_SUBQUERY + 1]; - char AlreadyExists[TL_Pub_MAX_BYTES_SUBQUERY + 1]; - }; - struct TL_Pub_RangePubsToGet { long Top; @@ -424,25 +414,9 @@ void TL_Pub_FreeListPubs (struct TL_Timeline *Timeline) static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL_Pub_SubQueries *SubQueries) { MYSQL_RES *mysql_res; - unsigned NumPubs = 0; // Initialized to avoid warning struct TL_Pub_Publication *Pub; - NumPubs = - (unsigned) DB_QuerySELECT (&mysql_res,"can not get publication", - "SELECT tl_pubs.PubCod," // row[0] - "tl_pubs.NotCod," // row[1] - "tl_pubs.PublisherCod," // row[2] - "tl_pubs.PubType" // row[3] - " FROM tl_pubs%s" - " WHERE %s%s%s%s" - " ORDER BY tl_pubs.PubCod DESC LIMIT 1", - SubQueries->TablePublishers, - SubQueries->RangeBottom, - SubQueries->RangeTop, - SubQueries->Publishers, - SubQueries->AlreadyExists); - - if (NumPubs == 1) + if (TL_DB_SelectTheMostRecentPub (SubQueries,&mysql_res) == 1) { /* Allocate space for publication */ if ((Pub = malloc (sizeof (*Pub))) == NULL) @@ -608,33 +582,6 @@ long TL_Pub_GetParamPubCod (void) return Par_GetParToLong ("PubCod"); } -/*****************************************************************************/ -/*********************** Get code of note of a publication *******************/ -/*****************************************************************************/ - -long TL_Pub_GetNotCodFromPubCod (long PubCod) - { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - long NotCod = -1L; - - /***** Get code of note from database *****/ - if (DB_QuerySELECT (&mysql_res,"can not get code of note", - "SELECT NotCod FROM tl_pubs" - " WHERE PubCod=%ld", - PubCod) == 1) // Result should have a unique row - { - /* Get code of note */ - row = mysql_fetch_row (mysql_res); - NotCod = Str_ConvertStrCodToLongCod (row[0]); - } - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); - - return NotCod; - } - /*****************************************************************************/ /***************** Get data of publication using its code ********************/ /*****************************************************************************/ diff --git a/swad_timeline_publication.h b/swad_timeline_publication.h index 7cf22f54..d004d736 100644 --- a/swad_timeline_publication.h +++ b/swad_timeline_publication.h @@ -65,6 +65,16 @@ struct TL_Pub_Publication struct TL_Pub_Publication *Next; // Used for chained list }; +#define TL_Pub_MAX_BYTES_SUBQUERY (128 - 1) +struct TL_Pub_SubQueries + { + char *TablePublishers; + char Publishers [TL_Pub_MAX_BYTES_SUBQUERY + 1]; + char RangeBottom [TL_Pub_MAX_BYTES_SUBQUERY + 1]; + char RangeTop [TL_Pub_MAX_BYTES_SUBQUERY + 1]; + char AlreadyExists[TL_Pub_MAX_BYTES_SUBQUERY + 1]; + }; + /*****************************************************************************/ /****************************** Public prototypes ****************************/ /*****************************************************************************/ @@ -83,8 +93,6 @@ void TL_Pub_PutLinkToViewOldPublications (void); void TL_Pub_PutHiddenParamPubCod (long PubCod); long TL_Pub_GetParamPubCod (void); -long TL_Pub_GetNotCodFromPubCod (long PubCod); - void TL_Pub_GetDataOfPublicationFromNextRow (MYSQL_RES *mysql_res, struct TL_Pub_Publication *Pub);