mirror of https://github.com/acanas/swad-core.git
Version 21.48: Nov 03, 2021 New module swad_timetable_database for database queries related to timetables.
This commit is contained in:
parent
ee52848fca
commit
84aa601825
2
Makefile
2
Makefile
|
@ -90,7 +90,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
|||
swad_timeline_favourite.o swad_timeline_form.o swad_timeline_note.o \
|
||||
swad_timeline_notification.o swad_timeline_post.o \
|
||||
swad_timeline_publication.o swad_timeline_share.o swad_timeline_user.o \
|
||||
swad_timeline_who.o swad_timetable.o \
|
||||
swad_timeline_who.o swad_timetable.o swad_timetable_database.o \
|
||||
swad_user.o \
|
||||
swad_xml.o \
|
||||
swad_zip.o
|
||||
|
|
|
@ -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 21.47.5 (2021-10-30)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 21.48 (2021-11-03)"
|
||||
#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.47.5: Oct 29, 2021 Queries moved to module swad_questions_database. (321308 lines)
|
||||
Version 21.48: Nov 03, 2021 New module swad_timetable_database for database queries related to timetables. (321438 lines)
|
||||
Version 21.47.5: Oct 30, 2021 Queries moved to module swad_questions_database. (321308 lines)
|
||||
Version 21.47.4: Oct 30, 2021 Review of comments. (321253 lines)
|
||||
Version 21.47.3: Oct 29, 2021 Queries moved to module swad_questions_database. (321299 lines)
|
||||
Version 21.47.2: Oct 29, 2021 Queries moved to module swad_questions_database. (321259 lines)
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "swad_survey.h"
|
||||
#include "swad_survey_database.h"
|
||||
#include "swad_timetable.h"
|
||||
#include "swad_timetable_database.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Private constants *******************************/
|
||||
|
|
274
swad_timetable.c
274
swad_timetable.c
|
@ -42,6 +42,7 @@
|
|||
#include "swad_parameter.h"
|
||||
#include "swad_setting.h"
|
||||
#include "swad_timetable.h"
|
||||
#include "swad_timetable_database.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** External constants ******************************/
|
||||
|
@ -81,16 +82,6 @@ extern struct Globals Gbl;
|
|||
#define Tmt_MAX_BYTES_STR_CLASS_TYPE 256
|
||||
#define Tmt_MAX_BYTES_STR_DURATION 32 // "hh:mm h"
|
||||
|
||||
struct Tmt_Column
|
||||
{
|
||||
long CrsCod; // Course code (-1 if no course selected)
|
||||
long GrpCod; // Group code (-1 if no group selected)
|
||||
Tmt_IntervalType_t IntervalType;
|
||||
Tmt_ClassType_t ClassType;
|
||||
unsigned DurationIntervals;
|
||||
char Info[Tmt_MAX_BYTES_INFO + 1];
|
||||
};
|
||||
|
||||
struct Tmt_Cell
|
||||
{
|
||||
unsigned NumColumns;
|
||||
|
@ -101,14 +92,6 @@ struct Tmt_Cell
|
|||
/************************** Private global variables *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *Tmt_ClassTypeDB[Tmt_NUM_CLASS_TYPES] =
|
||||
{
|
||||
[Tmt_FREE ] = "free",
|
||||
[Tmt_LECTURE ] = "lecture",
|
||||
[Tmt_PRACTICAL] = "practical",
|
||||
[Tmt_TUTORING ] = "tutoring",
|
||||
};
|
||||
|
||||
struct Tmt_Cell *Tmt_TimeTable[Tmt_DAYS_PER_WEEK];
|
||||
|
||||
/* Possible resolutions of the timetable in minutes */
|
||||
|
@ -137,7 +120,7 @@ static void Tmt_PutIconToViewMyTT (__attribute__((unused)) void *Args);
|
|||
|
||||
static void Tmt_WriteCrsTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
||||
long CrsCod);
|
||||
static void Tmt_WriteTutTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
||||
static void Tmt_WriteUsrTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
||||
long UsrCod);
|
||||
static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable,
|
||||
long UsrCod);
|
||||
|
@ -237,6 +220,7 @@ static void Tmt_ShowTimeTableGrpsSelected (void)
|
|||
extern const char *Txt_All_groups;
|
||||
|
||||
HTM_DIV_Begin ("class=\"CLASSPHOTO_TITLE CM\"");
|
||||
|
||||
switch (Gbl.Crs.Grps.WhichGrps)
|
||||
{
|
||||
case Grp_MY_GROUPS:
|
||||
|
@ -246,6 +230,7 @@ static void Tmt_ShowTimeTableGrpsSelected (void)
|
|||
HTM_Txt (Txt_All_groups);
|
||||
break;
|
||||
}
|
||||
|
||||
HTM_DIV_End ();
|
||||
}
|
||||
|
||||
|
@ -255,6 +240,7 @@ static void Tmt_ShowTimeTableGrpsSelected (void)
|
|||
|
||||
static void Tmt_GetParamsTimeTable (struct Tmt_Timetable *Timetable)
|
||||
{
|
||||
extern const char *Tmt_DB_ClassType[Tmt_NUM_CLASS_TYPES];
|
||||
char StrClassType[Tmt_MAX_BYTES_STR_CLASS_TYPE + 1];
|
||||
char StrDuration[Tmt_MAX_BYTES_STR_DURATION + 1];
|
||||
unsigned Hours;
|
||||
|
@ -286,7 +272,7 @@ static void Tmt_GetParamsTimeTable (struct Tmt_Timetable *Timetable)
|
|||
for (Timetable->ClassType = (Tmt_ClassType_t) 0;
|
||||
Timetable->ClassType <= (Tmt_ClassType_t) (Tmt_NUM_CLASS_TYPES - 1);
|
||||
Timetable->ClassType++)
|
||||
if (!strcmp (StrClassType,Tmt_ClassTypeDB[Timetable->ClassType]))
|
||||
if (!strcmp (StrClassType,Tmt_DB_ClassType[Timetable->ClassType]))
|
||||
break;
|
||||
if (Timetable->ClassType > (Tmt_ClassType_t) (Tmt_NUM_CLASS_TYPES - 1))
|
||||
Err_ShowErrorAndExit ("Type of timetable cell is missing.");
|
||||
|
@ -566,7 +552,7 @@ void Tmt_ShowTimeTable (struct Tmt_Timetable *Timetable,long UsrCod)
|
|||
Tmt_WriteCrsTimeTableIntoDB (Timetable,Gbl.Hierarchy.Crs.CrsCod);
|
||||
break;
|
||||
case Tmt_TUTORING_TIMETABLE:
|
||||
Tmt_WriteTutTimeTableIntoDB (Timetable,UsrCod);
|
||||
Tmt_WriteUsrTimeTableIntoDB (Timetable,UsrCod);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -600,10 +586,7 @@ static void Tmt_WriteCrsTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
|||
unsigned Column;
|
||||
|
||||
/***** Remove former timetable *****/
|
||||
DB_QueryDELETE ("can not remove former timetable",
|
||||
"DELETE FROM tmt_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
Tmt_DB_RemoveCrsTimeTable (CrsCod);
|
||||
|
||||
/***** Go across the timetable inserting classes into database *****/
|
||||
for (Weekday = 0;
|
||||
|
@ -619,29 +602,17 @@ static void Tmt_WriteCrsTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
|||
Column++)
|
||||
if (Tmt_TimeTable[Weekday][Interval].Columns[Column].IntervalType == Tmt_FIRST_INTERVAL &&
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals)
|
||||
DB_QueryINSERT ("can not create course timetable",
|
||||
"INSERT INTO tmt_courses"
|
||||
" (CrsCod,GrpCod,Weekday,StartTime,Duration,"
|
||||
"ClassType,Info)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),"
|
||||
"'%s','%s')",
|
||||
CrsCod,
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].GrpCod,
|
||||
Weekday,
|
||||
Hour,
|
||||
Min,
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals *
|
||||
Timetable->Config.SecondsPerInterval,
|
||||
Tmt_ClassTypeDB[Tmt_TimeTable[Weekday][Interval].Columns[Column].ClassType],
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].Info);
|
||||
Tmt_DB_InsertHourInCrsTimeTable (CrsCod,
|
||||
&Tmt_TimeTable[Weekday][Interval].Columns[Column],
|
||||
Weekday,Hour,Min,
|
||||
Timetable->Config.SecondsPerInterval);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Write tutor timetable into database *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void Tmt_WriteTutTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
||||
static void Tmt_WriteUsrTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
||||
long UsrCod)
|
||||
{
|
||||
unsigned Weekday;
|
||||
|
@ -651,10 +622,7 @@ static void Tmt_WriteTutTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
|||
unsigned Column;
|
||||
|
||||
/***** Remove former timetable *****/
|
||||
DB_QueryDELETE ("can not remove former timetable",
|
||||
"DELETE FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrCod);
|
||||
Tmt_DB_RemoveUsrTimeTable (UsrCod);
|
||||
|
||||
/***** Loop over timetable *****/
|
||||
for (Weekday = 0;
|
||||
|
@ -670,18 +638,10 @@ static void Tmt_WriteTutTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
|||
Column++)
|
||||
if (Tmt_TimeTable[Weekday][Interval].Columns[Column].IntervalType == Tmt_FIRST_INTERVAL &&
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals)
|
||||
DB_QueryINSERT ("can not create office timetable",
|
||||
"INSERT INTO tmt_tutoring"
|
||||
" (UsrCod,Weekday,StartTime,Duration,Info)"
|
||||
" VALUES"
|
||||
" (%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),'%s')",
|
||||
UsrCod,
|
||||
Weekday,
|
||||
Hour,
|
||||
Min,
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].DurationIntervals *
|
||||
Timetable->Config.SecondsPerInterval,
|
||||
Tmt_TimeTable[Weekday][Interval].Columns[Column].Info);
|
||||
Tmt_DB_InsertHourInUsrTimeTable (UsrCod,
|
||||
&Tmt_TimeTable[Weekday][Interval].Columns[Column],
|
||||
Weekday,Hour,Min,
|
||||
Timetable->Config.SecondsPerInterval);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -691,6 +651,7 @@ static void Tmt_WriteTutTimeTableIntoDB (const struct Tmt_Timetable *Timetable,
|
|||
static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable,
|
||||
long UsrCod)
|
||||
{
|
||||
extern const char *Tmt_DB_ClassType[Tmt_NUM_CLASS_TYPES];
|
||||
extern const char *Txt_Incomplete_timetable_for_lack_of_space;
|
||||
MYSQL_RES *mysql_res;
|
||||
MYSQL_ROW row;
|
||||
|
@ -712,168 +673,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable,
|
|||
bool Found;
|
||||
|
||||
/***** Get timetable from database *****/
|
||||
switch (Timetable->Type)
|
||||
{
|
||||
case Tmt_MY_TIMETABLE:
|
||||
switch (Gbl.Crs.Grps.WhichGrps)
|
||||
{
|
||||
case Grp_MY_GROUPS:
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.GrpCod=-1"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION DISTINCT "
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM grp_users,"
|
||||
"tmt_courses"
|
||||
" WHERE grp_users.UsrCod=%ld"
|
||||
" AND grp_users.GrpCod=tmt_courses.GrpCod"
|
||||
" UNION "
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"'tutoring' AS ClassType," // row[4]
|
||||
"-1 AS GrpCod," // row[5]
|
||||
"-1 AS CrsCod" // row[6]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC,"
|
||||
"CrsCod",
|
||||
UsrCod,
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
break;
|
||||
case Grp_ALL_GROUPS:
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION "
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"'tutoring' AS ClassType," // row[4]
|
||||
"-1 AS GrpCod," // row[5]
|
||||
"-1 AS CrsCod" // row[6]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC,"
|
||||
"CrsCod",
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Tmt_COURSE_TIMETABLE:
|
||||
if (Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS ||
|
||||
Gbl.Action.Act == ActEdiCrsTT ||
|
||||
Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get timetable",
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"ClassType," // row[4]
|
||||
"GrpCod" // row[5]
|
||||
" FROM tmt_courses"
|
||||
" WHERE CrsCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
else
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod" // row[5]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE tmt_courses.CrsCod=%ld"
|
||||
" AND tmt_courses.GrpCod=-1"
|
||||
" AND crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION DISTINCT "
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod" // row[5]
|
||||
" FROM tmt_courses,"
|
||||
"grp_users"
|
||||
" WHERE tmt_courses.CrsCod=%ld"
|
||||
" AND grp_users.UsrCod=%ld"
|
||||
" AND tmt_courses.GrpCod=grp_users.GrpCod"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
Gbl.Hierarchy.Crs.CrsCod,UsrCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod,UsrCod);
|
||||
break;
|
||||
case Tmt_TUTORING_TIMETABLE:
|
||||
NumRows = (unsigned)
|
||||
DB_QuerySELECT (&mysql_res,"can not get timetable",
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info" // row[3]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
UsrCod);
|
||||
break;
|
||||
}
|
||||
NumRows = Tmt_DB_GetTimeTable (&mysql_res,Timetable->Type,UsrCod);
|
||||
|
||||
/***** If viewing (not editing) ==>
|
||||
calculate range of hours and resolution *****/
|
||||
|
@ -979,7 +779,7 @@ static void Tmt_FillTimeTableFromDB (struct Tmt_Timetable *Timetable,
|
|||
for (ClassType = Tmt_LECTURE, Found = false;
|
||||
ClassType <= Tmt_TUTORING;
|
||||
ClassType++)
|
||||
if (!strcmp (row[4],Tmt_ClassTypeDB[ClassType]))
|
||||
if (!strcmp (row[4],Tmt_DB_ClassType[ClassType]))
|
||||
{
|
||||
Found = true;
|
||||
break;
|
||||
|
@ -1505,6 +1305,7 @@ static void Tmt_TimeTableDrawCell (const struct Tmt_Timetable *Timetable,
|
|||
long CrsCod,Tmt_IntervalType_t IntervalType,Tmt_ClassType_t ClassType,
|
||||
unsigned DurationNumIntervals,long GrpCod,const char *Info)
|
||||
{
|
||||
extern const char *Tmt_DB_ClassType[Tmt_NUM_CLASS_TYPES];
|
||||
extern const char *Txt_unknown_removed_course;
|
||||
extern const char *Txt_TIMETABLE_CLASS_TYPES[Tmt_NUM_CLASS_TYPES];
|
||||
extern const char *Txt_Group;
|
||||
|
@ -1689,7 +1490,7 @@ static void Tmt_TimeTableDrawCell (const struct Tmt_Timetable *Timetable,
|
|||
if ((CT == Tmt_FREE) ||
|
||||
((Timetable->View == Tmt_CRS_EDIT) && (CT == Tmt_LECTURE || CT == Tmt_PRACTICAL)) ||
|
||||
((Timetable->View == Tmt_TUT_EDIT) && (CT == Tmt_TUTORING)))
|
||||
HTM_OPTION (HTM_Type_STRING,Tmt_ClassTypeDB[CT],
|
||||
HTM_OPTION (HTM_Type_STRING,Tmt_DB_ClassType[CT],
|
||||
CT == ClassType,false,
|
||||
"%s",Txt_TIMETABLE_CLASS_TYPES[CT]);
|
||||
HTM_SELECT_End ();
|
||||
|
@ -1823,32 +1624,3 @@ static void Tmt_TimeTableDrawCell (const struct Tmt_Timetable *Timetable,
|
|||
/***** End cell *****/
|
||||
HTM_TD_End ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Orphan all groups of a given type in course timetable ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_OrphanAllGrpsOfATypeInCrsTimeTable (long GrpTypCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update all groups of a type in course timetable",
|
||||
"UPDATE tmt_courses"
|
||||
" SET GrpCod=-1"
|
||||
" WHERE GrpCod IN"
|
||||
" (SELECT GrpCod"
|
||||
" FROM grp_groups"
|
||||
" WHERE GrpTypCod=%ld)",
|
||||
GrpTypCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Orphan a group in course timetable ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_OrphanGrpInCrsTimeTable (long GrpCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update a group in course timetable",
|
||||
"UPDATE tmt_courses"
|
||||
" SET GrpCod=-1"
|
||||
" WHERE GrpCod=%ld",
|
||||
GrpCod);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// swad_timetable.h: timetables
|
||||
|
||||
#ifndef _SWAD_TT
|
||||
#define _SWAD_TT
|
||||
#ifndef _SWAD_TMT
|
||||
#define _SWAD_TMT
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
|
@ -106,6 +106,16 @@ struct Tmt_Timetable
|
|||
} ContextualIcons;
|
||||
};
|
||||
|
||||
struct Tmt_Column
|
||||
{
|
||||
long CrsCod; // Course code (-1 if no course selected)
|
||||
long GrpCod; // Group code (-1 if no group selected)
|
||||
Tmt_IntervalType_t IntervalType;
|
||||
Tmt_ClassType_t ClassType;
|
||||
unsigned DurationIntervals;
|
||||
char Info[Tmt_MAX_BYTES_INFO + 1];
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -115,7 +125,4 @@ void Tmt_EditCrsTimeTable (void);
|
|||
void Tmt_EditMyTutTimeTable (void);
|
||||
void Tmt_ShowTimeTable (struct Tmt_Timetable *Timetable,long UsrCod);
|
||||
|
||||
void Tmt_DB_OrphanAllGrpsOfATypeInCrsTimeTable (long GrpTypCod);
|
||||
void Tmt_DB_OrphanGrpInCrsTimeTable (long GrpCod);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,326 @@
|
|||
// swad_timetable_database.c: timetables, operations with database
|
||||
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/*********************************** Headers *********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include "swad_database.h"
|
||||
#include "swad_global.h"
|
||||
#include "swad_timetable_database.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** External constants ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Public constants and types ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *Tmt_DB_ClassType[Tmt_NUM_CLASS_TYPES] =
|
||||
{
|
||||
[Tmt_FREE ] = "free",
|
||||
[Tmt_LECTURE ] = "lecture",
|
||||
[Tmt_PRACTICAL] = "practical",
|
||||
[Tmt_TUTORING ] = "tutoring",
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Private global variables *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ***************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Insert class in course timetable **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_InsertHourInCrsTimeTable (long CrsCod,
|
||||
const struct Tmt_Column *Column,
|
||||
unsigned Weekday,unsigned Hour,unsigned Min,
|
||||
unsigned SecondsPerInterval)
|
||||
{
|
||||
DB_QueryINSERT ("can not insert hour in course timetable",
|
||||
"INSERT INTO tmt_courses"
|
||||
" (CrsCod,GrpCod,Weekday,StartTime,Duration,"
|
||||
"ClassType,Info)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),"
|
||||
"'%s','%s')",
|
||||
CrsCod,
|
||||
Column->GrpCod,
|
||||
Weekday,Hour,Min,
|
||||
Column->DurationIntervals * SecondsPerInterval,
|
||||
Tmt_DB_ClassType[Column->ClassType],
|
||||
Column->Info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Insert class in course timetable **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_InsertHourInUsrTimeTable (long UsrCod,
|
||||
const struct Tmt_Column *Column,
|
||||
unsigned Weekday,unsigned Hour,unsigned Min,
|
||||
unsigned SecondsPerInterval)
|
||||
{
|
||||
DB_QueryINSERT ("can not insert hour in user timetable",
|
||||
"INSERT INTO tmt_tutoring"
|
||||
" (UsrCod,Weekday,StartTime,Duration,Info)"
|
||||
" VALUES"
|
||||
" (%ld,%u,'%02u:%02u:00',SEC_TO_TIME(%u),'%s')",
|
||||
UsrCod,
|
||||
Weekday,Hour,Min,
|
||||
Column->DurationIntervals * SecondsPerInterval,
|
||||
Column->Info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Get timetable from database ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Tmt_DB_GetTimeTable (MYSQL_RES **mysql_res,
|
||||
Tmt_TimeTableType_t Type,long UsrCod)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case Tmt_MY_TIMETABLE:
|
||||
switch (Gbl.Crs.Grps.WhichGrps)
|
||||
{
|
||||
case Grp_MY_GROUPS:
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.GrpCod=-1"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION DISTINCT "
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM grp_users,"
|
||||
"tmt_courses"
|
||||
" WHERE grp_users.UsrCod=%ld"
|
||||
" AND grp_users.GrpCod=tmt_courses.GrpCod"
|
||||
" UNION "
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"'tutoring' AS ClassType," // row[4]
|
||||
"-1 AS GrpCod," // row[5]
|
||||
"-1 AS CrsCod" // row[6]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC,"
|
||||
"CrsCod",
|
||||
UsrCod,
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
case Grp_ALL_GROUPS:
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod," // row[5]
|
||||
"tmt_courses.CrsCod" // row[6]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION "
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"'tutoring' AS ClassType," // row[4]
|
||||
"-1 AS GrpCod," // row[5]
|
||||
"-1 AS CrsCod" // row[6]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC,"
|
||||
"CrsCod",
|
||||
UsrCod,
|
||||
UsrCod);
|
||||
}
|
||||
return 0; // Not reached
|
||||
case Tmt_COURSE_TIMETABLE:
|
||||
if (Gbl.Crs.Grps.WhichGrps == Grp_ALL_GROUPS ||
|
||||
Gbl.Action.Act == ActEdiCrsTT ||
|
||||
Gbl.Action.Act == ActChgCrsTT) // If we are editing, all groups are shown
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get timetable",
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info," // row[3]
|
||||
"ClassType," // row[4]
|
||||
"GrpCod" // row[5]
|
||||
" FROM tmt_courses"
|
||||
" WHERE CrsCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
else
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get timetable",
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod" // row[5]
|
||||
" FROM tmt_courses,"
|
||||
"crs_users"
|
||||
" WHERE tmt_courses.CrsCod=%ld"
|
||||
" AND tmt_courses.GrpCod=-1"
|
||||
" AND crs_users.UsrCod=%ld"
|
||||
" AND tmt_courses.CrsCod=crs_users.CrsCod"
|
||||
" UNION DISTINCT "
|
||||
"SELECT tmt_courses.Weekday," // row[0]
|
||||
"TIME_TO_SEC(tmt_courses.StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(tmt_courses.Duration) AS D," // row[2]
|
||||
"tmt_courses.Info," // row[3]
|
||||
"tmt_courses.ClassType," // row[4]
|
||||
"tmt_courses.GrpCod" // row[5]
|
||||
" FROM tmt_courses,"
|
||||
"grp_users"
|
||||
" WHERE tmt_courses.CrsCod=%ld"
|
||||
" AND grp_users.UsrCod=%ld"
|
||||
" AND tmt_courses.GrpCod=grp_users.GrpCod"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"ClassType,"
|
||||
"GrpCod,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
Gbl.Hierarchy.Crs.CrsCod,UsrCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod,UsrCod);
|
||||
case Tmt_TUTORING_TIMETABLE:
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get timetable",
|
||||
"SELECT Weekday," // row[0]
|
||||
"TIME_TO_SEC(StartTime) AS S," // row[1]
|
||||
"TIME_TO_SEC(Duration) AS D," // row[2]
|
||||
"Info" // row[3]
|
||||
" FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld"
|
||||
" ORDER BY Weekday,"
|
||||
"S,"
|
||||
"Info,"
|
||||
"D DESC",
|
||||
UsrCod);
|
||||
default:
|
||||
return 0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Orphan all groups of a given type in course timetable ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_OrphanAllGrpsOfATypeInCrsTimeTable (long GrpTypCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update all groups of a type in course timetable",
|
||||
"UPDATE tmt_courses"
|
||||
" SET GrpCod=-1"
|
||||
" WHERE GrpCod IN"
|
||||
" (SELECT GrpCod"
|
||||
" FROM grp_groups"
|
||||
" WHERE GrpTypCod=%ld)",
|
||||
GrpTypCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Orphan a group in course timetable ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_OrphanGrpInCrsTimeTable (long GrpCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update a group in course timetable",
|
||||
"UPDATE tmt_courses"
|
||||
" SET GrpCod=-1"
|
||||
" WHERE GrpCod=%ld",
|
||||
GrpCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Remove course timetable *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_RemoveCrsTimeTable (long CrsCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove timetable",
|
||||
"DELETE FROM tmt_courses"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Remove user timetable **************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_RemoveUsrTimeTable (long UsrCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove former timetable",
|
||||
"DELETE FROM tmt_tutoring"
|
||||
" WHERE UsrCod=%ld",
|
||||
UsrCod);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
// swad_timetable_database.h: timetables, operations with database
|
||||
|
||||
#ifndef _SWAD_TMT_DB
|
||||
#define _SWAD_TMT_DB
|
||||
/*
|
||||
SWAD (Shared Workspace At a Distance in Spanish),
|
||||
is a web platform developed at the University of Granada (Spain),
|
||||
and used to support university teaching.
|
||||
|
||||
This file is part of SWAD core.
|
||||
Copyright (C) 1999-2021 Antonio Cañas Vargas
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/********************************** Headers **********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <mysql/mysql.h> // To access MySQL databases
|
||||
|
||||
#include "swad_timetable.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Public constants and types ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************************** Public prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Tmt_DB_InsertHourInCrsTimeTable (long CrsCod,
|
||||
const struct Tmt_Column *Column,
|
||||
unsigned Weekday,unsigned Hour,unsigned Min,
|
||||
unsigned SecondsPerInterval);
|
||||
void Tmt_DB_InsertHourInUsrTimeTable (long UsrCod,
|
||||
const struct Tmt_Column *Column,
|
||||
unsigned Weekday,unsigned Hour,unsigned Min,
|
||||
unsigned SecondsPerInterval);
|
||||
|
||||
unsigned Tmt_DB_GetTimeTable (MYSQL_RES **mysql_res,
|
||||
Tmt_TimeTableType_t Type,long UsrCod);
|
||||
|
||||
void Tmt_DB_OrphanAllGrpsOfATypeInCrsTimeTable (long GrpTypCod);
|
||||
void Tmt_DB_OrphanGrpInCrsTimeTable (long GrpCod);
|
||||
|
||||
void Tmt_DB_RemoveCrsTimeTable (long CrsCod);
|
||||
void Tmt_DB_RemoveUsrTimeTable (long UsrCod);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue