Version19.255

This commit is contained in:
acanas 2020-06-23 18:10:20 +02:00
parent 71ea7e1190
commit 7e4973bb9d
2 changed files with 92 additions and 132 deletions

View File

@ -556,7 +556,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 19.254.2 (2020-06-23)"
#define Log_PLATFORM_VERSION "SWAD 19.255 (2020-06-23)"
#define CSS_FILE "swad19.253.css"
#define JS_FILE "swad19.254.js"
/*
@ -566,8 +566,8 @@ TODO: Fix bug: Un estudiante recibe una notificaci
TODO: Fix bug: Cuando se pulsa en ver fichas, y luego en una ficha en "Ver trabajos" o "Ver exámenes", o lo que sea, sale dos veces ese estudiante.
TODO: No limitar el número de preguntas en un examen a ExaPrn_MAX_QUESTIONS_PER_EXAM_PRINT, sino asignar PrintedQuestions dinámicamente con malloc
TODO: Que al generar un examen sólo se cojan preguntas válidas. Y si ya está generado, al entrar de nuevo, que se vean en rojo.
TODO: Dentro de las funciones TstPrn_ShowUsrPrints y TstPrn_ShowOnePrint crear y llamar a una función común similar a ExaRes_CheckIfICanSeePrintResult
Version 19.255: Jun 23, 2020 Code refactoring in test results. (303625 lines)
Version 19.254.2: Jun 23, 2020 Matches results can only be changed to visible when match is at the end.
If teacher goes back in match, the results change antumatically to hidden. (303667 lines)
Version 19.254.1: Jun 23, 2020 Code refactoring in matches results. (303646 lines)

View File

@ -56,6 +56,12 @@
/******************************* Private types *******************************/
/*****************************************************************************/
struct TstRes_ICanView
{
bool Result;
bool Score;
};
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
@ -171,6 +177,11 @@ static void TstPrn_ShowPrintsSummaryRow (bool ItsMe,
unsigned NumTotalQsts,
unsigned NumTotalQstsNotBlank,
double TotalScoreOfAllTests);
static void TstRes_CheckIfICanSeePrintResult (const struct TstPrn_Print *Print,
long UsrCod,
struct TstRes_ICanView *ICanView);
static void TstPrn_ShowTagsPresentInAPrint (long ResCod);
/*****************************************************************************/
@ -1919,7 +1930,7 @@ void TstPrn_ShowMyPrints (void)
TstPrn_ShowHeaderPrints ();
/***** List my test exams *****/
TstCfg_GetConfigFromDB (); // To get feedback type
TstCfg_GetConfigFromDB (); // To get visibility
TstPrn_ShowUsrPrints (&Gbl.Usrs.Me.UsrDat);
/***** End table and box *****/
@ -2027,12 +2038,7 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
double TotalScoreOfAllTests = 0.0;
unsigned NumPrintsVisibleByTchs = 0;
bool ItsMe = Usr_ItsMe (UsrDat->UsrCod);
struct
{
bool NumQsts;
bool Score;
bool Exam;
} ICanView;
struct TstRes_ICanView ICanView;
char *ClassDat;
/***** Make database query *****/
@ -2043,14 +2049,7 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
*/
NumPrints =
(unsigned) DB_QuerySELECT (&mysql_res,"can not get test exams of a user",
"SELECT ExaCod," // row[0]
"UNIX_TIMESTAMP(StartTime)," // row[1]
"UNIX_TIMESTAMP(EndTime)," // row[2]
"NumQsts," // row[3]
"NumQstsNotBlank," // row[4]
"Sent," // row[5]
"AllowTeachers," // row[6]
"Score" // row[7]
"SELECT ExaCod" // row[0]
" FROM tst_exams"
" WHERE CrsCod=%ld AND UsrCod=%ld"
" AND EndTime>=FROM_UNIXTIME(%ld)"
@ -2074,55 +2073,23 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
{
row = mysql_fetch_row (mysql_res);
/* Get test code (row[0]) */
/* Get print code (row[0]) */
TstPrn_ResetPrint (&Print);
if ((Print.PrnCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of test exam.");
/* Get if exam has been sent (row[5]) */
Print.Sent = (row[5][0] == 'Y');
/* Get if teachers are allowed to see this test exam (row[6]) */
Print.AllowTeachers = (row[6][0] == 'Y');
/* Get print data */
TstPrn_GetPrintDataByPrnCod (&Print);
ClassDat = Print.AllowTeachers ? "DAT" :
"DAT_LIGHT";
"DAT_LIGHT";
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
ICanView.NumQsts = Print.Sent && ItsMe;
ICanView.Score = Print.Sent && ItsMe &&
TstVis_IsVisibleTotalScore (TstCfg_GetConfigVisibility ());
ICanView.Exam = Print.Sent && ItsMe;
break;
case Rol_NET:
case Rol_TCH:
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
ICanView.NumQsts = Print.Sent; // If the exam has been sent,
// teachers can see the number of questions
ICanView.Score =
ICanView.Exam = Print.Sent && (ItsMe || Print.AllowTeachers);
break;
case Rol_SYS_ADM:
ICanView.NumQsts =
ICanView.Score =
ICanView.Exam = true;
break;
default:
ICanView.NumQsts =
ICanView.Score =
ICanView.Exam = false;
break;
}
/* Get if I can see print result and score */
TstRes_CheckIfICanSeePrintResult (&Print,UsrDat->UsrCod,&ICanView);
if (NumPrint)
HTM_TR_Begin (NULL);
/* Write date and time (row[1] and row[2] hold UTC date-times) */
Print.TimeUTC[Dat_START_TIME] = Dat_GetUNIXTimeFromStr (row[1]);
Print.TimeUTC[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[2]);
/* Write dates and times */
UniqueId++;
for (StartEndTime = (Dat_StartEndTime_t) 0;
StartEndTime <= (Dat_StartEndTime_t) (Dat_NUM_START_END_TIME - 1);
@ -2139,36 +2106,20 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
free (Id);
}
/* Get number of questions (row[3]) */
if (sscanf (row[3],"%u",&Print.NumQsts) != 1)
Print.NumQsts = 0;
if (Print.AllowTeachers)
NumTotalQsts += Print.NumQsts;
/* Get number of questions not blank (row[4]) */
if (sscanf (row[4],"%u",&Print.NumQstsNotBlank) != 1)
Print.NumQstsNotBlank = 0;
if (Print.AllowTeachers)
NumTotalQstsNotBlank += Print.NumQstsNotBlank;
/* Get score (row[7]) */
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[7],"%lf",&Print.Score) != 1)
Print.Score = 0.0;
Str_SetDecimalPointToLocal (); // Return to local system
if (Print.AllowTeachers)
TotalScoreOfAllTests += Print.Score;
/* Write number of questions */
HTM_TD_Begin ("class=\"%s RT COLOR%u\"",ClassDat,Gbl.RowEvenOdd);
if (ICanView.NumQsts)
if (ICanView.Result)
HTM_Unsigned (Print.NumQsts);
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Write number of questions not blank */
HTM_TD_Begin ("class=\"%s RT COLOR%u\"",ClassDat,Gbl.RowEvenOdd);
if (ICanView.NumQsts)
if (ICanView.Result)
HTM_Unsigned (Print.NumQstsNotBlank);
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Write score */
@ -2179,6 +2130,8 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
HTM_Txt ("/");
HTM_Unsigned (Print.NumQsts);
}
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Write average score per question */
@ -2187,17 +2140,21 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
HTM_Double2Decimals (Print.NumQsts ? Print.Score /
(double) Print.NumQsts :
0.0);
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Write grade */
HTM_TD_Begin ("class=\"%s RT COLOR%u\"",ClassDat,Gbl.RowEvenOdd);
if (ICanView.Score)
TstPrn_ComputeAndShowGrade (Print.NumQsts,Print.Score,Tst_SCORE_MAX);
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
/* Link to show this test exam */
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
if (ICanView.Exam)
if (ICanView.Result)
{
Frm_StartForm (Gbl.Action.Act == ActSeeMyTstResCrs ? ActSeeOneTstResMe :
ActSeeOneTstResOth);
@ -2205,6 +2162,8 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
Ico_PutIconLink ("tasks.svg",Txt_View_test);
Frm_EndForm ();
}
else
Ico_PutIconNotVisible ();
HTM_TD_End ();
HTM_TR_End ();
@ -2214,8 +2173,8 @@ static void TstPrn_ShowUsrPrints (struct UsrData *UsrDat)
/***** Write totals for this user *****/
TstPrn_ShowPrintsSummaryRow (ItsMe,NumPrintsVisibleByTchs,
NumTotalQsts,NumTotalQstsNotBlank,
TotalScoreOfAllTests);
NumTotalQsts,NumTotalQstsNotBlank,
TotalScoreOfAllTests);
}
else
{
@ -2356,9 +2315,7 @@ void TstPrn_ShowOnePrint (void)
char PhotoURL[PATH_MAX + 1];
Dat_StartEndTime_t StartEndTime;
char *Id;
bool ItsMe;
bool ICanViewTest;
bool ICanViewScore;
struct TstRes_ICanView ICanView;
/***** Get the code of the test *****/
TstPrn_ResetPrint (&Print);
@ -2367,54 +2324,13 @@ void TstPrn_ShowOnePrint (void)
/***** Get test exam data *****/
TstPrn_GetPrintDataByPrnCod (&Print);
TstCfg_SetConfigVisibility (TstVis_MAX_VISIBILITY);
/***** Check if I can view this test exam *****/
ItsMe = Usr_ItsMe (Gbl.Usrs.Other.UsrDat.UsrCod);
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
ICanViewTest = ItsMe;
if (ItsMe)
{
TstCfg_GetConfigFromDB (); // To get feedback type
ICanViewScore = TstVis_IsVisibleTotalScore (TstCfg_GetConfigVisibility ());
}
else
ICanViewScore = false;
break;
case Rol_TCH:
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
switch (Gbl.Action.Act)
{
case ActSeeOneTstResMe:
ICanViewTest =
ICanViewScore = ItsMe;
break;
case ActSeeOneTstResOth:
ICanViewTest =
ICanViewScore = ItsMe ||
Print.AllowTeachers;
break;
default:
ICanViewTest =
ICanViewScore = false;
break;
}
break;
case Rol_SYS_ADM:
ICanViewTest =
ICanViewScore = true;
break;
default:
ICanViewTest =
ICanViewScore = false;
break;
}
/***** Get if I can see print result and score *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
TstCfg_GetConfigFromDB (); // To get visibility
TstRes_CheckIfICanSeePrintResult (&Print,Gbl.Usrs.Other.UsrDat.UsrCod,&ICanView);
if (ICanViewTest) // I am allowed to view this test exam
if (ICanView.Result) // I am allowed to view this test print result
{
/***** Get questions and user's answers of the test exam from database *****/
TstPrn_GetPrintQuestionsFromDB (&Print);
@ -2520,7 +2436,7 @@ void TstPrn_ShowOnePrint (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LB\"");
if (ICanViewScore)
if (ICanView.Score)
{
HTM_STRONG_Begin ();
HTM_Double2Decimals (Print.Score);
@ -2540,7 +2456,7 @@ void TstPrn_ShowOnePrint (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"DAT LB\"");
if (ICanViewScore)
if (ICanView.Score)
{
HTM_STRONG_Begin ();
TstPrn_ComputeAndShowGrade (Print.NumQsts,Print.Score,Tst_SCORE_MAX);
@ -2579,6 +2495,50 @@ void TstPrn_ShowOnePrint (void)
Lay_NoPermissionExit ();
}
/*****************************************************************************/
/****************** Get if I can see print result and score ******************/
/*****************************************************************************/
static void TstRes_CheckIfICanSeePrintResult (const struct TstPrn_Print *Print,
long UsrCod,
struct TstRes_ICanView *ICanView)
{
/***** Check if I can view print result and score *****/
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
// Depends on whether the print is sent or not
// if the print is not sent ==> I can not view results
ICanView->Result = Print->Sent && Usr_ItsMe (UsrCod);
if (ICanView->Result)
// Depends on 5 visibility icons associated to tests
ICanView->Score = TstVis_IsVisibleTotalScore (TstCfg_GetConfigVisibility ());
else
ICanView->Score = false;
break;
case Rol_NET:
case Rol_TCH:
case Rol_DEG_ADM:
case Rol_CTR_ADM:
case Rol_INS_ADM:
// Depends on whether the print is sent or not, and whether teachers are allowed
// if the print is not sent ==> I can not view results
// if teachers are not allowed ==> I can not view results (except if the print is mine)
ICanView->Result =
ICanView->Score = Print->Sent && (Print->AllowTeachers || Usr_ItsMe (UsrCod));
break;
case Rol_SYS_ADM:
ICanView->Result =
ICanView->Score = true;
break;
default:
ICanView->Result =
ICanView->Score = false;
break;
}
}
/*****************************************************************************/
/********************* Show test tags in this test exam **********************/
/*****************************************************************************/