Version 20.86.1: May 31, 2021 Queries moved to module swad_call_for_exam_database.

This commit is contained in:
acanas 2021-05-31 15:12:14 +02:00
parent 3699490179
commit 46821df404
5 changed files with 123 additions and 113 deletions

View File

@ -634,7 +634,6 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
extern const char *Hlp_ASSESSMENT_Calls_for_exams;
extern const char *Txt_Calls_for_exams;
extern const char *Txt_No_calls_for_exams_of_X;
char SubQueryStatus[64];
MYSQL_RES *mysql_res;
unsigned NumExaAnns;
unsigned NumExaAnn;
@ -643,26 +642,9 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
bool ICanEdit = (Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
/***** Build subquery about status depending on my role *****/
if (ICanEdit)
sprintf (SubQueryStatus,"Status<>%u",
(unsigned) Cfe_DELETED_CALL_FOR_EXAM);
else
sprintf (SubQueryStatus,"Status=%u",
(unsigned) Cfe_VISIBLE_CALL_FOR_EXAM);
/***** Get calls for exams (the most recent first)
in current course from database *****/
NumExaAnns = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get calls for exams"
" in this course for listing",
"SELECT ExaCod" // row[0]
" FROM cfe_exams"
" WHERE CrsCod=%ld"
" AND %s"
" ORDER BY ExamDate DESC",
Gbl.Hierarchy.Crs.CrsCod,
SubQueryStatus);
NumExaAnns = Cfe_DB_GetCallsForExamsInCurrentCrs (&mysql_res,ICanEdit);
/***** Begin box *****/
if (ICanEdit)
@ -674,43 +656,42 @@ static void Cfe_ListCallsForExams (struct Cfe_CallsForExams *CallsForExams,
NULL,NULL,
Hlp_ASSESSMENT_Calls_for_exams,Box_NOT_CLOSABLE);
/***** The result of the query may be empty *****/
if (!NumExaAnns)
if (NumExaAnns)
/***** List the existing calls for exams *****/
for (NumExaAnn = 0;
NumExaAnn < NumExaAnns;
NumExaAnn++)
{
/***** Get the code of the call for exam (row[0]) *****/
if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0)
Err_WrongCallForExamExit ();
/***** Allocate memory for the call for exam *****/
Cfe_AllocMemCallForExam (CallsForExams);
/***** Read the data of the call for exam *****/
Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod);
/***** Show call for exam *****/
HighLight = false;
if (ExaCod == CallsForExams->HighlightExaCod)
HighLight = true;
else if (CallsForExams->HighlightDate[0])
{
if (!strcmp (CallsForExams->CallForExam.ExamDate.YYYYMMDD,
CallsForExams->HighlightDate))
HighLight = true;
}
Cfe_ShowCallForExam (CallsForExams,ExaCod,TypeViewCallForExam,
HighLight);
/***** Free memory of the call for exam *****/
Cfe_FreeMemCallForExam (CallsForExams);
}
else
Ale_ShowAlert (Ale_INFO,Txt_No_calls_for_exams_of_X,
Gbl.Hierarchy.Crs.FullName);
/***** List the existing calls for exams *****/
for (NumExaAnn = 0;
NumExaAnn < NumExaAnns;
NumExaAnn++)
{
/***** Get the code of the call for exam (row[0]) *****/
if ((ExaCod = DB_GetNextCode (mysql_res)) <= 0)
Err_WrongCallForExamExit ();
/***** Allocate memory for the call for exam *****/
Cfe_AllocMemCallForExam (CallsForExams);
/***** Read the data of the call for exam *****/
Cfe_GetDataCallForExamFromDB (CallsForExams,ExaCod);
/***** Show call for exam *****/
HighLight = false;
if (ExaCod == CallsForExams->HighlightExaCod)
HighLight = true;
else if (CallsForExams->HighlightDate[0])
{
if (!strcmp (CallsForExams->CallForExam.ExamDate.YYYYMMDD,
CallsForExams->HighlightDate))
HighLight = true;
}
Cfe_ShowCallForExam (CallsForExams,ExaCod,TypeViewCallForExam,
HighLight);
/***** Free memory of the call for exam *****/
Cfe_FreeMemCallForExam (CallsForExams);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@ -764,16 +745,7 @@ void Cfe_CreateListCallsForExams (struct Cfe_CallsForExams *CallsForExams)
/***** Get exam dates (ordered from more recent to older)
of visible calls for exams
in current course from database *****/
NumExaAnns = (unsigned)
DB_QuerySELECT (&mysql_res,"can not get calls for exams in this course",
"SELECT ExaCod," // row[0]
"DATE(ExamDate)" // row[1]
" FROM cfe_exams"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY ExamDate DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Cfe_VISIBLE_CALL_FOR_EXAM);
NumExaAnns = Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (&mysql_res);
/***** The result of the query may be empty *****/
CallsForExams->Lst = NULL;
@ -841,25 +813,7 @@ static void Cfe_GetDataCallForExamFromDB (struct Cfe_CallsForExams *CallsForExam
unsigned Second;
/***** Get data of a call for exam from database *****/
if (DB_QuerySELECT (&mysql_res,"can not get data of a call for exam",
"SELECT CrsCod," // row[ 0]
"Status," // row[ 1]
"CrsFullName," // row[ 2]
"Year," // row[ 3]
"ExamSession," // row[ 4]
"CallDate," // row[ 5]
"ExamDate," // row[ 6]
"Duration," // row[ 7]
"Place," // row[ 8]
"ExamMode," // row[ 9]
"Structure," // row[10]
"DocRequired," // row[11]
"MatRequired," // row[12]
"MatAllowed," // row[13]
"OtherInfo" // row[14]
" FROM cfe_exams"
" WHERE ExaCod=%ld",
ExaCod) != 1)
if (Cfe_DB_GetDataCallForExam (&mysql_res,ExaCod) != 1)
Err_WrongCallForExamExit ();
/***** Get the data of the call for exam *****/

View File

@ -25,32 +25,10 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
// #define _GNU_SOURCE // For asprintf
// #include <stddef.h> // For NULL
// #include <stdio.h> // For sscanf, asprintf, etc.
// #include <stdlib.h> // For exit, system, malloc, calloc, free, etc.
// #include <string.h> // For string functions
// #include "swad_box.h"
#include "swad_call_for_exam.h"
#include "swad_call_for_exam_database.h"
// #include "swad_config.h"
#include "swad_database.h"
// #include "swad_degree_database.h"
// #include "swad_error.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_hierarchy.h"
// #include "swad_hierarchy_level.h"
// #include "swad_HTML.h"
// #include "swad_logo.h"
// #include "swad_notification.h"
// #include "swad_parameter.h"
// #include "swad_QR.h"
// #include "swad_RSS.h"
// #include "swad_string.h"
// #include "swad_timeline.h"
// #include "swad_timeline_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
@ -114,6 +92,85 @@ long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam)
CallForExam->OtherInfo);
}
/*****************************************************************************/
/**************** Get all calls for exams in current course ******************/
/*****************************************************************************/
unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res,bool ICanEdit)
{
char SubQueryStatus[64];
/***** Build subquery about status depending on my role *****/
if (ICanEdit)
sprintf (SubQueryStatus,"Status<>%u",
(unsigned) Cfe_DELETED_CALL_FOR_EXAM);
else
sprintf (SubQueryStatus,"Status=%u",
(unsigned) Cfe_VISIBLE_CALL_FOR_EXAM);
/***** Get calls for exams (the most recent first)
in current course from database *****/
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get calls for exams"
" in this course for listing",
"SELECT ExaCod" // row[0]
" FROM cfe_exams"
" WHERE CrsCod=%ld"
" AND %s"
" ORDER BY ExamDate DESC",
Gbl.Hierarchy.Crs.CrsCod,
SubQueryStatus);
}
/*****************************************************************************/
/**************** Get all calls for exams in current course ******************/
/*****************************************************************************/
unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res)
{
/***** Get exam dates (ordered from more recent to older)
of visible calls for exams
in current course from database *****/
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get calls for exams in this course",
"SELECT ExaCod," // row[0]
"DATE(ExamDate)" // row[1]
" FROM cfe_exams"
" WHERE CrsCod=%ld"
" AND Status=%u"
" ORDER BY ExamDate DESC",
Gbl.Hierarchy.Crs.CrsCod,
(unsigned) Cfe_VISIBLE_CALL_FOR_EXAM);
}
/*****************************************************************************/
/***************** Get data of a call for exam from database *****************/
/*****************************************************************************/
unsigned Cfe_DB_GetDataCallForExam (MYSQL_RES **mysql_res,long ExaCod)
{
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get data of a call for exam",
"SELECT CrsCod," // row[ 0]
"Status," // row[ 1]
"CrsFullName," // row[ 2]
"Year," // row[ 3]
"ExamSession," // row[ 4]
"CallDate," // row[ 5]
"ExamDate," // row[ 6]
"Duration," // row[ 7]
"Place," // row[ 8]
"ExamMode," // row[ 9]
"Structure," // row[10]
"DocRequired," // row[11]
"MatRequired," // row[12]
"MatAllowed," // row[13]
"OtherInfo" // row[14]
" FROM cfe_exams"
" WHERE ExaCod=%ld",
ExaCod);
}
/*****************************************************************************/
/***************** Modify a call for exam in the database ********************/
/*****************************************************************************/

View File

@ -27,13 +27,7 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
// #include <stdbool.h> // For boolean type
#include "swad_call_for_exam.h"
// #include "swad_constant.h"
// #include "swad_course.h"
// #include "swad_date.h"
// #include "swad_notification.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
@ -45,6 +39,10 @@
long Cfe_DB_CreateCallForExam (const struct Cfe_CallForExam *CallForExam);
unsigned Cfe_DB_GetCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res,bool ICanEdit);
unsigned Cfe_DB_GetVisibleCallsForExamsInCurrentCrs (MYSQL_RES **mysql_res);
unsigned Cfe_DB_GetDataCallForExam (MYSQL_RES **mysql_res,long ExaCod);
void Cfe_DB_ModifyCallForExam (const struct Cfe_CallForExam *CallForExam,
long ExaCod);
void Cfe_DB_UpdateNumUsrsNotifiedByEMailAboutCallForExam (long ExaCod,

View File

@ -602,14 +602,15 @@ 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 20.86 (2021-05-31)"
#define Log_PLATFORM_VERSION "SWAD 20.86.1 (2021-05-31)"
#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 20.86: May 31, 2021 New module swad_call_for_exam_database for database queries related to calls for exams. (? lines)
Version 20.86.1: May 31, 2021 Queries moved to module swad_call_for_exam_database. (312420 lines)
Version 20.86: May 31, 2021 New module swad_call_for_exam_database for database queries related to calls for exams. (312415 lines)
Version 20.85: May 28, 2021 Queries moved to module swad_degree_database. (312319 lines)
Version 20.84: May 27, 2021 New module swad_degree_database for database queries related to degrees. (312216 lines)
Version 20.83.1: May 27, 2021 Database function moved from swad_date to swad_setting. (311993 lines)

View File

@ -32,7 +32,7 @@
#include <string.h> // For string functions
#include "swad_attendance.h"
#include "swad_call_for_exam.h"
#include "swad_call_for_exam_database.h"
#include "swad_course.h"
#include "swad_course_config.h"
#include "swad_course_database.h"