mirror of https://github.com/acanas/swad-core.git
Version 21.28.1: Oct 10, 2021 Code refactoring in projects.
This commit is contained in:
parent
e7020b8a21
commit
07931f57db
|
@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par
|
|||
|
||||
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.28 (2021-10-09)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.28.1 (2021-10-10)"
|
||||
#define CSS_FILE "swad20.45.css"
|
||||
#define JS_FILE "swad20.69.1.js"
|
||||
/*
|
||||
TODO: Rename CENTRE to CENTER in help wiki.
|
||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||
|
||||
Version 21.28.1: Oct 10, 2021 Code refactoring in projects. (318975 lines)
|
||||
Version 21.28: Oct 09, 2021 New module swad_program_database for database queries related to course program. (319013 lines)
|
||||
Version 21.27.1: Oct 07, 2021 Queries moved to module swad_profile_database. (318855 lines)
|
||||
Version 21.27: Oct 07, 2021 New module swad_profile_database for database queries related to user's public profile. (318846 lines)
|
||||
|
|
|
@ -1928,8 +1928,8 @@ static void Fig_GetAndShowProjectsStats (void)
|
|||
double NumProjectsPerCourse = 0.0;
|
||||
|
||||
/***** Get the number of projects from this location *****/
|
||||
if ((NumProjects = Prj_GetNumProjects (Gbl.Scope.Current)))
|
||||
if ((NumCoursesWithProjects = Prj_GetNumCoursesWithProjects (Gbl.Scope.Current)) != 0)
|
||||
if ((NumProjects = Prj_DB_GetNumProjects (Gbl.Scope.Current)))
|
||||
if ((NumCoursesWithProjects = Prj_DB_GetNumCoursesWithProjects (Gbl.Scope.Current)) != 0)
|
||||
NumProjectsPerCourse = (double) NumProjects /
|
||||
(double) NumCoursesWithProjects;
|
||||
|
||||
|
|
|
@ -1360,51 +1360,19 @@ Bottom.End: | 49| 222|-->|-->-49| 222| | -49| 222|-->|--> 26| 2
|
|||
*/
|
||||
/* Step 1: Change all indexes involved to negative,
|
||||
necessary to preserve unique index (CrsCod,ItmInd) */
|
||||
Prg_DB_UpdateIndexRange ( (long) 0 ,
|
||||
Prg_DB_UpdateIndexRange ( (long) 0 , // ItmInd=-ItmInd
|
||||
(long) Top.Begin ,
|
||||
(long) Bottom.End ); // All indexes in both parts
|
||||
/*
|
||||
DB_QueryUPDATE ("can not exchange indexes of items",
|
||||
"UPDATE prg_items"
|
||||
" SET ItmInd=-ItmInd"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND ItmInd>=%u"
|
||||
" AND ItmInd<=%u",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Top.Begin,
|
||||
Bottom.End); // All indexes in both parts */
|
||||
|
||||
/* Step 2: Increase top indexes */
|
||||
Prg_DB_UpdateIndexRange ( (long) DiffEnd ,
|
||||
Prg_DB_UpdateIndexRange ( (long) DiffEnd , // ItmInd=-ItmInd+DiffEnd
|
||||
-((long) Top.End ),
|
||||
-((long) Top.Begin)); // All indexes in top part
|
||||
/*
|
||||
DB_QueryUPDATE ("can not exchange indexes of items",
|
||||
"UPDATE prg_items"
|
||||
" SET ItmInd=-ItmInd+%u"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND ItmInd>=-%u"
|
||||
" AND ItmInd<=-%u",
|
||||
DiffEnd,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Top.End,
|
||||
Top.Begin); // All indexes in top part */
|
||||
-((long) Top.Begin )); // All indexes in top part
|
||||
|
||||
/* Step 3: Decrease bottom indexes */
|
||||
Prg_DB_UpdateIndexRange (-((long) DiffBegin ),
|
||||
Prg_DB_UpdateIndexRange (-((long) DiffBegin ), // ItmInd=-ItmInd-DiffBegin
|
||||
-((long) Bottom.End ),
|
||||
-((long) Bottom.Begin)); // All indexes in bottom part
|
||||
/*
|
||||
DB_QueryUPDATE ("can not exchange indexes of items",
|
||||
"UPDATE prg_items"
|
||||
" SET ItmInd=-ItmInd-%u"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND ItmInd>=-%u"
|
||||
" AND ItmInd<=-%u",
|
||||
DiffBegin,
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Bottom.End,
|
||||
Bottom.Begin); // All indexes in bottom part */
|
||||
|
||||
/***** Unlock table *****/
|
||||
Prg_DB_UnlockTable ();
|
||||
|
|
|
@ -275,8 +275,8 @@ static void Prj_PutIconsToLockUnlockAllProjects (struct Prj_Projects *Projects);
|
|||
static void Prj_FormLockUnlock (const struct Prj_Project *Prj);
|
||||
static void Prj_PutIconOffLockedUnlocked (const struct Prj_Project *Prj);
|
||||
|
||||
static void Prj_LockProjectEditionInDB (long PrjCod);
|
||||
static void Prj_UnlockProjectEditionInDB (long PrjCod);
|
||||
static void Prj_DB_LockProjectEdition (long PrjCod);
|
||||
static void Prj_DB_UnlockProjectEdition (long PrjCod);
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -427,8 +427,10 @@ void Prj_ShowTableSelectedPrjs (void)
|
|||
/***** Allocate memory for the project *****/
|
||||
Prj_AllocMemProject (&Prj);
|
||||
|
||||
/***** Table head *****/
|
||||
/***** Begin table *****/
|
||||
HTM_TABLE_BeginWidePadding (2);
|
||||
|
||||
/***** Table head *****/
|
||||
Prj_ShowTableAllProjectsHead ();
|
||||
|
||||
/***** Write all the projects *****/
|
||||
|
@ -513,8 +515,10 @@ static void Prj_ShowPrjsInCurrentPage (void *Projects)
|
|||
/***** Allocate memory for the project *****/
|
||||
Prj_AllocMemProject (&Prj);
|
||||
|
||||
/***** Table head *****/
|
||||
/***** Begin table *****/
|
||||
HTM_TABLE_BeginWideMarginPadding (2);
|
||||
|
||||
/***** Table head *****/
|
||||
Prj_ShowProjectsHead ((struct Prj_Projects *) Projects,Prj_LIST_PROJECTS);
|
||||
|
||||
/***** Write all the projects *****/
|
||||
|
@ -1197,8 +1201,10 @@ void Prj_PrintOneProject (void)
|
|||
Gbl.Hierarchy.Deg.DegCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
/***** Table head *****/
|
||||
/***** Begin table *****/
|
||||
HTM_TABLE_BeginWideMarginPadding (2);
|
||||
|
||||
/***** Table head *****/
|
||||
Prj_ShowProjectsHead (&Projects,Prj_PRINT_ONE_PROJECT);
|
||||
|
||||
/***** Write project *****/
|
||||
|
@ -1273,13 +1279,11 @@ static void Prj_ShowOneProject (struct Prj_Projects *Projects,
|
|||
HTM_TD_Begin ("rowspan=\"3\" class=\"BIG_INDEX RT COLOR%u\"",
|
||||
Gbl.RowEvenOdd);
|
||||
HTM_Unsigned (NumIndex);
|
||||
|
||||
if (PrjIsFaulty)
|
||||
{
|
||||
HTM_BR ();
|
||||
Prj_PutWarningIcon ();
|
||||
}
|
||||
|
||||
HTM_TD_End ();
|
||||
break;
|
||||
default:
|
||||
|
@ -2501,7 +2505,6 @@ static void Prj_AddUsrsToProject (Prj_RoleInProject_t RoleInProject)
|
|||
struct Prj_Projects Projects;
|
||||
struct Prj_Project Prj;
|
||||
const char *Ptr;
|
||||
bool ItsMe;
|
||||
|
||||
/***** Reset projects *****/
|
||||
Prj_ResetProjects (&Projects);
|
||||
|
@ -2536,8 +2539,7 @@ static void Prj_AddUsrsToProject (Prj_RoleInProject_t RoleInProject)
|
|||
Gbl.Usrs.Other.UsrDat.UsrCod);
|
||||
|
||||
/* Flush cache */
|
||||
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
|
||||
if (ItsMe)
|
||||
if (Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod))
|
||||
Prj_FlushCacheMyRolesInProject ();
|
||||
|
||||
/* Show success alert */
|
||||
|
@ -3211,24 +3213,20 @@ void Prj_GetDataOfProjectByCod (struct Prj_Project *Prj)
|
|||
/* Get row */
|
||||
row = mysql_fetch_row (mysql_res);
|
||||
|
||||
/* Get code of the project (row[0]) */
|
||||
/* Get code of the project (row[0]),
|
||||
code of the course (row[1])
|
||||
and code of the department (row[2]) */
|
||||
Prj->PrjCod = Str_ConvertStrCodToLongCod (row[0]);
|
||||
|
||||
/* Get code of the course (row[1]) */
|
||||
Prj->CrsCod = Str_ConvertStrCodToLongCod (row[1]);
|
||||
|
||||
/* Get code of the department (row[2]) */
|
||||
Prj->DptCod = Str_ConvertStrCodToLongCod (row[2]);
|
||||
|
||||
/* Get whether the project is locked or not (row[3]) */
|
||||
/* Get whether the project is locked or not (row[3]),
|
||||
whether the project is hidden or not (row[4])
|
||||
and whether the project is assigned or not (row[5]) */
|
||||
Prj->Locked = (row[3][0] == 'Y') ? Prj_LOCKED :
|
||||
Prj_UNLOCKED;
|
||||
|
||||
/* Get whether the project is hidden or not (row[4]) */
|
||||
Prj->Hidden = (row[4][0] == 'Y') ? Prj_HIDDEN :
|
||||
Prj_VISIBL;
|
||||
|
||||
/* Get if project is assigned or not (row[5]) */
|
||||
Prj->Assigned = (row[5][0] == 'Y') ? Prj_ASSIGNED :
|
||||
Prj_NONASSIG;
|
||||
|
||||
|
@ -3246,10 +3244,9 @@ void Prj_GetDataOfProjectByCod (struct Prj_Project *Prj)
|
|||
break;
|
||||
}
|
||||
|
||||
/* Get creation date/time (row[8] holds the creation UTC time) */
|
||||
/* Get creation date/time (row[8] holds the creation UTC time)
|
||||
and modification date/time (row[9] holds the modification UTC time) */
|
||||
Prj->CreatTime = Dat_GetUNIXTimeFromStr (row[8]);
|
||||
|
||||
/* Get modification date/time (row[9] holds the modification UTC time) */
|
||||
Prj->ModifTime = Dat_GetUNIXTimeFromStr (row[9]);
|
||||
|
||||
/* Get title (row[10]), description (row[11]), required knowledge (row[12]),
|
||||
|
@ -4142,7 +4139,6 @@ void Prj_ShowFormConfig (void)
|
|||
HTM_TD_End ();
|
||||
|
||||
HTM_TR_End ();
|
||||
|
||||
HTM_TABLE_End ();
|
||||
|
||||
/***** Send button *****/
|
||||
|
@ -4364,7 +4360,7 @@ void Prj_LockSelectedPrjsEdition (void)
|
|||
for (NumPrj = 0;
|
||||
NumPrj < Projects.Num;
|
||||
NumPrj++)
|
||||
Prj_LockProjectEditionInDB (Projects.LstPrjCods[NumPrj]);
|
||||
Prj_DB_LockProjectEdition (Projects.LstPrjCods[NumPrj]);
|
||||
else // No projects found
|
||||
Ale_ShowAlert (Ale_INFO,Txt_No_projects);
|
||||
|
||||
|
@ -4401,7 +4397,7 @@ void Prj_UnloSelectedPrjsEdition (void)
|
|||
for (NumPrj = 0;
|
||||
NumPrj < Projects.Num;
|
||||
NumPrj++)
|
||||
Prj_UnlockProjectEditionInDB (Projects.LstPrjCods[NumPrj]);
|
||||
Prj_DB_UnlockProjectEdition (Projects.LstPrjCods[NumPrj]);
|
||||
else // No projects found
|
||||
Ale_ShowAlert (Ale_INFO,Txt_No_projects);
|
||||
|
||||
|
@ -4490,7 +4486,7 @@ void Prj_LockProjectEdition (void)
|
|||
if (Prj_CheckIfICanEditProject (&Prj))
|
||||
{
|
||||
/***** Lock project edition *****/
|
||||
Prj_LockProjectEditionInDB (Prj.PrjCod);
|
||||
Prj_DB_LockProjectEdition (Prj.PrjCod);
|
||||
Prj.Locked = Prj_LOCKED;
|
||||
|
||||
/***** Show updated form and icon *****/
|
||||
|
@ -4503,7 +4499,7 @@ void Prj_LockProjectEdition (void)
|
|||
Prj_FreeMemProject (&Prj);
|
||||
}
|
||||
|
||||
static void Prj_LockProjectEditionInDB (long PrjCod)
|
||||
static void Prj_DB_LockProjectEdition (long PrjCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not lock project edition",
|
||||
"UPDATE prj_projects"
|
||||
|
@ -4540,7 +4536,7 @@ void Prj_UnloProjectEdition (void)
|
|||
if (Prj_CheckIfICanEditProject (&Prj))
|
||||
{
|
||||
/***** Unlock project edition *****/
|
||||
Prj_UnlockProjectEditionInDB (Prj.PrjCod);
|
||||
Prj_DB_UnlockProjectEdition (Prj.PrjCod);
|
||||
Prj.Locked = Prj_UNLOCKED;
|
||||
|
||||
/***** Show updated form and icon *****/
|
||||
|
@ -4553,7 +4549,7 @@ void Prj_UnloProjectEdition (void)
|
|||
Prj_FreeMemProject (&Prj);
|
||||
}
|
||||
|
||||
static void Prj_UnlockProjectEditionInDB (long PrjCod)
|
||||
static void Prj_DB_UnlockProjectEdition (long PrjCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not lock project edition",
|
||||
"UPDATE prj_projects"
|
||||
|
@ -4601,8 +4597,6 @@ void Prj_RemoveCrsProjects (long CrsCod)
|
|||
|
||||
void Prj_RemoveUsrFromProjects (long UsrCod)
|
||||
{
|
||||
bool ItsMe;
|
||||
|
||||
/***** Remove user from projects *****/
|
||||
DB_QueryDELETE ("can not remove user from projects",
|
||||
"DELETE FROM prj_users"
|
||||
|
@ -4610,8 +4604,7 @@ void Prj_RemoveUsrFromProjects (long UsrCod)
|
|||
UsrCod);
|
||||
|
||||
/***** Flush cache *****/
|
||||
ItsMe = Usr_ItsMe (UsrCod);
|
||||
if (ItsMe)
|
||||
if (Usr_ItsMe (UsrCod))
|
||||
Prj_FlushCacheMyRolesInProject ();
|
||||
}
|
||||
|
||||
|
@ -4621,7 +4614,7 @@ void Prj_RemoveUsrFromProjects (long UsrCod)
|
|||
// Returns the number of courses with projects
|
||||
// in this location (all the platform, current degree or current course)
|
||||
|
||||
unsigned Prj_GetNumCoursesWithProjects (HieLvl_Level_t Scope)
|
||||
unsigned Prj_DB_GetNumCoursesWithProjects (HieLvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of courses with projects from database *****/
|
||||
switch (Scope)
|
||||
|
@ -4680,7 +4673,6 @@ unsigned Prj_GetNumCoursesWithProjects (HieLvl_Level_t Scope)
|
|||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=prj_projects.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
break;
|
||||
case HieLvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with projects",
|
||||
|
@ -4688,9 +4680,9 @@ unsigned Prj_GetNumCoursesWithProjects (HieLvl_Level_t Scope)
|
|||
" FROM prj_projects"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
Err_WrongScopeExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4699,7 +4691,7 @@ unsigned Prj_GetNumCoursesWithProjects (HieLvl_Level_t Scope)
|
|||
/*****************************************************************************/
|
||||
// Returns the number of projects in this location
|
||||
|
||||
unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
||||
unsigned Prj_DB_GetNumProjects (HieLvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of projects from database *****/
|
||||
switch (Scope)
|
||||
|
@ -4710,7 +4702,6 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
"SELECT COUNT(*)"
|
||||
" FROM prj_projects"
|
||||
" WHERE CrsCod>0");
|
||||
break;
|
||||
case HieLvl_CTY:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of projects",
|
||||
|
@ -4726,7 +4717,6 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=prj_projects.CrsCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
break;
|
||||
case HieLvl_INS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of projects",
|
||||
|
@ -4740,7 +4730,6 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=prj_projects.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
break;
|
||||
case HieLvl_CTR:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of projects",
|
||||
|
@ -4752,7 +4741,6 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=prj_projects.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
break;
|
||||
case HieLvl_DEG:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of projects",
|
||||
|
@ -4762,7 +4750,6 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=prj_projects.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
break;
|
||||
case HieLvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of projects",
|
||||
|
@ -4770,8 +4757,8 @@ unsigned Prj_GetNumProjects (HieLvl_Level_t Scope)
|
|||
" FROM prj_projects"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
Err_WrongScopeExit ();
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ void Prj_UnloProjectEdition (void);
|
|||
void Prj_RemoveCrsProjects (long CrsCod);
|
||||
void Prj_RemoveUsrFromProjects (long UsrCod);
|
||||
|
||||
unsigned Prj_GetNumCoursesWithProjects (HieLvl_Level_t Scope);
|
||||
unsigned Prj_GetNumProjects (HieLvl_Level_t Scope);
|
||||
unsigned Prj_DB_GetNumCoursesWithProjects (HieLvl_Level_t Scope);
|
||||
unsigned Prj_DB_GetNumProjects (HieLvl_Level_t Scope);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue