diff --git a/swad_changelog.h b/swad_changelog.h index b69ea13b..9865267b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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.7: Feb 27, 2021 Query moved to module swad_timeline_database. (? lines) 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.4: Feb 26, 2021 Query moved to module swad_timeline_database. (305156 lines) diff --git a/swad_timeline_database.c b/swad_timeline_database.c index d85913f2..acdb5395 100644 --- a/swad_timeline_database.c +++ b/swad_timeline_database.c @@ -50,6 +50,50 @@ /***************************** Private prototypes ****************************/ /*****************************************************************************/ +/*****************************************************************************/ +/***************************** Create a new note *****************************/ +/*****************************************************************************/ +// Returns code of note just created + +long TL_DB_CreateNewNote (TL_Not_NoteType_t NoteType,long Cod, + long PublisherCod,long HieCod) + { + return + DB_QueryINSERTandReturnCode ("can not create new note", + "INSERT INTO tl_notes" + " (NoteType,Cod,UsrCod,HieCod,Unavailable,TimeNote)" + " VALUES" + " (%u,%ld,%ld,%ld,'N',NOW())", + (unsigned) NoteType, // Post, file, exam, notice, forum + Cod, // Post, file, exam, notice, forum code + PublisherCod, // Publisher code + HieCod); // Where in hierarchy + } + +/*****************************************************************************/ +/**** Insert note in temporary tables used to not get notes already shown ****/ +/*****************************************************************************/ + +void TL_DB_InsertNoteInJustRetrievedNotes (long NotCod) + { + /* Insert note in temporary table with just retrieved notes. + This table will be used to not get notes already shown */ + DB_QueryINSERT ("can not store note code", + "INSERT IGNORE INTO tl_tmp_just_retrieved_notes" + " SET NotCod=%ld", + NotCod); + } + +void TL_DB_InsertNoteInVisibleTimeline (long NotCod) + { + /* Insert note in temporary table with visible timeline. + This table will be used to not get notes already shown */ + DB_QueryINSERT ("can not store note code", + "INSERT IGNORE INTO tl_tmp_visible_timeline" + " SET NotCod=%ld", + NotCod); + } + /*****************************************************************************/ /********************* Get number of comments in a note **********************/ /*****************************************************************************/ @@ -134,7 +178,7 @@ unsigned TL_DB_GetDataOfCommByCod (long PubCod,MYSQL_RES **mysql_res) /***** Get data of comment from database *****/ return (unsigned) - DB_QuerySELECT (&mysql_res,"can not get data of comment", + 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] diff --git a/swad_timeline_database.h b/swad_timeline_database.h index 8d7a78ee..bf14b430 100644 --- a/swad_timeline_database.h +++ b/swad_timeline_database.h @@ -28,6 +28,7 @@ /*****************************************************************************/ #include "swad_database.h" +#include "swad_timeline_note.h" #include "swad_timeline_post.h" /*****************************************************************************/ @@ -42,6 +43,13 @@ /****************************** Public prototypes ****************************/ /*****************************************************************************/ +/* Notes */ +long TL_DB_CreateNewNote (TL_Not_NoteType_t NoteType,long Cod, + long PublisherCod,long HieCod); +void TL_DB_InsertNoteInJustRetrievedNotes (long NotCod); +void TL_DB_InsertNoteInVisibleTimeline (long NotCod); + +/* Comments */ unsigned TL_DB_GetNumCommentsInNote (long NotCod); unsigned TL_DB_GetInitialComments (long NotCod, unsigned NumInitialCommentsToGet, diff --git a/swad_timeline_note.c b/swad_timeline_note.c index c5cf9c0f..8866a8b9 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -41,6 +41,7 @@ #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_form.h" #include "swad_timeline_publication.h" @@ -184,30 +185,6 @@ void TL_Not_ShowHighlightedNote (struct TL_Timeline *Timeline, Box_BoxEnd (); } -/*****************************************************************************/ -/**** Insert note in temporary tables used to not get notes already shown ****/ -/*****************************************************************************/ - -void TL_Not_InsertNoteInJustRetrievedNotes (long NotCod) - { - /* Insert note in temporary table with just retrieved notes. - This table will be used to not get notes already shown */ - DB_QueryINSERT ("can not store note code", - "INSERT IGNORE INTO tl_tmp_just_retrieved_notes" - " SET NotCod=%ld", - NotCod); - } - -void TL_Not_InsertNoteInVisibleTimeline (long NotCod) - { - /* Insert note in temporary table with visible timeline. - This table will be used to not get notes already shown */ - DB_QueryINSERT ("can not store note code", - "INSERT IGNORE INTO tl_tmp_visible_timeline" - " SET NotCod=%ld", - NotCod); - } - /*****************************************************************************/ /****************** Check and write note with top message ********************/ /*****************************************************************************/ @@ -895,18 +872,9 @@ void TL_Not_StoreAndPublishNoteInternal (TL_Not_NoteType_t NoteType,long Cod,str break; } - /***** Store note *****/ - Pub->NotCod = - DB_QueryINSERTandReturnCode ("can not create new note", - "INSERT INTO tl_notes" - " (NoteType,Cod,UsrCod,HieCod,Unavailable,TimeNote)" - " VALUES" - " (%u,%ld,%ld,%ld,'N',NOW())", - (unsigned) NoteType, - Cod,Gbl.Usrs.Me.UsrDat.UsrCod,HieCod); - /***** Publish note in timeline *****/ Pub->PublisherCod = Gbl.Usrs.Me.UsrDat.UsrCod; + Pub->NotCod = TL_DB_CreateNewNote (NoteType,Cod,Pub->PublisherCod,HieCod); Pub->PubType = TL_Pub_ORIGINAL_NOTE; TL_Pub_PublishPubInTimeline (Pub); } diff --git a/swad_timeline_note.h b/swad_timeline_note.h index d8cc34b0..02e553bd 100644 --- a/swad_timeline_note.h +++ b/swad_timeline_note.h @@ -87,9 +87,6 @@ struct TL_Not_Note void TL_Not_ShowHighlightedNote (struct TL_Timeline *Timeline, struct TL_Not_Note *Not); -void TL_Not_InsertNoteInJustRetrievedNotes (long NotCod); -void TL_Not_InsertNoteInVisibleTimeline (long NotCod); - void TL_Not_CheckAndWriteNoteWithTopMsg (const struct TL_Timeline *Timeline, const struct TL_Not_Note *Not, TL_TopMessage_t TopMessage, diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c index 9d93dd8a..62d2d488 100644 --- a/swad_timeline_publication.c +++ b/swad_timeline_publication.c @@ -223,9 +223,9 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline) /* Insert note in temporary tables with just retrieved notes. These tables will be used to not get notes already shown */ - TL_Not_InsertNoteInJustRetrievedNotes (Pub->NotCod); + TL_DB_InsertNoteInJustRetrievedNotes (Pub->NotCod); if (Timeline->WhatToGet == TL_GET_ONLY_OLD_PUBS) // Get only old publications - TL_Not_InsertNoteInVisibleTimeline (Pub->NotCod); + TL_DB_InsertNoteInVisibleTimeline (Pub->NotCod); /* Narrow the range for the next iteration */ RangePubsToGet.Top = Pub->PubCod;