2021-02-26 22:20:03 +01:00
|
|
|
|
// swad_timeline_database.c: social timeline operations with database
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-02-26 22:20:03 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General 3 License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************************** Headers *********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "swad_database.h"
|
2021-04-26 15:27:27 +02:00
|
|
|
|
#include "swad_error.h"
|
2021-02-28 21:12:44 +01:00
|
|
|
|
#include "swad_follow.h"
|
2021-09-13 23:26:25 +02:00
|
|
|
|
#include "swad_follow_database.h"
|
2021-02-28 21:12:44 +01:00
|
|
|
|
#include "swad_global.h"
|
2023-03-06 23:53:45 +01:00
|
|
|
|
#include "swad_parameter.h"
|
2021-02-26 22:20:03 +01:00
|
|
|
|
#include "swad_timeline.h"
|
2021-02-26 23:13:06 +01:00
|
|
|
|
#include "swad_timeline_database.h"
|
2021-02-26 22:20:03 +01:00
|
|
|
|
#include "swad_timeline_publication.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Private constants and types ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static const char *Tml_DB_TableFav[TmlUsr_NUM_FAV_SHA] =
|
2021-03-01 13:15:50 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
[TmlUsr_FAV_UNF_NOTE] = "tml_notes_fav",
|
|
|
|
|
[TmlUsr_FAV_UNF_COMM] = "tml_comments_fav",
|
|
|
|
|
[TmlUsr_SHA_UNS_NOTE] = NULL, // Not used
|
2021-03-01 13:15:50 +01:00
|
|
|
|
};
|
2023-03-10 17:21:04 +01:00
|
|
|
|
static const char *Tml_DB_FieldFav[TmlUsr_NUM_FAV_SHA] =
|
2021-03-01 13:15:50 +01:00
|
|
|
|
{
|
2023-03-10 17:21:04 +01:00
|
|
|
|
[TmlUsr_FAV_UNF_NOTE] = "NotCod",
|
|
|
|
|
[TmlUsr_FAV_UNF_COMM] = "PubCod",
|
|
|
|
|
[TmlUsr_SHA_UNS_NOTE] = NULL, // Not used
|
2021-03-01 13:15:50 +01:00
|
|
|
|
};
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static TmlPub_Type_t Tml_DB_PubTypeFav[TmlUsr_NUM_FAV_SHA] =
|
2021-03-01 14:46:57 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
[TmlUsr_FAV_UNF_NOTE] = TmlPub_ORIGINAL_NOTE,
|
|
|
|
|
[TmlUsr_FAV_UNF_COMM] = TmlPub_COMMENT_TO_NOTE,
|
|
|
|
|
[TmlUsr_SHA_UNS_NOTE] = TmlPub_UNKNOWN, // Not used
|
2021-03-01 14:46:57 +01:00
|
|
|
|
};
|
2021-03-01 13:15:50 +01:00
|
|
|
|
|
2021-02-26 22:20:03 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** External global variables from others modules ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-02-28 21:12:44 +01:00
|
|
|
|
extern struct Globals Gbl;
|
|
|
|
|
|
2021-02-26 22:20:03 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Private prototypes ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 17:21:04 +01:00
|
|
|
|
static long Tml_DB_GetMedCod (const char *Table,const char *Field,long Cod);
|
2021-02-27 15:09:23 +01:00
|
|
|
|
|
2021-02-27 16:45:29 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-03-01 16:58:32 +01:00
|
|
|
|
/********************* Get which users to show in timeline *******************/
|
2021-02-27 16:45:29 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetWho (MYSQL_RES **mysql_res)
|
2021-03-01 16:54:18 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
2021-03-01 16:58:32 +01:00
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get which timeline users",
|
2021-03-01 16:54:18 +01:00
|
|
|
|
"SELECT TimelineUsrs" // row[0]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM usr_last"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
2021-03-01 16:54:18 +01:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 16:58:32 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get which users to show in timeline *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_UpdateWho (Usr_Who_t Who)
|
2021-03-01 16:58:32 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update which timeline users",
|
2021-03-29 16:38:56 +02:00
|
|
|
|
"UPDATE usr_last"
|
|
|
|
|
" SET TimelineUsrs=%u"
|
2021-03-01 16:58:32 +01:00
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
(unsigned) Who,
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 16:54:18 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get data of note using its code ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Tml_DB_GetNoteDataByCod (long NotCod,MYSQL_RES **mysql_res)
|
2021-02-27 16:45:29 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Trivial check: note code should be > 0 *****/
|
|
|
|
|
if (NotCod <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/***** Get data of note from database *****/
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get data of note",
|
|
|
|
|
"SELECT NotCod," // row[0]
|
|
|
|
|
"NoteType," // row[1]
|
|
|
|
|
"Cod," // row[2]
|
|
|
|
|
"UsrCod," // row[3]
|
|
|
|
|
"HieCod," // row[4]
|
|
|
|
|
"Unavailable," // row[5]
|
|
|
|
|
"UNIX_TIMESTAMP(TimeNote)" // row[6]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_notes"
|
2021-02-27 16:45:29 +01:00
|
|
|
|
" WHERE NotCod=%ld",
|
|
|
|
|
NotCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get code of publication of the original note ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long Tml_DB_GetPubCodOfOriginalNote (long NotCod)
|
2021-02-27 16:45:29 +01:00
|
|
|
|
{
|
2021-04-05 23:45:24 +02:00
|
|
|
|
return DB_QuerySELECTCode ("can not get code of publication",
|
|
|
|
|
"SELECT PubCod"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE NotCod=%ld"
|
|
|
|
|
" AND PubType=%u",
|
|
|
|
|
NotCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_ORIGINAL_NOTE);
|
2021-02-27 16:45:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:12:41 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Create a new note *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns code of note just created
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
long Tml_DB_CreateNewNote (TmlNot_Type_t NoteType,long Cod,
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long PublisherCod,long HieCod)
|
2021-02-27 14:12:41 +01:00
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
DB_QueryINSERTandReturnCode ("can not create new note",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"INSERT INTO tml_notes"
|
2021-04-17 11:27:33 +02:00
|
|
|
|
" (NoteType,Cod,UsrCod,HieCod,"
|
|
|
|
|
"Unavailable,TimeNote)"
|
2021-02-27 14:12:41 +01:00
|
|
|
|
" VALUES"
|
2021-04-17 11:27:33 +02:00
|
|
|
|
" (%u,%ld,%ld,%ld,"
|
|
|
|
|
"'N',NOW())",
|
2021-02-27 14:12:41 +01:00
|
|
|
|
(unsigned) NoteType, // Post, file, exam, notice, forum
|
|
|
|
|
Cod, // Post, file, exam, notice, forum code
|
|
|
|
|
PublisherCod, // Publisher code
|
|
|
|
|
HieCod); // Where in hierarchy
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:25:17 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Mark a note as unavailable ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_MarkNoteAsUnavailable (TmlNot_Type_t NoteType,long Cod)
|
2021-02-27 14:25:17 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not mark note as unavailable",
|
2021-04-17 13:11:37 +02:00
|
|
|
|
"UPDATE tml_notes"
|
|
|
|
|
" SET Unavailable='Y'"
|
|
|
|
|
" WHERE NoteType=%u"
|
|
|
|
|
" AND Cod=%ld",
|
|
|
|
|
(unsigned) NoteType,
|
|
|
|
|
Cod);
|
2021-02-27 14:25:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 14:39:16 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***** Mark possible notes involving children of a folder as unavailable *****/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_MarkNotesChildrenOfFolderAsUnavailable (TmlNot_Type_t NoteType,
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Brw_FileBrowser_t FileBrowser,
|
|
|
|
|
long Cod,const char *Path)
|
2021-02-27 14:39:16 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not mark notes as unavailable",
|
2021-03-18 12:44:00 +01:00
|
|
|
|
"UPDATE tml_notes"
|
|
|
|
|
" SET Unavailable='Y'"
|
|
|
|
|
" WHERE NoteType=%u"
|
|
|
|
|
" AND Cod IN"
|
|
|
|
|
" (SELECT FilCod"
|
|
|
|
|
" FROM brw_files"
|
|
|
|
|
" WHERE FileBrowser=%u"
|
|
|
|
|
" AND Cod=%ld"
|
|
|
|
|
" AND Path LIKE '%s/%%'"
|
|
|
|
|
" AND Public='Y')", // Only public files
|
2021-02-27 14:39:16 +01:00
|
|
|
|
(unsigned) NoteType,
|
|
|
|
|
(unsigned) FileBrowser,Cod,
|
|
|
|
|
Path);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 17:44:00 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get number of notes and users depending on note type *************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Tml_DB_GetNumNotesAndUsrsByType (MYSQL_RES **mysql_res,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlNot_Type_t NoteType)
|
2021-09-11 17:44:00 +02:00
|
|
|
|
{
|
|
|
|
|
switch (Gbl.Scope.Current)
|
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT UsrCod)" // row[1]
|
|
|
|
|
" FROM tml_notes"
|
|
|
|
|
" WHERE NoteType=%u",
|
|
|
|
|
(unsigned) NoteType);
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_CTY:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM ins_instits,"
|
|
|
|
|
"ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE ins_instits.CtyCod=%ld"
|
|
|
|
|
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod"
|
|
|
|
|
" AND tml_notes.NoteType=%u",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTY].HieCod,
|
2021-09-11 17:44:00 +02:00
|
|
|
|
(unsigned) NoteType);
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_INS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE ctr_centers.InsCod=%ld"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod"
|
|
|
|
|
" AND tml_notes.NoteType=%u",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_INS].HieCod,
|
2021-09-11 17:44:00 +02:00
|
|
|
|
(unsigned) NoteType);
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_CTR:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE deg_degrees.CtrCod=%ld"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod"
|
|
|
|
|
" AND tml_notes.NoteType=%u",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTR].HieCod,
|
2021-09-11 17:44:00 +02:00
|
|
|
|
(unsigned) NoteType);
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_DEG:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE crs_courses.DegCod=%ld"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod"
|
|
|
|
|
" AND tml_notes.NoteType=%u",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_DEG].HieCod,
|
2021-09-11 17:44:00 +02:00
|
|
|
|
(unsigned) NoteType);
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_CRS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE crs_users.CrsCod=%ld"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod"
|
|
|
|
|
" AND tml_notes.NoteType=%u",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod,
|
2021-09-11 17:44:00 +02:00
|
|
|
|
(unsigned) NoteType);
|
|
|
|
|
default:
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Err_WrongHierarchyLevelExit ();
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return 0; // Not reached
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Get total number of notes and users ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Tml_DB_GetNumNotesAndUsrsTotal (MYSQL_RES **mysql_res)
|
|
|
|
|
{
|
|
|
|
|
switch (Gbl.Scope.Current)
|
|
|
|
|
{
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_SYS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(*)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT UsrCod)" // row[1]
|
|
|
|
|
" FROM tml_notes");
|
2023-09-22 14:47:56 +02:00
|
|
|
|
case Hie_CTY:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM ins_instits,"
|
|
|
|
|
"ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE ins_instits.CtyCod=%ld"
|
|
|
|
|
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTY].HieCod);
|
|
|
|
|
case Hie_INS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM ctr_centers,"
|
|
|
|
|
"deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE ctr_centers.InsCod=%ld"
|
|
|
|
|
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_INS].HieCod);
|
|
|
|
|
case Hie_CTR:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM deg_degrees,"
|
|
|
|
|
"crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE deg_degrees.CtrCod=%ld"
|
|
|
|
|
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CTR].HieCod);
|
|
|
|
|
case Hie_DEG:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM crs_courses,"
|
|
|
|
|
"crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE crs_courses.DegCod=%ld"
|
|
|
|
|
" AND crs_courses.CrsCod=crs_users.CrsCod"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_DEG].HieCod);
|
|
|
|
|
case Hie_CRS:
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get number of social notes",
|
|
|
|
|
"SELECT COUNT(DISTINCT tml_notes.NotCod)," // row[0]
|
|
|
|
|
"COUNT(DISTINCT tml_notes.UsrCod)" // row[1]
|
|
|
|
|
" FROM crs_users,"
|
|
|
|
|
"tml_notes"
|
|
|
|
|
" WHERE crs_users.CrsCod=%ld"
|
|
|
|
|
" AND crs_users.UsrCod=tml_notes.UsrCod",
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
|
2021-09-11 17:44:00 +02:00
|
|
|
|
default:
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Err_WrongHierarchyLevelExit ();
|
2021-09-11 17:44:00 +02:00
|
|
|
|
return 0; // Not reached
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 17:23:22 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Create temporary tables used to not get notes already shown *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-21 01:22:59 +01:00
|
|
|
|
void Tml_DB_CreateTmpTableTimeline (Tml_WhatToGet_t WhatToGet)
|
2021-02-27 17:23:22 +01:00
|
|
|
|
{
|
2021-11-21 01:22:59 +01:00
|
|
|
|
switch (WhatToGet)
|
|
|
|
|
{
|
|
|
|
|
case Tml_GET_OLD_PUBS:
|
|
|
|
|
DB_CreateTmpTable ("CREATE TEMPORARY TABLE tml_tmp_timeline "
|
|
|
|
|
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
|
|
|
|
|
" ENGINE=MEMORY"
|
|
|
|
|
" SELECT NotCod"
|
|
|
|
|
" FROM tml_timelines"
|
|
|
|
|
" WHERE SessionId='%s'",
|
|
|
|
|
Gbl.Session.Id);
|
|
|
|
|
break;
|
|
|
|
|
case Tml_GET_NEW_PUBS:
|
|
|
|
|
case Tml_GET_REC_PUBS:
|
|
|
|
|
default:
|
|
|
|
|
DB_CreateTmpTable ("CREATE TEMPORARY TABLE tml_tmp_timeline "
|
|
|
|
|
"(NotCod BIGINT NOT NULL,UNIQUE INDEX(NotCod))"
|
|
|
|
|
" ENGINE=MEMORY");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-27 14:12:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 16:30:41 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-11-21 01:22:59 +01:00
|
|
|
|
/**** Insert note in temporary table used to not get notes already shown *****/
|
2021-02-27 16:30:41 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-21 01:22:59 +01:00
|
|
|
|
void Tml_DB_InsertNoteInTimeline (long NotCod)
|
2021-02-27 16:30:41 +01:00
|
|
|
|
{
|
2021-03-04 18:37:16 +01:00
|
|
|
|
/* tml_timelines contains the distinct notes in timeline of each open session:
|
|
|
|
|
mysql> SELECT SessionId,COUNT(*) FROM tml_timelines GROUP BY SessionId;
|
2021-02-27 16:30:41 +01:00
|
|
|
|
+---------------------------------------------+----------+
|
|
|
|
|
| SessionId | COUNT(*) |
|
|
|
|
|
+---------------------------------------------+----------+
|
|
|
|
|
| u-X-R3gKki7eKMXrNCP8bGhwOAZuVngRy7FNGZFMKzI | 52 | --> 52 distinct notes
|
|
|
|
|
| u1CoqL1YWl3_hR4wk4bI7vhnc-uRcCmIDyKYAgBB6kk | 10 |
|
|
|
|
|
| u8xqamzkorHfY4BvYRMXjNhzHvQyigZUZemO0YiMn48 | 10 |
|
|
|
|
|
| u_n2V_L3KrFjnd4SqZk0gxMFwZHRuWZ8_EIVTU9sdpI | 10 |
|
|
|
|
|
| V6pGe1kGGS_uO5i__waqXKnuDkPYaDZHNAYr-Zv-GJQ | 2 |
|
|
|
|
|
| vqDRz-iiM8v10Dl8ThwqIqmDRIklz8szJaqflwXZucs | 10 |
|
|
|
|
|
| w11juqKPx6lg-f_pL2ZBYqlagU1mEepSvvk9L3gDGac | 10 | --> 10 distinct notes
|
|
|
|
|
| wLg4e8KQljCcVuFWIkJjNeti89kAiwOZ3iyXdzm_eDk | 10 |
|
|
|
|
|
| wnU85YrwJHhZGWIZhd7LQfQTPrclIWHfMF3DcB-Rcgw | 4 |
|
|
|
|
|
| wRzRJFnHfzW61fZYnvMIaMRlkuWUeEyqXVQ6JeWA32k | 11 |
|
|
|
|
|
+---------------------------------------------+----------+
|
|
|
|
|
10 rows in set (0,01 sec)
|
|
|
|
|
*/
|
2021-11-21 01:22:59 +01:00
|
|
|
|
/* Insert note in temporary table with visible timeline.
|
|
|
|
|
This table will be used to not get notes already shown */
|
|
|
|
|
DB_QueryINSERT ("can not insert note in timeline",
|
|
|
|
|
"INSERT IGNORE INTO tml_tmp_timeline"
|
|
|
|
|
" SET NotCod=%ld",
|
|
|
|
|
NotCod);
|
|
|
|
|
|
|
|
|
|
DB_QueryINSERT ("can not insert note in timeline",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"INSERT IGNORE INTO tml_timelines"
|
2021-02-27 16:30:41 +01:00
|
|
|
|
" (SessionId,NotCod)"
|
2021-11-21 01:22:59 +01:00
|
|
|
|
" VALUES"
|
|
|
|
|
" ('%s',%ld)",
|
|
|
|
|
Gbl.Session.Id,
|
|
|
|
|
NotCod);
|
2021-02-27 16:30:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 17:23:22 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-11-21 01:22:59 +01:00
|
|
|
|
/********** Drop temporary table with all notes visible in timeline **********/
|
2021-02-27 17:23:22 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-21 01:22:59 +01:00
|
|
|
|
void Tml_DB_DropTmpTableTimeline (void)
|
2021-02-27 17:23:22 +01:00
|
|
|
|
{
|
2021-11-21 01:22:59 +01:00
|
|
|
|
DB_DropTmpTable ("tml_tmp_timeline");
|
2021-02-27 17:23:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Clear unused old timelines in database ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_ClearOldTimelinesNotesFromDB (void)
|
2021-02-27 17:23:22 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove old timelines",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE LOW_PRIORITY FROM tml_timelines"
|
2021-03-18 20:47:28 +01:00
|
|
|
|
" WHERE SessionId NOT IN"
|
|
|
|
|
" (SELECT SessionId"
|
|
|
|
|
" FROM ses_sessions)");
|
2021-02-27 17:23:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Clear timeline for a session in database ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_ClearTimelineNotesOfSessionFromDB (void)
|
2021-02-27 17:23:22 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove timeline",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_timelines"
|
2021-02-27 17:23:22 +01:00
|
|
|
|
" WHERE SessionId='%s'",
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Session.Id);
|
2021-02-27 17:23:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 16:16:46 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Remove favs for a note **************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveNoteFavs (long NotCod)
|
2021-02-27 16:16:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove favs for note",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_notes_fav"
|
2021-02-27 16:16:46 +01:00
|
|
|
|
" WHERE NotCod=%ld",
|
|
|
|
|
NotCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Remove all publications of this note *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveNotePubs (long NotCod)
|
2021-02-27 16:16:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a publication",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_pubs"
|
2021-02-27 16:16:46 +01:00
|
|
|
|
" WHERE NotCod=%ld",
|
|
|
|
|
NotCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Remove note publication from database *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveNote (long NotCod)
|
2021-02-27 16:16:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a note",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_notes"
|
2021-02-27 16:16:46 +01:00
|
|
|
|
" WHERE NotCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND UsrCod=%ld", // Extra check: author
|
2021-02-27 16:16:46 +01:00
|
|
|
|
NotCod,
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
2021-02-27 16:16:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 13:56:58 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Remove all notes created by a user *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllNotesUsr (long UsrCod)
|
2021-03-01 13:56:58 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove notes",
|
2021-04-17 13:40:55 +02:00
|
|
|
|
"DELETE FROM tml_notes"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
2021-03-01 13:56:58 +01:00
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 19:14:11 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-03-01 13:26:59 +01:00
|
|
|
|
/********************* Get data of post using its code ***********************/
|
2021-02-27 19:14:11 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetPostByCod (long PstCod,MYSQL_RES **mysql_res)
|
2021-02-27 19:14:11 +01:00
|
|
|
|
{
|
2021-03-01 13:26:59 +01:00
|
|
|
|
/***** Trivial check: post code should be > 0 *****/
|
|
|
|
|
if (PstCod <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/***** Get data of post from database *****/
|
2021-02-27 19:14:11 +01:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get the content"
|
|
|
|
|
" of a post",
|
2021-03-01 13:26:59 +01:00
|
|
|
|
"SELECT Txt," // row[0]
|
|
|
|
|
"MedCod" // row[1]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_posts"
|
2021-02-27 19:14:11 +01:00
|
|
|
|
" WHERE PstCod=%ld",
|
|
|
|
|
PstCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 15:09:23 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Get code of media associated to post **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long Tml_DB_GetMedCodFromPost (long PstCod)
|
2021-02-27 15:09:23 +01:00
|
|
|
|
{
|
2023-03-10 17:21:04 +01:00
|
|
|
|
return Tml_DB_GetMedCod ("tml_posts","PstCod",PstCod);
|
2021-02-27 15:09:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 19:28:27 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Insert post content in database ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns code of just created post
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
long Tml_DB_CreateNewPost (const struct TmlPst_Content *Content)
|
2021-02-27 19:28:27 +01:00
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
DB_QueryINSERTandReturnCode ("can not create post",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"INSERT INTO tml_posts"
|
2021-02-27 19:28:27 +01:00
|
|
|
|
" (Txt,MedCod)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" ('%s',%ld)",
|
|
|
|
|
Content->Txt,
|
|
|
|
|
Content->Media.MedCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 16:16:46 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Remove post from database *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemovePost (long PstCod)
|
2021-02-27 16:16:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a post",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_posts"
|
2021-02-27 16:16:46 +01:00
|
|
|
|
" WHERE PstCod=%ld",
|
|
|
|
|
PstCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 14:06:12 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Remove all posts of a user ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllPostsUsr (long UsrCod)
|
2021-03-01 14:06:12 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove posts",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_posts"
|
2021-03-01 14:06:12 +01:00
|
|
|
|
" WHERE PstCod IN"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" (SELECT Cod"
|
|
|
|
|
" FROM tml_notes"
|
|
|
|
|
" WHERE UsrCod=%ld"
|
|
|
|
|
" AND NoteType=%u)",
|
2022-05-30 19:03:56 +02:00
|
|
|
|
UsrCod,(unsigned) TmlNot_POST);
|
2021-03-01 14:06:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 22:25:48 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Get number of comments in a note **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetNumCommsInNote (long NotCod)
|
2021-02-26 22:25:48 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of comments in a note",
|
2021-03-29 16:38:56 +02:00
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE NotCod=%ld"
|
|
|
|
|
" AND PubType=%u",
|
2021-11-05 23:41:26 +01:00
|
|
|
|
NotCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-02-26 22:25:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 22:34:11 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-09-11 17:44:00 +02:00
|
|
|
|
/******* Get publication codes of comments of a note from database ***********/
|
2021-02-27 14:57:13 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetComms (long NotCod,MYSQL_RES **mysql_res)
|
2021-02-27 14:57:13 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get comments",
|
|
|
|
|
"SELECT PubCod" // row[0]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE NotCod=%ld"
|
|
|
|
|
" AND PubType=%u",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
NotCod,(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-02-27 14:57:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-26 22:34:11 +01:00
|
|
|
|
/************** Get initial comments of a note from database *****************/
|
|
|
|
|
/*****************************************************************************/
|
2021-02-26 23:45:45 +01:00
|
|
|
|
// Returns the number of rows got
|
2021-02-26 22:34:11 +01:00
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetInitialComms (long NotCod,unsigned NumInitialCommsToGet,
|
|
|
|
|
MYSQL_RES **mysql_res)
|
2021-02-26 22:34:11 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get comments",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"SELECT tml_pubs.PubCod," // row[0]
|
|
|
|
|
"tml_pubs.PublisherCod," // row[1]
|
|
|
|
|
"tml_pubs.NotCod," // row[2]
|
|
|
|
|
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
|
|
|
|
|
"tml_comments.Txt," // row[4]
|
|
|
|
|
"tml_comments.MedCod" // row[5]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs,tml_comments"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_pubs.NotCod=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments.PubCod"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" ORDER BY tml_pubs.PubCod"
|
2021-02-26 22:34:11 +01:00
|
|
|
|
" LIMIT %lu",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
NotCod,(unsigned) TmlPub_COMMENT_TO_NOTE,
|
2021-03-02 00:54:26 +01:00
|
|
|
|
NumInitialCommsToGet);
|
2021-02-26 22:34:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 22:20:03 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get final comments of a note from database ******************/
|
|
|
|
|
/*****************************************************************************/
|
2021-02-26 23:45:45 +01:00
|
|
|
|
// Returns the number of rows got
|
2021-02-26 22:20:03 +01:00
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetFinalComms (long NotCod,unsigned NumFinalCommsToGet,
|
|
|
|
|
MYSQL_RES **mysql_res)
|
2021-02-26 22:20:03 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get comments",
|
2021-03-29 16:38:56 +02:00
|
|
|
|
"SELECT *"
|
|
|
|
|
" FROM (SELECT tml_pubs.PubCod," // row[0]
|
|
|
|
|
"tml_pubs.PublisherCod," // row[1]
|
|
|
|
|
"tml_pubs.NotCod," // row[2]
|
|
|
|
|
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
|
|
|
|
|
"tml_comments.Txt," // row[4]
|
|
|
|
|
"tml_comments.MedCod" // row[5]
|
|
|
|
|
" FROM tml_pubs,tml_comments"
|
|
|
|
|
" WHERE tml_pubs.NotCod=%ld"
|
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments.PubCod"
|
|
|
|
|
" ORDER BY tml_pubs.PubCod DESC"
|
|
|
|
|
" LIMIT %u) AS comments"
|
2021-02-26 22:34:11 +01:00
|
|
|
|
" ORDER BY PubCod",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
NotCod,(unsigned) TmlPub_COMMENT_TO_NOTE,
|
2021-03-02 00:54:26 +01:00
|
|
|
|
NumFinalCommsToGet);
|
2021-02-26 22:20:03 +01:00
|
|
|
|
}
|
2021-02-26 23:13:06 +01:00
|
|
|
|
|
2021-02-27 13:17:15 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Get data of comment using its code **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Tml_DB_GetCommDataByCod (long PubCod,MYSQL_RES **mysql_res)
|
2021-02-27 13:17:15 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Trivial check: publication code should be > 0 *****/
|
|
|
|
|
if (PubCod <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/***** Get data of comment from database *****/
|
|
|
|
|
return (unsigned)
|
2021-02-27 14:12:41 +01:00
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get data of comment",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"SELECT tml_pubs.PubCod," // row[0]
|
|
|
|
|
"tml_pubs.PublisherCod," // row[1]
|
|
|
|
|
"tml_pubs.NotCod," // row[2]
|
|
|
|
|
"UNIX_TIMESTAMP(tml_pubs.TimePublish)," // row[3]
|
|
|
|
|
"tml_comments.Txt," // row[4]
|
|
|
|
|
"tml_comments.MedCod" // row[5]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs,tml_comments"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_pubs.PubCod=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments.PubCod",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
PubCod,(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-02-27 13:17:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 23:13:06 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Insert comment content in database **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_InsertCommContent (long PubCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
const struct TmlPst_Content *Content)
|
2021-02-26 23:13:06 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryINSERT ("can not store comment content",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"INSERT INTO tml_comments"
|
2021-02-26 23:13:06 +01:00
|
|
|
|
" (PubCod,Txt,MedCod)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,'%s',%ld)",
|
|
|
|
|
PubCod,
|
|
|
|
|
Content->Txt,
|
|
|
|
|
Content->Media.MedCod);
|
|
|
|
|
}
|
2021-02-26 23:45:45 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-27 13:17:15 +01:00
|
|
|
|
/**************** Get code of media associated to comment ********************/
|
2021-02-26 23:45:45 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long Tml_DB_GetMedCodFromComm (long PubCod)
|
2021-02-26 23:45:45 +01:00
|
|
|
|
{
|
2023-03-10 17:21:04 +01:00
|
|
|
|
return Tml_DB_GetMedCod ("tml_comments","PubCod",PubCod);
|
2021-02-26 23:45:45 +01:00
|
|
|
|
}
|
2021-02-26 23:58:36 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Remove favs for comment from database ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveCommFavs (long PubCod)
|
2021-02-26 23:58:36 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove favs for comment",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_comments_fav"
|
2021-02-26 23:58:36 +01:00
|
|
|
|
" WHERE PubCod=%ld",
|
|
|
|
|
PubCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Remove content of comment from database *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveCommContent (long PubCod)
|
2021-02-26 23:58:36 +01:00
|
|
|
|
{
|
2021-02-27 13:17:15 +01:00
|
|
|
|
DB_QueryDELETE ("can not remove comment content",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_comments"
|
2021-02-26 23:58:36 +01:00
|
|
|
|
" WHERE PubCod=%ld",
|
|
|
|
|
PubCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Remove comment publication from database ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveCommPub (long PubCod)
|
2021-02-26 23:58:36 +01:00
|
|
|
|
{
|
2021-02-27 13:17:15 +01:00
|
|
|
|
DB_QueryDELETE ("can not remove comment",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_pubs"
|
2021-02-26 23:58:36 +01:00
|
|
|
|
" WHERE PubCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND PublisherCod=%ld" // Extra check: author
|
|
|
|
|
" AND PubType=%u", // Extra check: it's a comment
|
2021-02-26 23:58:36 +01:00
|
|
|
|
PubCod,
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-02-26 23:58:36 +01:00
|
|
|
|
}
|
2021-02-27 15:09:23 +01:00
|
|
|
|
|
2021-03-01 15:23:18 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-10-30 13:28:48 +02:00
|
|
|
|
/************* Remove all comments in all notes for a given user *************/
|
2021-03-01 15:23:18 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllCommsInAllNotesOf (long UsrCod)
|
2021-03-01 15:23:18 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove comments",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_comments"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" USING tml_notes,"
|
|
|
|
|
"tml_pubs,"
|
|
|
|
|
"tml_comments"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_notes.UsrCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND tml_notes.NotCod=tml_pubs.NotCod"
|
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments.PubCod",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
UsrCod,(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-03-01 15:23:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********** Remove all comments made by a given user in any note ************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllCommsMadeBy (long UsrCod)
|
2021-03-01 15:23:18 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove comments",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_comments"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" USING tml_pubs,"
|
|
|
|
|
"tml_comments"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_pubs.PublisherCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments.PubCod",
|
|
|
|
|
UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-03-01 15:23:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 15:09:23 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Get code of media associated to post/comment ****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-10 17:21:04 +01:00
|
|
|
|
static long Tml_DB_GetMedCod (const char *Table,const char *Field,long Cod)
|
2021-02-27 15:09:23 +01:00
|
|
|
|
{
|
2021-04-05 23:45:24 +02:00
|
|
|
|
return DB_QuerySELECTCode ("can not get media code",
|
|
|
|
|
"SELECT MedCod" // row[0]
|
|
|
|
|
" FROM %s"
|
|
|
|
|
" WHERE %s=%ld",
|
|
|
|
|
Table,
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Field,Cod);
|
2021-02-27 15:09:23 +01:00
|
|
|
|
}
|
2021-02-27 21:23:14 +01:00
|
|
|
|
|
2021-02-28 21:12:44 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******* Create temporary table and subquery with potential publishers *******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_CreateSubQueryPublishers (TmlUsr_UsrOrGbl_t UsrOrGbl,Usr_Who_t Who,
|
2021-11-18 01:29:48 +01:00
|
|
|
|
char **Table,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
char SubQuery[TmlPub_MAX_BYTES_SUBQUERY + 1])
|
2021-02-28 21:12:44 +01:00
|
|
|
|
{
|
2021-11-18 01:29:48 +01:00
|
|
|
|
switch (UsrOrGbl)
|
2021-02-28 21:12:44 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
case TmlUsr_TIMELINE_USR: // Show the timeline of a user
|
2021-11-18 01:29:48 +01:00
|
|
|
|
*Table = "";
|
|
|
|
|
sprintf (SubQuery,"tml_pubs.PublisherCod=%ld AND ",
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Usrs.Other.UsrDat.UsrCod);
|
|
|
|
|
break;
|
2021-12-31 14:51:44 +01:00
|
|
|
|
case TmlUsr_TIMELINE_GBL: // Show the global timeline
|
2021-11-18 01:29:48 +01:00
|
|
|
|
switch (Who)
|
2021-02-28 21:12:44 +01:00
|
|
|
|
{
|
|
|
|
|
case Usr_WHO_ME: // Show my timeline
|
2021-11-18 01:29:48 +01:00
|
|
|
|
*Table = "";
|
2021-12-31 14:51:44 +01:00
|
|
|
|
snprintf (SubQuery,TmlPub_MAX_BYTES_SUBQUERY + 1,
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"tml_pubs.PublisherCod=%ld AND ",
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
break;
|
|
|
|
|
case Usr_WHO_FOLLOWED: // Show the timeline of the users I follow
|
2021-05-07 19:11:57 +02:00
|
|
|
|
Fol_DB_CreateTmpTableMeAndUsrsIFollow ();
|
2021-11-18 01:29:48 +01:00
|
|
|
|
*Table = ",fol_tmp_me_and_followed";
|
|
|
|
|
Str_Copy (SubQuery,
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"tml_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod AND ",
|
2021-12-31 14:51:44 +01:00
|
|
|
|
TmlPub_MAX_BYTES_SUBQUERY);
|
2021-02-28 21:12:44 +01:00
|
|
|
|
break;
|
|
|
|
|
case Usr_WHO_ALL: // Show the timeline of all users
|
2021-11-18 01:29:48 +01:00
|
|
|
|
*Table = "";
|
|
|
|
|
SubQuery[0] = '\0';
|
2021-02-28 21:12:44 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-04-26 15:27:27 +02:00
|
|
|
|
Err_WrongWhoExit ();
|
2021-02-28 21:12:44 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-03-04 18:37:16 +01:00
|
|
|
|
/***** Create subqueries with range of publications to get from tml_pubs *****/
|
2021-02-28 21:12:44 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_CreateSubQueryRange (TmlPub_Range_t Range,long PubCod,
|
|
|
|
|
char SubQuery[TmlPub_MAX_BYTES_SUBQUERY + 1])
|
2021-02-28 21:12:44 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
static const char Operator[TmlPub_NUM_RANGES] =
|
2021-11-21 11:40:57 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
[TmlPub_TOP ] = '<',
|
|
|
|
|
[TmlPub_BOTTOM] = '>',
|
2021-11-21 11:40:57 +01:00
|
|
|
|
};
|
2021-02-28 21:12:44 +01:00
|
|
|
|
|
2021-11-21 11:40:57 +01:00
|
|
|
|
if (PubCod > 0)
|
2021-12-31 14:51:44 +01:00
|
|
|
|
snprintf (SubQuery,TmlPub_MAX_BYTES_SUBQUERY + 1,
|
2021-11-21 11:40:57 +01:00
|
|
|
|
"tml_pubs.PubCod%c%ld AND ",Operator[Range],PubCod);
|
2021-02-28 21:12:44 +01:00
|
|
|
|
else
|
2021-11-18 01:29:48 +01:00
|
|
|
|
SubQuery[0] = '\0';
|
2021-02-28 21:12:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 22:13:05 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Select the most recent publication *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2021-11-18 01:29:48 +01:00
|
|
|
|
unsigned Tml_DB_SelectTheMostRecentPub (MYSQL_RES **mysql_res,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
const struct TmlPub_SubQueries *SubQueries)
|
2021-02-27 22:13:05 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get publication",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"SELECT tml_pubs.PubCod," // row[0]
|
|
|
|
|
"tml_pubs.NotCod," // row[1]
|
|
|
|
|
"tml_pubs.PublisherCod," // row[2]
|
|
|
|
|
"tml_pubs.PubType" // row[3]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs%s"
|
2021-11-21 11:40:57 +01:00
|
|
|
|
" WHERE %s%s%s"
|
|
|
|
|
" tml_pubs.NotCod NOT IN"
|
|
|
|
|
" (SELECT NotCod"
|
|
|
|
|
" FROM tml_tmp_timeline)"
|
2021-11-14 01:13:07 +01:00
|
|
|
|
" ORDER BY tml_pubs.PubCod DESC"
|
|
|
|
|
" LIMIT 1",
|
2021-11-18 01:29:48 +01:00
|
|
|
|
SubQueries->Publishers.Table,
|
2021-11-21 11:52:19 +01:00
|
|
|
|
SubQueries->Range.Bottom,
|
|
|
|
|
SubQueries->Range.Top,
|
2021-11-21 11:40:57 +01:00
|
|
|
|
SubQueries->Publishers.SubQuery);
|
2021-02-27 22:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 13:26:59 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Get data of publication using its code *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Returns the number of rows got
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Tml_DB_GetPubDataByCod (long PubCod,MYSQL_RES **mysql_res)
|
2021-03-01 13:26:59 +01:00
|
|
|
|
{
|
|
|
|
|
/***** Trivial check: publication code should be > 0 *****/
|
|
|
|
|
if (PubCod <= 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2023-11-05 19:44:03 +01:00
|
|
|
|
/***** Get data of publication from database *****/
|
2021-03-01 13:26:59 +01:00
|
|
|
|
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]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE PubCod=%ld",
|
2021-03-01 13:26:59 +01:00
|
|
|
|
PubCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 22:13:05 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Get code of note of a publication *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long Tml_DB_GetNotCodFromPubCod (long PubCod)
|
2021-02-27 22:13:05 +01:00
|
|
|
|
{
|
2021-04-05 23:45:24 +02:00
|
|
|
|
return DB_QuerySELECTCode ("can not get code of note",
|
|
|
|
|
"SELECT NotCod"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE PubCod=%ld",
|
|
|
|
|
PubCod);
|
2021-02-27 22:13:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 21:23:14 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-11-18 01:29:48 +01:00
|
|
|
|
/************* Get first/last publication code stored in session *************/
|
2021-02-27 21:23:14 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
long Tml_DB_GetPubCodFromSession (TmlPub_FirstLast_t FirstLast)
|
2021-02-27 21:23:14 +01:00
|
|
|
|
{
|
2023-03-10 00:13:55 +01:00
|
|
|
|
static const char *FldName[TmlPub_NUM_FIRST_LAST] =
|
2021-11-18 01:29:48 +01:00
|
|
|
|
{
|
2021-12-31 14:51:44 +01:00
|
|
|
|
[TmlPub_FIRST] = "FirstPubCod",
|
|
|
|
|
[TmlPub_LAST ] = "LastPubCod",
|
2021-11-18 01:29:48 +01:00
|
|
|
|
};
|
2021-02-27 21:23:14 +01:00
|
|
|
|
long PubCod;
|
|
|
|
|
|
|
|
|
|
/***** Get last publication code from database *****/
|
2021-11-14 01:13:07 +01:00
|
|
|
|
PubCod = DB_QuerySELECTCode ("can not get publication code from session",
|
|
|
|
|
"SELECT %s" // row[0]
|
|
|
|
|
" FROM ses_sessions"
|
|
|
|
|
" WHERE SessionId='%s'",
|
2023-03-10 00:13:55 +01:00
|
|
|
|
FldName[FirstLast],
|
2021-11-14 01:13:07 +01:00
|
|
|
|
Gbl.Session.Id);
|
|
|
|
|
if (PubCod < 0)
|
2021-02-27 21:23:14 +01:00
|
|
|
|
PubCod = 0;
|
|
|
|
|
|
|
|
|
|
return PubCod;
|
|
|
|
|
}
|
2021-02-27 21:44:46 +01:00
|
|
|
|
|
2021-02-28 19:59:49 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Get number of publications from a user *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-04-17 01:57:19 +02:00
|
|
|
|
unsigned Tml_DB_GetNumPubsUsr (long UsrCod)
|
2021-02-28 19:59:49 +01:00
|
|
|
|
{
|
2021-04-17 01:57:19 +02:00
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of publications from a user",
|
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE PublisherCod=%ld",
|
|
|
|
|
UsrCod);
|
2021-02-28 19:59:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-04 14:36:35 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Get all publisher codes in a note, except me *****************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Tml_DB_GetPublishersInNoteExceptMe (MYSQL_RES **mysql_res,long PubCod)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get publishers of a note",
|
2021-11-06 12:13:05 +01:00
|
|
|
|
"SELECT DISTINCT "
|
|
|
|
|
"PublisherCod"
|
2021-10-04 14:36:35 +02:00
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE NotCod=(SELECT NotCod"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE PubCod=%ld)"
|
|
|
|
|
" AND PublisherCod<>%ld",
|
|
|
|
|
PubCod,
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 19:55:04 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************* Insert new publication in database ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
// Return just created publication code
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
long Tml_DB_CreateNewPub (const struct TmlPub_Publication *Pub)
|
2021-02-28 19:55:04 +01:00
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
DB_QueryINSERTandReturnCode ("can not publish note/comment",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"INSERT INTO tml_pubs"
|
2021-02-28 19:55:04 +01:00
|
|
|
|
" (NotCod,PublisherCod,PubType,TimePublish)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,%ld,%u,NOW())",
|
|
|
|
|
Pub->NotCod,
|
|
|
|
|
Pub->PublisherCod,
|
2021-11-10 00:39:09 +01:00
|
|
|
|
(unsigned) Pub->Type);
|
2021-02-28 19:55:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 21:44:46 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************** Update first publication code stored in session **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_UpdateFirstPubCodInSession (long FirstPubCod)
|
2021-02-27 21:44:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update first publication code into session",
|
2021-03-18 20:47:28 +01:00
|
|
|
|
"UPDATE ses_sessions"
|
|
|
|
|
" SET FirstPubCod=%ld"
|
2021-02-27 21:44:46 +01:00
|
|
|
|
" WHERE SessionId='%s'",
|
|
|
|
|
FirstPubCod,
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Session.Id);
|
2021-02-27 21:44:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************** Update last publication code stored in session **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_UpdateLastPubCodInSession (void)
|
2021-02-27 21:44:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update last publication code into session",
|
2021-03-18 20:47:28 +01:00
|
|
|
|
"UPDATE ses_sessions"
|
|
|
|
|
" SET LastPubCod="
|
|
|
|
|
"(SELECT IFNULL(MAX(PubCod),0)"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs)" // The most recent publication
|
2021-02-27 21:44:46 +01:00
|
|
|
|
" WHERE SessionId='%s'",
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Session.Id);
|
2021-02-27 21:44:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********* Update first and last publication codes stored in session *********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_UpdateFirstLastPubCodsInSession (long FirstPubCod)
|
2021-02-27 21:44:46 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update first/last publication codes into session",
|
2021-03-18 20:47:28 +01:00
|
|
|
|
"UPDATE ses_sessions"
|
|
|
|
|
" SET FirstPubCod=%ld,"
|
|
|
|
|
"LastPubCod="
|
|
|
|
|
"(SELECT IFNULL(MAX(PubCod),0)"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs)" // The most recent publication
|
2021-02-27 21:44:46 +01:00
|
|
|
|
" WHERE SessionId='%s'",
|
|
|
|
|
FirstPubCod,
|
2021-02-28 21:12:44 +01:00
|
|
|
|
Gbl.Session.Id);
|
2021-02-27 21:44:46 +01:00
|
|
|
|
}
|
2021-02-28 21:24:49 +01:00
|
|
|
|
|
2021-03-01 14:12:18 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-03-01 15:23:18 +01:00
|
|
|
|
/************** Remove all publications published by any user ****************/
|
|
|
|
|
/************** related to notes authored by a given user ****************/
|
2021-03-01 14:12:18 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllPubsPublishedByAnyUsrOfNotesAuthoredBy (long UsrCod)
|
2021-03-01 14:12:18 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove publications",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_pubs"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" USING tml_notes,"
|
|
|
|
|
"tml_pubs"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_notes.UsrCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND tml_notes.NotCod=tml_pubs.NotCod",
|
2021-03-01 14:12:18 +01:00
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 14:01:55 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-03-01 14:46:57 +01:00
|
|
|
|
/**************** Remove all publications published by a user ****************/
|
2021-03-01 14:01:55 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllPubsPublishedBy (long UsrCod)
|
2021-03-01 14:01:55 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove publications",
|
2021-04-17 13:40:55 +02:00
|
|
|
|
"DELETE FROM tml_pubs"
|
|
|
|
|
" WHERE PublisherCod=%ld",
|
2021-03-01 14:01:55 +01:00
|
|
|
|
UsrCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 21:47:18 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Check if a user has favourited a note ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
bool Tml_DB_CheckIfFavedByUsr (TmlUsr_FavSha_t FavSha,long Cod,long UsrCod)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
{
|
2021-11-05 23:41:26 +01:00
|
|
|
|
return
|
|
|
|
|
DB_QueryEXISTS ("can not check if a user has favourited",
|
|
|
|
|
"SELECT EXISTS"
|
|
|
|
|
"(SELECT *"
|
|
|
|
|
" FROM %s"
|
|
|
|
|
" WHERE %s=%ld"
|
|
|
|
|
" AND UsrCod=%ld)",
|
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],Cod,UsrCod);
|
2021-02-28 21:47:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 21:24:49 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-02-28 22:42:08 +01:00
|
|
|
|
/********* Get number of times a note/comment has been favourited ************/
|
2021-02-28 21:55:33 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
unsigned Tml_DB_GetNumFavers (TmlUsr_FavSha_t FavSha,long Cod,long UsrCod)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
{
|
2021-02-28 21:55:33 +01:00
|
|
|
|
return (unsigned)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
DB_QueryCOUNT ("can not get number of times has been favourited",
|
2021-03-29 16:38:56 +02:00
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM %s"
|
2021-02-28 22:42:08 +01:00
|
|
|
|
" WHERE %s=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND UsrCod<>%ld", // Extra check
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],Cod,
|
2021-02-28 22:42:08 +01:00
|
|
|
|
UsrCod); // The author
|
2021-02-28 21:55:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-28 22:42:08 +01:00
|
|
|
|
/******* Get list of users who have marked a note/comment as favourite *******/
|
2021-02-28 21:55:33 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
unsigned Tml_DB_GetFavers (TmlUsr_FavSha_t FavSha,
|
2021-03-04 17:47:08 +01:00
|
|
|
|
long Cod,long UsrCod,unsigned MaxUsrs,
|
|
|
|
|
MYSQL_RES **mysql_res)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
{
|
2021-02-28 21:55:33 +01:00
|
|
|
|
return (unsigned)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get favers",
|
|
|
|
|
"SELECT UsrCod" // row[0]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM %s"
|
2021-02-28 22:42:08 +01:00
|
|
|
|
" WHERE %s=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND UsrCod<>%ld" // Extra check
|
|
|
|
|
" ORDER BY FavCod"
|
|
|
|
|
" LIMIT %u",
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],Cod,
|
2021-02-28 22:42:08 +01:00
|
|
|
|
UsrCod,
|
|
|
|
|
MaxUsrs);
|
2021-02-28 21:55:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-28 22:42:08 +01:00
|
|
|
|
/**************** Mark note/comment as favourite in database *****************/
|
2021-02-28 21:24:49 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_MarkAsFav (TmlUsr_FavSha_t FavSha,long Cod)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
{
|
2021-02-28 21:24:49 +01:00
|
|
|
|
DB_QueryINSERT ("can not favourite comment",
|
2021-02-28 22:42:08 +01:00
|
|
|
|
"INSERT IGNORE INTO %s"
|
|
|
|
|
" (%s,UsrCod,TimeFav)"
|
2021-02-28 21:24:49 +01:00
|
|
|
|
" VALUES"
|
|
|
|
|
" (%ld,%ld,NOW())",
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],
|
2021-02-28 22:42:08 +01:00
|
|
|
|
Cod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
2021-02-28 21:24:49 +01:00
|
|
|
|
}
|
2021-02-28 21:44:10 +01:00
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-28 22:42:08 +01:00
|
|
|
|
/*************** Unmark note/comment as favourite in database ****************/
|
2021-02-28 21:44:10 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_UnmarkAsFav (TmlUsr_FavSha_t FavSha,long Cod)
|
2021-02-28 22:42:08 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not unfavourite",
|
|
|
|
|
"DELETE FROM %s"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" WHERE %s=%ld"
|
|
|
|
|
" AND UsrCod=%ld",
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],Cod,
|
2021-04-17 13:40:55 +02:00
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod);
|
2021-02-28 21:44:10 +01:00
|
|
|
|
}
|
2021-03-01 11:40:03 +01:00
|
|
|
|
|
2021-03-01 13:52:24 +01:00
|
|
|
|
/*****************************************************************************/
|
2021-03-01 14:46:57 +01:00
|
|
|
|
/********** Remove all favs made by a given user to any comment **************/
|
2021-03-01 13:52:24 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_RemoveAllFavsMadeByUsr (TmlUsr_FavSha_t FavSha,long UsrCod)
|
2021-03-01 13:52:24 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove favs",
|
2021-04-17 13:40:55 +02:00
|
|
|
|
"DELETE FROM %s"
|
|
|
|
|
" WHERE UsrCod=%ld",
|
|
|
|
|
Tml_DB_TableFav[FavSha],
|
|
|
|
|
UsrCod);
|
2021-03-01 13:52:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 14:46:57 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************ Remove all favs to notes/comments of a given user **************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-12-31 14:51:44 +01:00
|
|
|
|
void Tml_DB_RemoveAllFavsToPubsBy (TmlUsr_FavSha_t FavSha,long UsrCod)
|
2021-03-01 14:46:57 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove favs",
|
|
|
|
|
"DELETE FROM %s"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" USING tml_pubs,"
|
|
|
|
|
"%s"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_pubs.PublisherCod=%ld" // Author of the comment
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND tml_pubs.PubType=%u"
|
2021-05-04 19:58:33 +02:00
|
|
|
|
" AND tml_pubs.%s=%s.%s",
|
2021-03-04 17:47:08 +01:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2021-03-01 14:46:57 +01:00
|
|
|
|
UsrCod,
|
2021-03-04 17:47:08 +01:00
|
|
|
|
(unsigned) Tml_DB_PubTypeFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha],
|
2021-05-04 19:58:33 +02:00
|
|
|
|
Tml_DB_TableFav[FavSha],
|
2023-03-10 17:21:04 +01:00
|
|
|
|
Tml_DB_FieldFav[FavSha]);
|
2021-03-01 14:46:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*** Remove all favs to all comments in all notes authored by a given user ***/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveAllFavsToAllCommsInAllNotesBy (long UsrCod)
|
2021-03-01 14:46:57 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove favs",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_comments_fav"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" USING tml_notes,"
|
|
|
|
|
"tml_pubs,"
|
|
|
|
|
"tml_comments_fav"
|
2021-03-04 18:37:16 +01:00
|
|
|
|
" WHERE tml_notes.UsrCod=%ld" // Author of the note
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND tml_notes.NotCod=tml_pubs.NotCod"
|
|
|
|
|
" AND tml_pubs.PubType=%u"
|
|
|
|
|
" AND tml_pubs.PubCod=tml_comments_fav.PubCod",
|
|
|
|
|
UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_COMMENT_TO_NOTE);
|
2021-03-01 14:46:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 11:43:00 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Check if a user has published a note *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
bool Tml_DB_CheckIfSharedByUsr (long NotCod,long UsrCod)
|
2021-03-01 11:43:00 +01:00
|
|
|
|
{
|
2021-11-05 23:41:26 +01:00
|
|
|
|
return
|
|
|
|
|
DB_QueryEXISTS ("can not check if a user has shared a note",
|
|
|
|
|
"SELECT EXISTS"
|
|
|
|
|
"(SELECT *"
|
|
|
|
|
" FROM tml_pubs"
|
|
|
|
|
" WHERE NotCod=%ld"
|
|
|
|
|
" AND PublisherCod=%ld"
|
|
|
|
|
" AND PubType=%u)",
|
|
|
|
|
NotCod,
|
|
|
|
|
UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_SHARED_NOTE);
|
2021-03-01 11:43:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 11:48:44 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********** Get number of times a note has been shared in timeline ***********/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetNumSharers (long NotCod,long UsrCod)
|
2021-03-01 11:48:44 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QueryCOUNT ("can not get number of times a note has been shared",
|
2021-03-29 16:38:56 +02:00
|
|
|
|
"SELECT COUNT(*)"
|
|
|
|
|
" FROM tml_pubs"
|
2021-03-01 11:48:44 +01:00
|
|
|
|
" WHERE NotCod=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND PublisherCod<>%ld"
|
|
|
|
|
" AND PubType=%u",
|
2021-03-03 02:15:32 +01:00
|
|
|
|
NotCod,
|
|
|
|
|
UsrCod, // Author of the note
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_SHARED_NOTE);
|
2021-03-01 11:48:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 13:15:50 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Get list of users who have shared a note ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
unsigned Tml_DB_GetSharers (long NotCod,long UsrCod,unsigned MaxUsrs,
|
|
|
|
|
MYSQL_RES **mysql_res)
|
2021-03-01 13:15:50 +01:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get users",
|
|
|
|
|
"SELECT PublisherCod" // row[0]
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" FROM tml_pubs"
|
2021-03-01 13:15:50 +01:00
|
|
|
|
" WHERE NotCod=%ld"
|
2021-03-29 16:38:56 +02:00
|
|
|
|
" AND PublisherCod<>%ld"
|
|
|
|
|
" AND PubType=%u"
|
|
|
|
|
" ORDER BY PubCod"
|
|
|
|
|
" LIMIT %u",
|
2021-03-01 13:15:50 +01:00
|
|
|
|
NotCod,
|
|
|
|
|
UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_SHARED_NOTE,
|
2021-03-01 13:15:50 +01:00
|
|
|
|
MaxUsrs);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 11:40:03 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Remove shared publication from database ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-03-04 17:47:08 +01:00
|
|
|
|
void Tml_DB_RemoveSharedPub (long NotCod)
|
2021-03-01 11:40:03 +01:00
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a publication",
|
2021-03-04 18:37:16 +01:00
|
|
|
|
"DELETE FROM tml_pubs"
|
2021-03-01 11:40:03 +01:00
|
|
|
|
" WHERE NotCod=%ld"
|
2021-04-17 13:40:55 +02:00
|
|
|
|
" AND PublisherCod=%ld"
|
|
|
|
|
" AND PubType=%u", // Extra check: shared note
|
2021-03-01 11:40:03 +01:00
|
|
|
|
NotCod,
|
|
|
|
|
Gbl.Usrs.Me.UsrDat.UsrCod,
|
2021-12-31 14:51:44 +01:00
|
|
|
|
(unsigned) TmlPub_SHARED_NOTE);
|
2021-03-01 11:40:03 +01:00
|
|
|
|
}
|