Version 23.24: Oct 03, 2023 Code refactoring in user's hierarchy.

This commit is contained in:
acanas 2023-10-03 18:36:48 +02:00
parent f92040dec2
commit 2f5fd84097
17 changed files with 48 additions and 141 deletions

View File

@ -1760,26 +1760,6 @@ static void Ctr_FormToGoToMap (struct Hie_Node *Ctr)
}
}
/*****************************************************************************/
/*********************** Check if I belong to a center ***********************/
/*****************************************************************************/
bool Ctr_CheckIfIBelongToCtr (long CtrCod)
{
unsigned NumMyCtr;
/***** Fill the list with the centers I belong to *****/
Hie_GetMyHierarchy (Hie_CTR);
/***** Check if the center passed as parameter is any of my centers *****/
for (NumMyCtr = 0;
NumMyCtr < Gbl.Usrs.Me.Hierarchy[Hie_CTR].Num;
NumMyCtr++)
if (Gbl.Usrs.Me.Hierarchy[Hie_CTR].Nodes[NumMyCtr].HieCod == CtrCod)
return true;
return false;
}
/*****************************************************************************/
/******************** Write parameter with code of center ********************/
/*****************************************************************************/

View File

@ -73,6 +73,4 @@ unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role);
void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs);
bool Ctr_CheckIfIBelongToCtr (long CtrCod);
#endif

View File

@ -632,10 +632,11 @@ TODO: Francisco Javier Fern
Me sale este error, no si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así?
"can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod')
*/
#define Log_PLATFORM_VERSION "SWAD 23.23.1 (2023-10-03)"
#define Log_PLATFORM_VERSION "SWAD 23.24 (2023-10-03)"
#define CSS_FILE "swad23.16.1.css"
#define JS_FILE "swad22.49.js"
/*
Version 23.24: Oct 03, 2023 Code refactoring in user's hierarchy. (336276 lines)
Version 23.23.1: Oct 03, 2023 Removed unused code in user's hierarchy. (336349 lines)
Version 23.23: Oct 03, 2023 Code refactoring in user's hierarchy. (336620 lines)
Version 23.22: Oct 03, 2023 Code refactoring in user's hierarchy. (336518 lines)

View File

@ -1774,26 +1774,6 @@ static void Cty_FormToGoToMap (struct Hie_Node *Cty)
}
}
/*****************************************************************************/
/********************** Check if I belong to a country **********************/
/*****************************************************************************/
bool Cty_CheckIfIBelongToCty (long CtyCod)
{
unsigned NumMyCty;
/***** Fill the list with the institutions I belong to *****/
Hie_GetMyHierarchy (Hie_CTY);
/***** Check if the country passed as parameter is any of my countries *****/
for (NumMyCty = 0;
NumMyCty < Gbl.Usrs.Me.Hierarchy[Hie_CTY].Num;
NumMyCty++)
if (Gbl.Usrs.Me.Hierarchy[Hie_CTY].Nodes[NumMyCty].HieCod == CtyCod)
return true;
return false;
}
/*****************************************************************************/
/******* Get number of users who don't claim to belong to any country ********/
/*****************************************************************************/

View File

@ -84,8 +84,6 @@ unsigned Cty_GetCachedNumCtysWithUsrs (Rol_Role_t Role);
void Cty_ListCtysFound (MYSQL_RES **mysql_res,unsigned NumCtys);
bool Cty_CheckIfIBelongToCty (long CtyCod);
void Cty_FlushCacheNumUsrsWhoDontClaimToBelongToAnyCty (void);
unsigned Cty_GetCachedNumUsrsWhoDontClaimToBelongToAnyCty (void);
unsigned Cty_GetNumUsrsWhoDontClaimToBelongToAnyCty (void);

View File

@ -744,8 +744,8 @@ static bool Crs_ListCoursesOfAYearForSeeing (unsigned Year)
}
/* Check if this course is one of my courses */
BgColor = (Enr_CheckIfIBelongToCrs (Crs->HieCod)) ? "BG_HIGHLIGHT" :
The_GetColorRows ();
BgColor = (Hie_CheckIfIBelongTo (Hie_CRS,Crs->HieCod)) ? "BG_HIGHLIGHT" :
The_GetColorRows ();
HTM_TR_Begin (NULL);

View File

@ -1642,26 +1642,6 @@ static void Deg_EditingDegreeDestructor (void)
}
}
/*****************************************************************************/
/*********************** Check if I belong to a degree ***********************/
/*****************************************************************************/
bool Deg_CheckIfIBelongToDeg (long DegCod)
{
unsigned NumMyDeg;
/***** Fill the list with the degrees I belong to *****/
Hie_GetMyHierarchy (Hie_DEG);
/***** Check if the degree passed as parameter is any of my degrees *****/
for (NumMyDeg = 0;
NumMyDeg < Gbl.Usrs.Me.Hierarchy[Hie_DEG].Num;
NumMyDeg++)
if (Gbl.Usrs.Me.Hierarchy[Hie_DEG].Nodes[NumMyDeg].HieCod == DegCod)
return true;
return false;
}
/*****************************************************************************/
/********* Get the degree in which a user is enroled in more courses *********/
/*****************************************************************************/

View File

@ -83,7 +83,6 @@ unsigned Deg_GetCachedNumDegsWithUsrs (Rol_Role_t Role);
void Deg_ListDegsFound (MYSQL_RES **mysql_res,unsigned NumCrss);
bool Deg_CheckIfIBelongToDeg (long DegCod);
void Deg_GetUsrMainDeg (long UsrCod,
char ShrtName[Hie_MAX_BYTES_SHRT_NAME + 1],
Rol_Role_t *MaxRole);

View File

@ -3221,27 +3221,6 @@ static void Enr_EffectivelyRemUsrFromCrs (struct Usr_Data *UsrDat,
Ale_CreateAlertUserNotFoundOrYouDoNotHavePermission ();
}
/*****************************************************************************/
/*********************** Check if I belong to a course ***********************/
/*****************************************************************************/
bool Enr_CheckIfIBelongToCrs (long CrsCod)
{
unsigned NumMyCrs;
/***** Fill the list with the courses I belong to *****/
Hie_GetMyHierarchy (Hie_CRS);
/***** Check if the course passed as parameter is any of my courses *****/
for (NumMyCrs = 0;
NumMyCrs < Gbl.Usrs.Me.Hierarchy[Hie_CRS].Num;
NumMyCrs++)
if (Gbl.Usrs.Me.Hierarchy[Hie_CRS].Nodes[NumMyCrs].HieCod == CrsCod)
return true;
return false;
}
/*****************************************************************************/
/***** Check if user belongs (no matter if he/she has accepted or not) *******/
/***** to the current course *******/

View File

@ -137,7 +137,6 @@ void Enr_CreateNewUsr2 (void);
void Enr_ModifyUsr1 (void);
void Enr_ModifyUsr2 (void);
bool Enr_CheckIfIBelongToCrs (long CrsCod);
void Enr_FlushCacheUsrBelongsToCurrentCrs (void);
bool Enr_CheckIfUsrBelongsToCurrentCrs (const struct Usr_Data *UsrDat);
void Enr_FlushCacheUsrHasAcceptedInCurrentCrs (void);

View File

@ -1261,7 +1261,7 @@ void For_ShowForumList (struct For_Forums *Forums)
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM)
ICanSeeInsForum = true;
else
ICanSeeInsForum = Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod);
ICanSeeInsForum = Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod);
}
else
ICanSeeInsForum = false;
@ -1274,7 +1274,7 @@ void For_ShowForumList (struct For_Forums *Forums)
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM)
ICanSeeCtrForum = true;
else
ICanSeeCtrForum = Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod);
ICanSeeCtrForum = Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod);
/***** Links to forums of current institution *****/
if (For_WriteLinksToInsForums (Forums,Gbl.Hierarchy.Node[Hie_INS].HieCod,
@ -1285,7 +1285,7 @@ void For_ShowForumList (struct For_Forums *Forums)
if (Gbl.Usrs.Me.Role.Logged >= Rol_DEG_ADM)
ICanSeeDegForum = true;
else
ICanSeeDegForum = Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod);
ICanSeeDegForum = Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod);
/***** Links to forums of current center *****/
if (For_WriteLinksToCtrForums (Forums,

View File

@ -1040,6 +1040,26 @@ void Hie_GetMyHierarchy (Hie_Level_t Level)
Gbl.Usrs.Me.Hierarchy[Level].Filled = true;
}
/*****************************************************************************/
/****** Check if I belong to a course/degree/center/institution/country ******/
/*****************************************************************************/
bool Hie_CheckIfIBelongTo (Hie_Level_t Level,long HieCod)
{
unsigned NumMyNode;
/***** Fill the list with the centers I belong to *****/
Hie_GetMyHierarchy (Level);
/***** Check if the node passed as parameter is any of my nodes *****/
for (NumMyNode = 0;
NumMyNode < Gbl.Usrs.Me.Hierarchy[Level].Num;
NumMyNode++)
if (Gbl.Usrs.Me.Hierarchy[Level].Nodes[NumMyNode].HieCod == HieCod)
return true;
return false;
}
/*****************************************************************************/
/*** Flush cache that stores if a user belongs to a node of the hierarchy ****/
/*****************************************************************************/

View File

@ -67,6 +67,7 @@ void Hie_FreeList (Hie_Level_t Level);
void Hie_ResetMyHierarchy (void);
void Hie_FreeMyHierarchy (void);
void Hie_GetMyHierarchy (Hie_Level_t Level);
bool Hie_CheckIfIBelongTo (Hie_Level_t Level,long HieCod);
void Hie_FlushCacheUsrBelongsTo (Hie_Level_t Level);
bool Hie_CheckIfUsrBelongsTo (Hie_Level_t Level,long UsrCod,long HieCod,

View File

@ -1683,26 +1683,6 @@ static void Ins_FormToGoToMap (struct Hie_Node *Ins)
}
}
/*****************************************************************************/
/******************** Check if I belong to an institution ********************/
/*****************************************************************************/
bool Ins_CheckIfIBelongToIns (long InsCod)
{
unsigned NumMyIns;
/***** Fill the list with the institutions I belong to *****/
Hie_GetMyHierarchy (Hie_INS);
/***** Check if the institution passed as parameter is any of my institutions *****/
for (NumMyIns = 0;
NumMyIns < Gbl.Usrs.Me.Hierarchy[Hie_INS].Num;
NumMyIns++)
if (Gbl.Usrs.Me.Hierarchy[Hie_INS].Nodes[NumMyIns].HieCod == InsCod)
return true;
return false;
}
/*****************************************************************************/
/***************** Write parameter with code of institution ******************/
/*****************************************************************************/

View File

@ -70,8 +70,6 @@ unsigned Ins_GetCachedNumInssWithUsrs (Rol_Role_t Role);
void Ins_ListInssFound (MYSQL_RES **mysql_res,unsigned NumInss);
bool Ins_CheckIfIBelongToIns (long InsCod);
void Ins_PutParInsCod (void *InsCod);
//-------------------------------- Figures ------------------------------------

View File

@ -143,7 +143,7 @@ void Rol_SetMyRoles (void)
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
Gbl.Usrs.Me.IBelongToCurrentDeg = true;
else
Gbl.Usrs.Me.IBelongToCurrentDeg = Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod);
Gbl.Usrs.Me.IBelongToCurrentDeg = Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentDeg = false;
@ -154,7 +154,7 @@ void Rol_SetMyRoles (void)
if (Gbl.Usrs.Me.IBelongToCurrentDeg)
Gbl.Usrs.Me.IBelongToCurrentCtr = true;
else
Gbl.Usrs.Me.IBelongToCurrentCtr = Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod);
Gbl.Usrs.Me.IBelongToCurrentCtr = Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentCtr = false;
@ -165,7 +165,7 @@ void Rol_SetMyRoles (void)
if (Gbl.Usrs.Me.IBelongToCurrentCtr)
Gbl.Usrs.Me.IBelongToCurrentIns = true;
else
Gbl.Usrs.Me.IBelongToCurrentIns = Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod);
Gbl.Usrs.Me.IBelongToCurrentIns = Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod);
}
else
Gbl.Usrs.Me.IBelongToCurrentIns = false;

View File

@ -965,16 +965,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
// ...but not belonging to the current course *********
*ScopesAllowed = 1 << Hie_SYS;
*HiddenAllowed = 0;
if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTY;
if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod))
if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod))
{
*ScopesAllowed |= 1 << Hie_INS;
if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTR;
if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod))
if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod))
*ScopesAllowed |= 1 << Hie_DEG;
}
}
@ -983,16 +983,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
case Rol_STD: // Student in current course **************************
*ScopesAllowed = 1 << Hie_SYS;
*HiddenAllowed = 0;
if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTY;
if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod))
if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod))
{
*ScopesAllowed |= 1 << Hie_INS;
if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTR;
if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod))
if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod))
{
*ScopesAllowed |= 1 << Hie_DEG;
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
@ -1006,16 +1006,16 @@ static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
case Rol_TCH: // Teacher in current course **************************
*ScopesAllowed = 1 << Hie_SYS;
*HiddenAllowed = 0;
if (Cty_CheckIfIBelongToCty (Gbl.Hierarchy.Node[Hie_CTY].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTY,Gbl.Hierarchy.Node[Hie_CTY].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTY;
if (Ins_CheckIfIBelongToIns (Gbl.Hierarchy.Node[Hie_INS].HieCod))
if (Hie_CheckIfIBelongTo (Hie_INS,Gbl.Hierarchy.Node[Hie_INS].HieCod))
{
*ScopesAllowed |= 1 << Hie_INS;
if (Ctr_CheckIfIBelongToCtr (Gbl.Hierarchy.Node[Hie_CTR].HieCod))
if (Hie_CheckIfIBelongTo (Hie_CTR,Gbl.Hierarchy.Node[Hie_CTR].HieCod))
{
*ScopesAllowed |= 1 << Hie_CTR;
if (Deg_CheckIfIBelongToDeg (Gbl.Hierarchy.Node[Hie_DEG].HieCod))
if (Hie_CheckIfIBelongTo (Hie_DEG,Gbl.Hierarchy.Node[Hie_DEG].HieCod))
{
*ScopesAllowed |= 1 << Hie_DEG;
if (Gbl.Usrs.Me.IBelongToCurrentCrs)
@ -1167,28 +1167,22 @@ void Svy_GetSurveyDataByCod (struct Svy_Survey *Svy)
/* Do I belong to valid groups to answer this survey? */
switch (Svy->Level)
{
case Hie_UNK: // Unknown
Err_WrongHierarchyLevelExit ();
break;
case Hie_SYS: // System
Svy->Status.IBelongToScope = Gbl.Usrs.Me.Logged;
break;
case Hie_CTY: // Country
Svy->Status.IBelongToScope = Cty_CheckIfIBelongToCty (Svy->HieCod);
break;
case Hie_INS: // Institution
Svy->Status.IBelongToScope = Ins_CheckIfIBelongToIns (Svy->HieCod);
break;
case Hie_CTR: // Center
Svy->Status.IBelongToScope = Ctr_CheckIfIBelongToCtr (Svy->HieCod);
break;
case Hie_DEG: // Degree
Svy->Status.IBelongToScope = Deg_CheckIfIBelongToDeg (Svy->HieCod);
Svy->Status.IBelongToScope = Hie_CheckIfIBelongTo (Svy->Level,Svy->HieCod);
break;
case Hie_CRS: // Course
Svy->Status.IBelongToScope = Enr_CheckIfIBelongToCrs (Svy->HieCod) &&
Svy->Status.IBelongToScope = Hie_CheckIfIBelongTo (Svy->Level,Svy->HieCod) &&
Svy_DB_CheckIfICanDoThisSurveyBasedOnGrps (Svy->SvyCod);
break;
default: // Unknown
Err_WrongHierarchyLevelExit ();
break;
}
/* Have I answered this survey? */