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 *******************************/
|
||||
|
|
974
swad_timetable.c
974
swad_timetable.c
File diff suppressed because it is too large
Load Diff
|
@ -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