Version 18.48.1

This commit is contained in:
Antonio Cañas Vargas 2019-02-18 09:40:46 +01:00
parent 664c0f4d5e
commit 9eb7a17d30
4 changed files with 67 additions and 103 deletions

View File

@ -5329,8 +5329,7 @@ void Act_AdjustCurrentAction (void)
default: default:
/* If there are some group types with groups in wich I must register, /* If there are some group types with groups in wich I must register,
the the only action possible is show a form to register in groups */ the the only action possible is show a form to register in groups */
if (Gbl.Action.Act == ActLogIn) // Only when login... if (Grp_GetIfAnyMandatoryGrpTypIsAvailable ()) // This query may be slow
if (Grp_ThereAreGrpTypesIMustRegister ()) // ...because this query is slow
{ {
Gbl.Action.Act = ActReqSelGrp; Gbl.Action.Act = ActReqSelGrp;
Tab_SetCurrentTab (); Tab_SetCurrentTab ();

View File

@ -402,10 +402,11 @@ En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 18.48 (2019-02-18)" #define Log_PLATFORM_VERSION "SWAD 18.48.1 (2019-02-18)"
#define CSS_FILE "swad18.41.1.css" #define CSS_FILE "swad18.41.1.css"
#define JS_FILE "swad18.32.1.js" #define JS_FILE "swad18.32.1.js"
/* /*
Version 18.48.1: Feb 18, 2019 Optimization on query about available mandatory group types. (237548 lines)
Version 18.48: Feb 18, 2019 Fixed bugs in actions related to account. Version 18.48: Feb 18, 2019 Fixed bugs in actions related to account.
Fixed bug related with groups. (237589 lines) Fixed bug related with groups. (237589 lines)
1 change necessary in database: 1 change necessary in database:

View File

@ -131,7 +131,7 @@ static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
static long Grp_GetTypeOfGroupOfAGroup (long GrpCod); static long Grp_GetTypeOfGroupOfAGroup (long GrpCod);
static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod); static unsigned long Grp_CountNumUsrsInNoGrpsOfType (Rol_Role_t Role,long GrpTypCod);
static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod); static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod);
static bool Grp_GetIfGrpIsAvailable (long GrpTypCod); static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod);
static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod, static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,long UsrCod,
struct ListCodGrps *LstGrps); struct ListCodGrps *LstGrps);
static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps); static bool Grp_CheckIfGrpIsInList (long GrpCod,struct ListCodGrps *LstGrps);
@ -1899,7 +1899,7 @@ static void Grp_ShowWarningToStdsToChangeGrps (void)
GrpTyp = &Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp]; GrpTyp = &Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp];
if (GrpTyp->NumGrps) // If there are groups of this type if (GrpTyp->NumGrps) // If there are groups of this type
if (Grp_GetFirstCodGrpIBelongTo (GrpTyp->GrpTypCod) < 0) // If I don't belong to any group if (Grp_GetFirstCodGrpIBelongTo (GrpTyp->GrpTypCod) < 0) // If I don't belong to any group
if (Grp_GetIfGrpIsAvailable (GrpTyp->GrpTypCod)) // If there is any group of this type available if (Grp_GetIfGrpTypIsAvailable (GrpTyp->GrpTypCod)) // If there is any group of this type available
{ {
if (GrpTyp->MandatoryEnrolment) if (GrpTyp->MandatoryEnrolment)
Ale_ShowAlert (Ale_WARNING,GrpTyp->MultipleEnrolment ? Txt_You_have_to_register_compulsorily_at_least_in_one_group_of_type_X : Ale_ShowAlert (Ale_WARNING,GrpTyp->MultipleEnrolment ? Txt_You_have_to_register_compulsorily_at_least_in_one_group_of_type_X :
@ -3360,10 +3360,11 @@ static long Grp_GetFirstCodGrpIBelongTo (long GrpTypCod)
/***** Get a group which I belong to from database *****/ /***** Get a group which I belong to from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not check if you belong to a group", NumRows = DB_QuerySELECT (&mysql_res,"can not check if you belong to a group",
"SELECT crs_grp.GrpCod FROM crs_grp,crs_grp_usr" "SELECT crs_grp.GrpCod"
" FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod=%ld" " WHERE crs_grp.GrpTypCod=%ld"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=%ld", " AND crs_grp_usr.UsrCod=%ld", // I belong
GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod); GrpTypCod,Gbl.Usrs.Me.UsrDat.UsrCod);
/***** Get the group *****/ /***** Get the group *****/
@ -3495,109 +3496,68 @@ bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat)
} }
/*****************************************************************************/ /*****************************************************************************/
/****** Are there any group types with groups in wich I must register? *******/ /**** Query if any mandatory group in this course is open and has vacants ****/
/*****************************************************************************/ /*****************************************************************************/
bool Grp_ThereAreGrpTypesIMustRegister (void) bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void)
{ {
unsigned NumGrpTypesEmptyIMustRegister; unsigned NumGrpTypes;
unsigned NumGrpTypesNotEmptyIMustRegister;
/***** /***** Get the number of types of group in this course
Number of group types: with one or more open groups with vacants, from database *****/
- with mandatory registration NumGrpTypes =
- with groups: (unsigned) DB_QueryCOUNT ("can not check if there has available mandatory group types",
- open "SELECT COUNT(GrpTypCod) FROM "
- not full "("
- empty
*****/
NumGrpTypesEmptyIMustRegister =
(unsigned) DB_QueryCOUNT ("can not get group types I must register",
// Mandatory group types open, which admit students
" SELECT COUNT(DISTINCT crs_grp_types.GrpTypCod)"
" FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.Mandatory='Y'" // Mandatory registration
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents>0" // Admits students
// Empty, without students
" AND crs_grp_types.GrpTypCod NOT IN"
// Mandatory group types open, which admit students, with students
" (SELECT DISTINCT crs_grp_types.GrpTypCod"
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
" WHERE crs_grp_types.CrsCod=%ld"
" AND crs_grp_types.Mandatory='Y'" // Mandatory registration
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents>0" // Admits students
" AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role=%u)",
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.CurrentCrs.Crs.CrsCod,
(unsigned) Rol_STD);
if (NumGrpTypesEmptyIMustRegister)
return true;
/***** // Available groups with students
Number of group types: "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
- with mandatory registration
- with groups:
- open
- not full
- not empty
- to which I don't belong
*****/
NumGrpTypesNotEmptyIMustRegister =
(unsigned) DB_QueryCOUNT ("can not get group types I must register",
// Number of group types
"SELECT COUNT(DISTINCT GrpTypCod) FROM"
// Mandatory group types open, which admit students, not full
" (SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
"COUNT(*) AS NumStudents," "COUNT(*) AS NumStudents,"
"crs_grp.MaxStudents as MaxStudents" "crs_grp.MaxStudents as MaxStudents"
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
" WHERE crs_grp_types.CrsCod=%ld" " WHERE crs_grp_types.CrsCod=%ld" // In this course
" AND crs_grp_types.Mandatory='Y'" // Mandatory registration
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" // Open " AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents > 0" // Admits students " AND crs_grp.MaxStudents > 0" // Admits students
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role=%u" " AND crs_usr.Role=%u" // With some student
" GROUP BY crs_grp.GrpCod" " GROUP BY crs_grp.GrpCod"
" HAVING NumStudents<MaxStudents)" // Not full " HAVING NumStudents<MaxStudents" // Not full
" AS mand_grp_types_open_not_full"
" WHERE GrpTypCod NOT IN"
// Mandatory group types to which I already belong " UNION "
" (SELECT DISTINCT crs_grp_types.GrpTypCod"
" FROM crs_grp_types,crs_grp,crs_grp_usr" // Available groups without students
" WHERE crs_grp_types.CrsCod=%ld" "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
" AND crs_grp_types.Mandatory='Y'" // Mandatory registration "0 AS NumStudents,"
"crs_grp.MaxStudents as MaxStudents"
" FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.CrsCod=%ld" // In this course
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" // Open " AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents > 0" // Admits students " AND crs_grp.MaxStudents > 0" // Admits students
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp.GrpCod NOT IN" // Only if empty
" AND crs_grp_usr.UsrCod=%ld)", " (SELECT crs_grp_usr.GrpCod"
" FROM crs_usr,crs_grp_usr"
" WHERE crs_usr.CrsCod=%ld"
" AND crs_usr.Role=%u"
" AND crs_usr.UsrCod=crs_grp_usr.UsrCod)"
") AS available_grp_types",
Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD,
Gbl.CurrentCrs.Crs.CrsCod, Gbl.CurrentCrs.Crs.CrsCod,
(unsigned) Rol_STD, Gbl.CurrentCrs.Crs.CrsCod,(unsigned) Rol_STD);
Gbl.CurrentCrs.Crs.CrsCod,
Gbl.Usrs.Me.UsrDat.UsrCod); return (NumGrpTypes != 0);
return (NumGrpTypesNotEmptyIMustRegister > 0);
} }
/*****************************************************************************/ /*****************************************************************************/
/********** Query if any group of a type is open and has vacants *************/ /********** Query if any group of a type is open and has vacants *************/
/*****************************************************************************/ /*****************************************************************************/
static bool Grp_GetIfGrpIsAvailable (long GrpTypCod) static bool Grp_GetIfGrpTypIsAvailable (long GrpTypCod)
{ {
unsigned NumGrpTypes; unsigned NumGrpTypes;
@ -3607,33 +3567,35 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod)
(unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups", (unsigned) DB_QueryCOUNT ("can not check if a type of group has available groups",
"SELECT COUNT(GrpTypCod) FROM " "SELECT COUNT(GrpTypCod) FROM "
"(" "("
// Groups with students
// Available groups with students
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
"COUNT(*) AS NumStudents," "COUNT(*) AS NumStudents,"
"crs_grp.MaxStudents as MaxStudents" "crs_grp.MaxStudents as MaxStudents"
" FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr" " FROM crs_grp_types,crs_grp,crs_grp_usr,crs_usr"
" WHERE crs_grp_types.GrpTypCod=%ld" " WHERE crs_grp_types.GrpTypCod=%ld" // Of this type
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" " AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents > 0" // Admits students
" AND crs_grp_types.CrsCod=crs_usr.CrsCod" " AND crs_grp_types.CrsCod=crs_usr.CrsCod"
" AND crs_grp.GrpCod=crs_grp_usr.GrpCod" " AND crs_grp.GrpCod=crs_grp_usr.GrpCod"
" AND crs_grp_usr.UsrCod=crs_usr.UsrCod" " AND crs_grp_usr.UsrCod=crs_usr.UsrCod"
" AND crs_usr.Role=%u" " AND crs_usr.Role=%u" // With some student
" GROUP BY crs_grp.GrpCod" " GROUP BY crs_grp.GrpCod"
" HAVING NumStudents<MaxStudents" " HAVING NumStudents<MaxStudents" // Not full
" UNION " " UNION "
// Groups without students // Available groups without students
"SELECT crs_grp_types.GrpTypCod AS GrpTypCod," "SELECT crs_grp_types.GrpTypCod AS GrpTypCod,"
"0 AS NumStudents," "0 AS NumStudents,"
"crs_grp.MaxStudents as MaxStudents" "crs_grp.MaxStudents as MaxStudents"
" FROM crs_grp_types,crs_grp" " FROM crs_grp_types,crs_grp"
" WHERE crs_grp_types.GrpTypCod=%ld" " WHERE crs_grp_types.GrpTypCod=%ld" // Of this type
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod" " AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.Open='Y'" " AND crs_grp.Open='Y'" // Open
" AND crs_grp.MaxStudents > 0" " AND crs_grp.MaxStudents > 0" // Admits students
" AND crs_grp.GrpCod NOT IN" " AND crs_grp.GrpCod NOT IN" // Only if empty
" (SELECT crs_grp_usr.GrpCod" " (SELECT crs_grp_usr.GrpCod"
" FROM crs_grp_types,crs_usr,crs_grp_usr" " FROM crs_grp_types,crs_usr,crs_grp_usr"
" WHERE crs_grp_types.GrpTypCod=%ld" " WHERE crs_grp_types.GrpTypCod=%ld"
@ -3642,6 +3604,7 @@ static bool Grp_GetIfGrpIsAvailable (long GrpTypCod)
" AND crs_usr.UsrCod=crs_grp_usr.UsrCod)" " AND crs_usr.UsrCod=crs_grp_usr.UsrCod)"
") AS available_grp_types", ") AS available_grp_types",
GrpTypCod,(unsigned) Rol_STD, GrpTypCod,(unsigned) Rol_STD,
GrpTypCod, GrpTypCod,
GrpTypCod,(unsigned) Rol_STD); GrpTypCod,(unsigned) Rol_STD);

View File

@ -186,7 +186,8 @@ bool Grp_GetIfIBelongToGrp (long GrpCod);
void Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (void); void Grp_FlushCacheUsrSharesAnyOfMyGrpsInCurrentCrs (void);
bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat); bool Grp_CheckIfUsrSharesAnyOfMyGrpsInCurrentCrs (const struct UsrData *UsrDat);
bool Grp_ThereAreGrpTypesIMustRegister (void); bool Grp_GetIfAnyMandatoryGrpTypIsAvailable (void);
void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps); void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps);
void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GrpNames); void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GrpNames);
void Grp_RecFormNewGrpTyp (void); void Grp_RecFormNewGrpTyp (void);