diff --git a/css/swad15.117.css b/css/swad15.120.2.css
similarity index 100%
rename from css/swad15.117.css
rename to css/swad15.120.2.css
diff --git a/swad_changelog.h b/swad_changelog.h
index b9efd1bf1..d0940974a 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -122,13 +122,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
-#define Log_PLATFORM_VERSION "SWAD 15.120.1 (2016-01-19)"
-#define CSS_FILE "swad15.117.css"
+#define Log_PLATFORM_VERSION "SWAD 15.120.2 (2016-01-19)"
+#define CSS_FILE "swad15.120.2.css"
#define JS_FILE "swad15.118.4.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
+ Version 15.120.2: Jan 19, 2016 Code optimization on sharers or favers. (193491 lines)
Version 15.120.1: Jan 19, 2016 Show number of users who marked a social note as favourite. (193533 lines)
Version 15.120: Jan 19, 2016 Mark/unmark social notes as favourites. (193475 lines)
Version 15.119: Jan 18, 2016 New table to mark social notes as favourites. (193036 lines)
diff --git a/swad_social.c b/swad_social.c
index 091c80d19..fbb87a333 100644
--- a/swad_social.c
+++ b/swad_social.c
@@ -312,6 +312,7 @@ static void Soc_UpdateNumTimesANoteHasBeenFav (struct SocialNote *SocNot);
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot);
static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot);
+static void Soc_ShowSharersOrFavers (unsigned NumUsrs,const char *Query);
static void Soc_GetDataOfSocialNoteByCod (struct SocialNote *SocNot);
static void Soc_GetDataOfSocialCommentByCod (struct SocialComment *SocCom);
@@ -3414,96 +3415,55 @@ static void Soc_UpdateNumTimesANoteHasBeenFav (struct SocialNote *SocNot)
/*****************************************************************************/
/**************** Show users who have shared this social note ****************/
/*****************************************************************************/
-// All forms in this function and nested functions must have unique identifiers
static void Soc_ShowUsrsWhoHaveSharedSocialNote (const struct SocialNote *SocNot)
{
char Query[256];
- MYSQL_RES *mysql_res;
- MYSQL_ROW row;
- unsigned NumUsrs;
- unsigned NumUsr;
- unsigned NumUsrsShown = 0;
- struct UsrData UsrDat;
- bool ShowPhoto;
- char PhotoURL[PATH_MAX+1];
- /***** Show number of users who have shared this social note *****/
- fprintf (Gbl.F.Out," %u",
- SocNot->NumShared);
-
- if (SocNot->NumShared)
- {
- /***** Get list of publishers from database (only the first) *****/
- sprintf (Query,"SELECT PublisherCod"
- " FROM social_pubs"
- " WHERE NotCod='%ld'"
- " AND PublisherCod<>'%ld'"
- " AND PubType='%u'"
- " ORDER BY PubCod LIMIT %u",
- SocNot->NotCod,
- SocNot->UsrCod,
- (unsigned) Soc_PUB_SHARED_NOTE,
- Soc_MAX_SHARERS_FAVERS_SHOWN);
- NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get users who shared a social note");
- if (NumUsrs)
- {
- /***** Initialize structure with user's data *****/
- Usr_UsrDataConstructor (&UsrDat);
-
- /***** List users *****/
- for (NumUsr = 0;
- NumUsr < NumUsrs;
- NumUsr++)
- {
- /***** Get user *****/
- row = mysql_fetch_row (mysql_res);
-
- /* Get user's code (row[0]) */
- UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]);
-
- /***** Get user's data and show user's photo *****/
- if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat))
- {
- fprintf (Gbl.F.Out,"
");
- ShowPhoto = Pho_ShowUsrPhotoIsAllowed (&UsrDat,PhotoURL);
- Pho_ShowUsrPhoto (&UsrDat,ShowPhoto ? PhotoURL :
- NULL,
- "PHOTO18x24",Pho_ZOOM,true); // Use unique id
- fprintf (Gbl.F.Out,"
");
-
- NumUsrsShown++;
- }
- }
-
- /***** Free memory used for user's data *****/
- Usr_UsrDataDestructor (&UsrDat);
- }
-
- if (SocNot->NumShared > NumUsrsShown)
- fprintf (Gbl.F.Out,""
- "
![\"%u\"" \"%u\"](\"%s/ellipsis32x32.gif\"")
"
- "
",
- Gbl.Prefs.IconsURL,
- SocNot->NumShared - NumUsrsShown,
- SocNot->NumShared - NumUsrsShown);
- }
+ /***** Get users who have shared this note *****/
+ sprintf (Query,"SELECT PublisherCod"
+ " FROM social_pubs"
+ " WHERE NotCod='%ld'"
+ " AND PublisherCod<>'%ld'"
+ " AND PubType='%u'"
+ " ORDER BY PubCod LIMIT %u",
+ SocNot->NotCod,
+ SocNot->UsrCod,
+ (unsigned) Soc_PUB_SHARED_NOTE,
+ Soc_MAX_SHARERS_FAVERS_SHOWN);
+ Soc_ShowSharersOrFavers (SocNot->NumShared,Query);
}
+/*****************************************************************************/
+/********* Show users who have marked this social note as favourite **********/
+/*****************************************************************************/
+
+static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot)
+ {
+ char Query[256];
+
+ /***** Get users who have mark this note as favourite *****/
+ sprintf (Query,"SELECT UsrCod"
+ " FROM social_notes_fav"
+ " WHERE NotCod='%ld'"
+ " AND UsrCod<>'%ld'" // Extra check
+ " ORDER BY TimeFav LIMIT %u",
+ SocNot->NotCod,
+ SocNot->UsrCod,
+ Soc_MAX_SHARERS_FAVERS_SHOWN);
+ Soc_ShowSharersOrFavers (SocNot->NumFavs,Query);
+ }
/*****************************************************************************/
/********* Show users who have marked this social note as favourite **********/
/*****************************************************************************/
// All forms in this function and nested functions must have unique identifiers
-static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *SocNot)
+static void Soc_ShowSharersOrFavers (unsigned NumUsrs,const char *Query)
{
- char Query[256];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
- unsigned NumUsrs;
+ unsigned NumFirstUsrs;
unsigned NumUsr;
unsigned NumUsrsShown = 0;
struct UsrData UsrDat;
@@ -3512,28 +3472,20 @@ static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *S
/***** Show number of users who have marked this social note as favourite *****/
fprintf (Gbl.F.Out," %u",
- SocNot->NumFavs);
+ NumUsrs);
- if (SocNot->NumFavs)
+ if (NumUsrs)
{
- /***** Get list of publishers from database (only the first) *****/
- sprintf (Query,"SELECT UsrCod"
- " FROM social_notes_fav"
- " WHERE NotCod='%ld'"
- " AND UsrCod<>'%ld'" // Extra check
- " ORDER BY TimeFav LIMIT %u",
- SocNot->NotCod,
- SocNot->UsrCod,
- Soc_MAX_SHARERS_FAVERS_SHOWN);
- NumUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get users who fav a social note");
- if (NumUsrs)
+ /***** Get list of users from database *****/
+ NumFirstUsrs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get users");
+ if (NumFirstUsrs)
{
/***** Initialize structure with user's data *****/
Usr_UsrDataConstructor (&UsrDat);
/***** List users *****/
for (NumUsr = 0;
- NumUsr < NumUsrs;
+ NumUsr < NumFirstUsrs;
NumUsr++)
{
/***** Get user *****/
@@ -3560,15 +3512,15 @@ static void Soc_ShowUsrsWhoHaveMarkedSocialNoteAsFav (const struct SocialNote *S
Usr_UsrDataDestructor (&UsrDat);
}
- if (SocNot->NumFavs > NumUsrsShown)
+ if (NumUsrs > NumUsrsShown)
fprintf (Gbl.F.Out,""
"
![\"%u\"" \"%u\"](\"%s/ellipsis32x32.gif\"")
"
"
",
Gbl.Prefs.IconsURL,
- SocNot->NumFavs - NumUsrsShown,
- SocNot->NumFavs - NumUsrsShown);
+ NumUsrs - NumUsrsShown,
+ NumUsrs - NumUsrsShown);
}
}