mirror of https://github.com/acanas/swad-core.git
Version 20.94: Jun 17, 2021 New module swad_group_database for database queries related to groups.
This commit is contained in:
parent
3c7089216b
commit
2cbb1b2b38
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
|
||||||
swad_figure.o swad_figure_cache.o swad_file.o swad_file_browser.o \
|
swad_figure.o swad_figure_cache.o swad_file.o swad_file_browser.o \
|
||||||
swad_file_extension.o swad_file_MIME.o swad_firewall.o swad_follow.o \
|
swad_file_extension.o swad_file_MIME.o swad_firewall.o swad_follow.o \
|
||||||
swad_follow_database.o swad_form.o swad_forum.o \
|
swad_follow_database.o swad_form.o swad_forum.o \
|
||||||
swad_game.o swad_global.o swad_group.o \
|
swad_game.o swad_global.o swad_group.o swad_group_database.o \
|
||||||
swad_help.o swad_hierarchy.o swad_hierarchy_config.o swad_holiday.o \
|
swad_help.o swad_hierarchy.o swad_hierarchy_config.o swad_holiday.o \
|
||||||
swad_HTML.o \
|
swad_HTML.o \
|
||||||
swad_icon.o swad_ID.o swad_indicator.o swad_info.o swad_institution.o \
|
swad_icon.o swad_ID.o swad_indicator.o swad_info.o swad_institution.o \
|
||||||
|
|
|
@ -109,6 +109,7 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/
|
||||||
#include "swad_file_browser.h"
|
#include "swad_file_browser.h"
|
||||||
#include "swad_forum.h"
|
#include "swad_forum.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_hierarchy.h"
|
#include "swad_hierarchy.h"
|
||||||
#include "swad_hierarchy_level.h"
|
#include "swad_hierarchy_level.h"
|
||||||
#include "swad_ID.h"
|
#include "swad_ID.h"
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_group.h"
|
#include "swad_group.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_notification.h"
|
#include "swad_notification.h"
|
||||||
#include "swad_pagination.h"
|
#include "swad_pagination.h"
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_group.h"
|
#include "swad_group.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_hierarchy_level.h"
|
#include "swad_hierarchy_level.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_ID.h"
|
#include "swad_ID.h"
|
||||||
|
|
|
@ -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.
|
TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo.
|
||||||
*/
|
*/
|
||||||
#define Log_PLATFORM_VERSION "SWAD 20.93 (2021-06-17)"
|
#define Log_PLATFORM_VERSION "SWAD 20.94 (2021-06-17)"
|
||||||
#define CSS_FILE "swad20.45.css"
|
#define CSS_FILE "swad20.45.css"
|
||||||
#define JS_FILE "swad20.69.1.js"
|
#define JS_FILE "swad20.69.1.js"
|
||||||
/*
|
/*
|
||||||
TODO: Rename CENTRE to CENTER in help wiki.
|
TODO: Rename CENTRE to CENTER in help wiki.
|
||||||
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams
|
||||||
|
|
||||||
|
Version 20.94: Jun 17, 2021 New module swad_group_database for database queries related to groups. (313489 lines)
|
||||||
Version 20.93: Jun 17, 2021 Code refactoring. (313382 lines)
|
Version 20.93: Jun 17, 2021 Code refactoring. (313382 lines)
|
||||||
Version 20.92: Jun 11, 2021 New modules swad_admin and swad_admin_database for administrators. (313381 lines)
|
Version 20.92: Jun 11, 2021 New modules swad_admin and swad_admin_database for administrators. (313381 lines)
|
||||||
Version 20.91.3: Jun 11, 2021 Queries moved to module swad_enrolment_database. (313173 lines)
|
Version 20.91.3: Jun 11, 2021 Queries moved to module swad_enrolment_database. (313173 lines)
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include "swad_exam_type.h"
|
#include "swad_exam_type.h"
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_role.h"
|
#include "swad_role.h"
|
||||||
#include "swad_setting.h"
|
#include "swad_setting.h"
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "swad_file_MIME.h"
|
#include "swad_file_MIME.h"
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_hierarchy.h"
|
#include "swad_hierarchy.h"
|
||||||
#include "swad_hierarchy_level.h"
|
#include "swad_hierarchy_level.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
|
@ -11724,7 +11725,7 @@ void Brw_RemoveZonesOfGroupsOfType (long GrpTypCod)
|
||||||
long GrpCod;
|
long GrpCod;
|
||||||
|
|
||||||
/***** Query database *****/
|
/***** Query database *****/
|
||||||
NumGrps = Grp_DB_GetGrpsOfType (GrpTypCod,&mysql_res);
|
NumGrps = Grp_DB_GetGrpsOfType (&mysql_res,GrpTypCod);
|
||||||
for (NumGrp = 0;
|
for (NumGrp = 0;
|
||||||
NumGrp < NumGrps;
|
NumGrp < NumGrps;
|
||||||
NumGrp++)
|
NumGrp++)
|
||||||
|
|
137
swad_group.c
137
swad_group.c
|
@ -42,6 +42,7 @@
|
||||||
#include "swad_game.h"
|
#include "swad_game.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_group.h"
|
#include "swad_group.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_match.h"
|
#include "swad_match.h"
|
||||||
#include "swad_notification.h"
|
#include "swad_notification.h"
|
||||||
|
@ -107,9 +108,6 @@ static void Grp_PutIconToCreateNewGroup (void);
|
||||||
|
|
||||||
static void Grp_PutCheckboxAllGrps (Grp_WhichGroups_t GroupsSelectableByStdsOrNETs);
|
static void Grp_PutCheckboxAllGrps (Grp_WhichGroups_t GroupsSelectableByStdsOrNETs);
|
||||||
|
|
||||||
static void Grp_DB_LockTables (void);
|
|
||||||
static void Grp_DB_UnlockTables (void);
|
|
||||||
|
|
||||||
static void Grp_ConstructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType);
|
static void Grp_ConstructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType);
|
||||||
static void Grp_DestructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType);
|
static void Grp_DestructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **AlreadyExistsGroupOfType);
|
||||||
static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod);
|
static void Grp_RemoveUsrFromGroup (long UsrCod,long GrpCod);
|
||||||
|
@ -123,8 +121,7 @@ static void Grp_WriteHeadingGroupTypes (void);
|
||||||
|
|
||||||
static void Grp_ListGroupsForEdition (const struct Roo_Rooms *Rooms);
|
static void Grp_ListGroupsForEdition (const struct Roo_Rooms *Rooms);
|
||||||
static void Grp_WriteHeadingGroups (void);
|
static void Grp_WriteHeadingGroups (void);
|
||||||
static bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field,
|
|
||||||
long Cod,long GrpCod);
|
|
||||||
static void Grp_PutIconToEditGroups (__attribute__((unused)) void *Args);
|
static void Grp_PutIconToEditGroups (__attribute__((unused)) void *Args);
|
||||||
|
|
||||||
static void Grp_ShowWarningToStdsToChangeGrps (void);
|
static void Grp_ShowWarningToStdsToChangeGrps (void);
|
||||||
|
@ -137,7 +134,6 @@ static void Grp_WriteGrpHead (struct GroupType *GrpTyp);
|
||||||
static void Grp_WriteRowGrp (struct Group *Grp,bool Highlight);
|
static void Grp_WriteRowGrp (struct Group *Grp,bool Highlight);
|
||||||
static void Grp_PutFormToCreateGroupType (void);
|
static void Grp_PutFormToCreateGroupType (void);
|
||||||
static void Grp_PutFormToCreateGroup (const struct Roo_Rooms *Rooms);
|
static void Grp_PutFormToCreateGroup (const struct Roo_Rooms *Rooms);
|
||||||
static unsigned Grp_DB_CountNumGrpsInThisCrsOfType (long GrpTypCod);
|
|
||||||
static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp);
|
static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp);
|
||||||
static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
|
static bool Grp_GetMultipleEnrolmentOfAGroupType (long GrpTypCod);
|
||||||
static long Grp_DB_GetTypeOfGroupOfAGroup (long GrpCod);
|
static long Grp_DB_GetTypeOfGroupOfAGroup (long GrpCod);
|
||||||
|
@ -972,35 +968,6 @@ void Grp_ChangeGrpsOtherUsrAtomically (struct ListCodGrps *LstGrpsUsrWants)
|
||||||
Grp_FreeListGrpTypesAndGrps ();
|
Grp_FreeListGrpTypesAndGrps ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*********** Lock tables to make the registration in groups atomic ***********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void Grp_DB_LockTables (void)
|
|
||||||
{
|
|
||||||
DB_Query ("can not lock tables to change user's groups",
|
|
||||||
"LOCK TABLES "
|
|
||||||
"grp_types WRITE,"
|
|
||||||
"grp_groups WRITE,"
|
|
||||||
"grp_users WRITE,"
|
|
||||||
"crs_users READ,"
|
|
||||||
"crs_user_settings READ,"
|
|
||||||
"roo_rooms READ");
|
|
||||||
Gbl.DB.LockedTables = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*********** Unlock tables after changes in registration in groups ***********/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void Grp_DB_UnlockTables (void)
|
|
||||||
{
|
|
||||||
Gbl.DB.LockedTables = false; // Set to false before the following unlock...
|
|
||||||
// ...to not retry the unlock if error in unlocking
|
|
||||||
DB_Query ("can not unlock tables after changing user's groups",
|
|
||||||
"UNLOCK TABLES");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******* Check if not selected more than a group of single enrolment *********/
|
/******* Check if not selected more than a group of single enrolment *********/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -1767,47 +1734,6 @@ void Grp_ListGrpsToEditAsgAttSvyEvtMch (struct GroupType *GrpTyp,
|
||||||
Grp_FreeListCodGrp (&LstGrpsIBelong);
|
Grp_FreeListCodGrp (&LstGrpsIBelong);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/************ Check if an assignment is associated to a group ****************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field,
|
|
||||||
long Cod,long GrpCod)
|
|
||||||
{
|
|
||||||
/***** Get if an assignment, attendance event, survey, exam event or match
|
|
||||||
is associated to a given group from database *****/
|
|
||||||
return (DB_QueryCOUNT ("can not check if associated to a group",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM %s"
|
|
||||||
" WHERE %s=%ld"
|
|
||||||
" AND GrpCod=%ld",
|
|
||||||
Table,
|
|
||||||
Field,Cod,
|
|
||||||
GrpCod) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*** Check if an assignment, attendance event, survey, exam event or match ***/
|
|
||||||
/*** is associated to any group ***/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
bool Grp_DB_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod)
|
|
||||||
{
|
|
||||||
/***** Trivial check *****/
|
|
||||||
if (Cod <= 0) // Assignment, attendance event, survey, exam event or match code
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/***** Get if an assignment, attendance event, survey, exam event or match
|
|
||||||
is associated to any group from database *****/
|
|
||||||
return (DB_QueryCOUNT ("can not check if associated to groups",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM %s"
|
|
||||||
" WHERE %s=%ld",
|
|
||||||
Table,
|
|
||||||
Field,Cod) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/***************** Show list of groups to register/remove me *****************/
|
/***************** Show list of groups to register/remove me *****************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -2955,7 +2881,7 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
|
||||||
if (GrpTyp->NumGrps) // If there are groups of this type...
|
if (GrpTyp->NumGrps) // If there are groups of this type...
|
||||||
{
|
{
|
||||||
/***** Query database *****/
|
/***** Query database *****/
|
||||||
GrpTyp->NumGrps = Grp_DB_GetGrpsOfType (GrpTyp->GrpTypCod,&mysql_res);
|
GrpTyp->NumGrps = Grp_DB_GetGrpsOfType (&mysql_res,GrpTyp->GrpTypCod);
|
||||||
if (GrpTyp->NumGrps > 0) // Groups found...
|
if (GrpTyp->NumGrps > 0) // Groups found...
|
||||||
{
|
{
|
||||||
/***** Create list with groups of this type *****/
|
/***** Create list with groups of this type *****/
|
||||||
|
@ -3047,63 +2973,6 @@ void Grp_FreeListGrpTypesAndGrps (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/*********** Query the number of groups that hay in this course **************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
unsigned Grp_DB_CountNumGrpsInCurrentCrs (void)
|
|
||||||
{
|
|
||||||
/***** Get number of group in current course from database *****/
|
|
||||||
return (unsigned)
|
|
||||||
DB_QueryCOUNT ("can not get number of groups in this course",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM grp_types,"
|
|
||||||
"grp_groups"
|
|
||||||
" WHERE grp_types.CrsCod=%ld"
|
|
||||||
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod",
|
|
||||||
Gbl.Hierarchy.Crs.CrsCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/****************** Count number of groups in a group type *******************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static unsigned Grp_DB_CountNumGrpsInThisCrsOfType (long GrpTypCod)
|
|
||||||
{
|
|
||||||
/***** Get number of groups of a type from database *****/
|
|
||||||
return (unsigned)
|
|
||||||
DB_QueryCOUNT ("can not get number of groups of a type",
|
|
||||||
"SELECT COUNT(*)"
|
|
||||||
" FROM grp_groups"
|
|
||||||
" WHERE GrpTypCod=%ld",
|
|
||||||
GrpTypCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/******************** Get groups of a type in this course ********************/
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
unsigned Grp_DB_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res)
|
|
||||||
{
|
|
||||||
/***** Get groups of a type from database *****/
|
|
||||||
// Don't use INNER JOIN because there are groups without assigned room
|
|
||||||
return (unsigned)
|
|
||||||
DB_QuerySELECT (mysql_res,"can not get groups of a type",
|
|
||||||
"SELECT grp_groups.GrpCod," // row[0]
|
|
||||||
"grp_groups.GrpName," // row[1]
|
|
||||||
"grp_groups.RooCod," // row[2]
|
|
||||||
"roo_rooms.ShortName," // row[3]
|
|
||||||
"grp_groups.MaxStudents," // row[4]
|
|
||||||
"grp_groups.Open," // row[5]
|
|
||||||
"grp_groups.FileZones" // row[6]
|
|
||||||
" FROM grp_groups"
|
|
||||||
" LEFT JOIN roo_rooms"
|
|
||||||
" ON grp_groups.RooCod=roo_rooms.RooCod"
|
|
||||||
" WHERE grp_groups.GrpTypCod=%ld"
|
|
||||||
" ORDER BY grp_groups.GrpName",
|
|
||||||
GrpTypCod);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******************* Get data of a group type from its code ******************/
|
/******************* Get data of a group type from its code ******************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// swad_group.h: groups
|
// swad_group.h: types of groups and groups
|
||||||
|
|
||||||
#ifndef _SWAD_GRP
|
#ifndef _SWAD_GRP
|
||||||
#define _SWAD_GRP
|
#define _SWAD_GRP
|
||||||
|
@ -184,7 +184,6 @@ void Grp_ListGrpsToEditAsgAttSvyEvtMch (struct GroupType *GrpTyp,
|
||||||
Grp_WhichIsAssociatedToGrp_t WhichIsAssociatedToGrp,
|
Grp_WhichIsAssociatedToGrp_t WhichIsAssociatedToGrp,
|
||||||
long Cod);
|
long Cod);
|
||||||
|
|
||||||
bool Grp_DB_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod);
|
|
||||||
void Grp_ReqRegisterInGrps (void);
|
void Grp_ReqRegisterInGrps (void);
|
||||||
void Grp_ShowLstGrpsToChgMyGrps (void);
|
void Grp_ShowLstGrpsToChgMyGrps (void);
|
||||||
void Grp_ShowLstGrpsToChgOtherUsrsGrps (long UsrCod);
|
void Grp_ShowLstGrpsToChgOtherUsrsGrps (long UsrCod);
|
||||||
|
@ -193,8 +192,6 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes);
|
||||||
void Grp_FreeListGrpTypesAndGrps (void);
|
void Grp_FreeListGrpTypesAndGrps (void);
|
||||||
void Grp_OpenGroupsAutomatically (void);
|
void Grp_OpenGroupsAutomatically (void);
|
||||||
void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes);
|
void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes);
|
||||||
unsigned Grp_DB_CountNumGrpsInCurrentCrs (void);
|
|
||||||
unsigned Grp_DB_GetGrpsOfType (long GrpTypCod,MYSQL_RES **mysql_res);
|
|
||||||
void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat);
|
void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat);
|
||||||
bool Grp_DB_CheckIfGroupExists (long GrpCod);
|
bool Grp_DB_CheckIfGroupExists (long GrpCod);
|
||||||
bool Grp_DB_CheckIfGrpBelongsToCrs (long GrpCod,long CrsCod);
|
bool Grp_DB_CheckIfGrpBelongsToCrs (long GrpCod,long CrsCod);
|
||||||
|
|
|
@ -0,0 +1,200 @@
|
||||||
|
// swad_group_database.c: types of groups and groups 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 *********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
// #define _GNU_SOURCE // For asprintf
|
||||||
|
// #include <stddef.h> // For NULL
|
||||||
|
// #include <stdio.h> // For asprintf
|
||||||
|
// #include <stdlib.h> // For exit, system, malloc, free, rand, etc.
|
||||||
|
// #include <string.h> // For string functions
|
||||||
|
|
||||||
|
// #include "swad_action.h"
|
||||||
|
// #include "swad_assignment_database.h"
|
||||||
|
// #include "swad_attendance_database.h"
|
||||||
|
// #include "swad_box.h"
|
||||||
|
#include "swad_database.h"
|
||||||
|
// #include "swad_error.h"
|
||||||
|
// #include "swad_exam_session.h"
|
||||||
|
// #include "swad_form.h"
|
||||||
|
// #include "swad_game.h"
|
||||||
|
#include "swad_global.h"
|
||||||
|
#include "swad_group.h"
|
||||||
|
// #include "swad_HTML.h"
|
||||||
|
// #include "swad_match.h"
|
||||||
|
// #include "swad_notification.h"
|
||||||
|
// #include "swad_parameter.h"
|
||||||
|
// #include "swad_program.h"
|
||||||
|
// #include "swad_project.h"
|
||||||
|
// #include "swad_setting.h"
|
||||||
|
// #include "swad_survey.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*************************** Private constants *******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************************** Private types ********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************* External global variables from others modules *****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
extern struct Globals Gbl;
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************************** Private global variables *************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Private prototypes ****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*********** Lock tables to make the registration in groups atomic ***********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Grp_DB_LockTables (void)
|
||||||
|
{
|
||||||
|
DB_Query ("can not lock tables to change user's groups",
|
||||||
|
"LOCK TABLES "
|
||||||
|
"grp_types WRITE,"
|
||||||
|
"grp_groups WRITE,"
|
||||||
|
"grp_users WRITE,"
|
||||||
|
"crs_users READ,"
|
||||||
|
"crs_user_settings READ,"
|
||||||
|
"roo_rooms READ");
|
||||||
|
Gbl.DB.LockedTables = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*********** Unlock tables after changes in registration in groups ***********/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Grp_DB_UnlockTables (void)
|
||||||
|
{
|
||||||
|
Gbl.DB.LockedTables = false; // Set to false before the following unlock...
|
||||||
|
// ...to not retry the unlock if error in unlocking
|
||||||
|
DB_Query ("can not unlock tables after changing user's groups",
|
||||||
|
"UNLOCK TABLES");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/************ Check if an assignment is associated to a group ****************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field,
|
||||||
|
long Cod,long GrpCod)
|
||||||
|
{
|
||||||
|
/***** Get if an assignment, attendance event, survey, exam event or match
|
||||||
|
is associated to a given group from database *****/
|
||||||
|
return (DB_QueryCOUNT ("can not check if associated to a group",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM %s"
|
||||||
|
" WHERE %s=%ld"
|
||||||
|
" AND GrpCod=%ld",
|
||||||
|
Table,
|
||||||
|
Field,Cod,
|
||||||
|
GrpCod) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*** Check if an assignment, attendance event, survey, exam event or match ***/
|
||||||
|
/*** is associated to any group ***/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
bool Grp_DB_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod)
|
||||||
|
{
|
||||||
|
/***** Trivial check *****/
|
||||||
|
if (Cod <= 0) // Assignment, attendance event, survey, exam event or match code
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/***** Get if an assignment, attendance event, survey, exam event or match
|
||||||
|
is associated to any group from database *****/
|
||||||
|
return (DB_QueryCOUNT ("can not check if associated to groups",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM %s"
|
||||||
|
" WHERE %s=%ld",
|
||||||
|
Table,
|
||||||
|
Field,Cod) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*********** Query the number of groups that hay in this course **************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Grp_DB_CountNumGrpsInCurrentCrs (void)
|
||||||
|
{
|
||||||
|
/***** Get number of group in current course from database *****/
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get number of groups in this course",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM grp_types,"
|
||||||
|
"grp_groups"
|
||||||
|
" WHERE grp_types.CrsCod=%ld"
|
||||||
|
" AND grp_types.GrpTypCod=grp_groups.GrpTypCod",
|
||||||
|
Gbl.Hierarchy.Crs.CrsCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************** Count number of groups in a group type *******************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Grp_DB_CountNumGrpsInThisCrsOfType (long GrpTypCod)
|
||||||
|
{
|
||||||
|
/***** Get number of groups of a type from database *****/
|
||||||
|
return (unsigned)
|
||||||
|
DB_QueryCOUNT ("can not get number of groups of a type",
|
||||||
|
"SELECT COUNT(*)"
|
||||||
|
" FROM grp_groups"
|
||||||
|
" WHERE GrpTypCod=%ld",
|
||||||
|
GrpTypCod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************** Get groups of a type in this course ********************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
unsigned Grp_DB_GetGrpsOfType (MYSQL_RES **mysql_res,long GrpTypCod)
|
||||||
|
{
|
||||||
|
/***** Get groups of a type from database *****/
|
||||||
|
// Don't use INNER JOIN because there are groups without assigned room
|
||||||
|
return (unsigned)
|
||||||
|
DB_QuerySELECT (mysql_res,"can not get groups of a type",
|
||||||
|
"SELECT grp_groups.GrpCod," // row[0]
|
||||||
|
"grp_groups.GrpName," // row[1]
|
||||||
|
"grp_groups.RooCod," // row[2]
|
||||||
|
"roo_rooms.ShortName," // row[3]
|
||||||
|
"grp_groups.MaxStudents," // row[4]
|
||||||
|
"grp_groups.Open," // row[5]
|
||||||
|
"grp_groups.FileZones" // row[6]
|
||||||
|
" FROM grp_groups"
|
||||||
|
" LEFT JOIN roo_rooms"
|
||||||
|
" ON grp_groups.RooCod=roo_rooms.RooCod"
|
||||||
|
" WHERE grp_groups.GrpTypCod=%ld"
|
||||||
|
" ORDER BY grp_groups.GrpName",
|
||||||
|
GrpTypCod);
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
// swad_group_database.h: types of groups and groups operations with database
|
||||||
|
|
||||||
|
#ifndef _SWAD_GRP_DB
|
||||||
|
#define _SWAD_GRP_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 "swad_info.h"
|
||||||
|
// #include "swad_room.h"
|
||||||
|
// #include "swad_user.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/***************************** Public constants ******************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/******************************* Public types ********************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/****************************** Public prototypes ****************************/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Grp_DB_LockTables (void);
|
||||||
|
void Grp_DB_UnlockTables (void);
|
||||||
|
|
||||||
|
bool Grp_DB_CheckIfAssociatedToGrp (const char *Table,const char *Field,
|
||||||
|
long Cod,long GrpCod);
|
||||||
|
bool Grp_DB_CheckIfAssociatedToGrps (const char *Table,const char *Field,long Cod);
|
||||||
|
|
||||||
|
unsigned Grp_DB_CountNumGrpsInCurrentCrs (void);
|
||||||
|
unsigned Grp_DB_CountNumGrpsInThisCrsOfType (long GrpTypCod);
|
||||||
|
unsigned Grp_DB_GetGrpsOfType (MYSQL_RES **mysql_res,long GrpTypCod);
|
||||||
|
|
||||||
|
#endif
|
|
@ -34,6 +34,7 @@
|
||||||
#include "swad_error.h"
|
#include "swad_error.h"
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_hierarchy.h"
|
#include "swad_hierarchy.h"
|
||||||
#include "swad_hierarchy_level.h"
|
#include "swad_hierarchy_level.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_game.h"
|
#include "swad_game.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_match.h"
|
#include "swad_match.h"
|
||||||
#include "swad_match_result.h"
|
#include "swad_match_result.h"
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "swad_form.h"
|
#include "swad_form.h"
|
||||||
#include "swad_global.h"
|
#include "swad_global.h"
|
||||||
#include "swad_group.h"
|
#include "swad_group.h"
|
||||||
|
#include "swad_group_database.h"
|
||||||
#include "swad_HTML.h"
|
#include "swad_HTML.h"
|
||||||
#include "swad_notification.h"
|
#include "swad_notification.h"
|
||||||
#include "swad_pagination.h"
|
#include "swad_pagination.h"
|
||||||
|
|
Loading…
Reference in New Issue