Version 21.38: Oct 20, 2021 New module swad_survey_database for database queries related to surveys.

This commit is contained in:
acanas 2021-10-20 17:57:27 +02:00
parent 776174d0f1
commit 0bcffd3ee1
8 changed files with 521 additions and 402 deletions

View File

@ -80,8 +80,8 @@ OBJS = swad_account.o swad_account_database.o swad_action.o swad_admin.o \
swad_room_database.o swad_RSS.o \
swad_scope.o swad_search.o swad_session.o swad_session_database.o \
swad_setting.o swad_setting_database.o swad_statistic.o \
swad_statistic_database.o swad_string.o swad_survey.o swad_syllabus.o \
swad_system_config.o \
swad_statistic_database.o swad_string.o swad_survey.o \
swad_survey_database.o swad_syllabus.o swad_system_config.o \
swad_tab.o swad_tag.o swad_test.o swad_test_config.o \
swad_test_import.o swad_test_print.o swad_test_visibility.o \
swad_theme.o \

View File

@ -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.
*/
#define Log_PLATFORM_VERSION "SWAD 21.37.1 (2021-10-20)"
#define Log_PLATFORM_VERSION "SWAD 21.38 (2021-10-20)"
#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.38: Oct 20, 2021 New module swad_survey_database for database queries related to surveys. (320457 lines)
Version 21.37.1: Oct 20, 2021 Code refactoring in attendance. (320361 lines)
Version 21.37: Oct 19, 2021 New module swad_statistic_database for database queries related to statistics of accesses to platform. (320363 lines)
Version 21.36: Oct 18, 2021 New module swad_setting_database for database queries related to user's settings / preferences. (320253 lines)

View File

@ -3223,10 +3223,10 @@ static void Fig_GetAndShowSurveysStats (void)
/***** Get the number of surveys and the average number of questions per survey from this location *****/
if ((NumSurveys = Svy_GetNumCrsSurveys (Gbl.Scope.Current,&NumNotif)))
{
if ((NumCoursesWithSurveys = Svy_GetNumCoursesWithCrsSurveys (Gbl.Scope.Current)) != 0)
if ((NumCoursesWithSurveys = Svy_DB_GetNumCrssWithCrsSvys (Gbl.Scope.Current)) != 0)
NumSurveysPerCourse = (double) NumSurveys /
(double) NumCoursesWithSurveys;
NumQstsPerSurvey = Svy_GetNumQstsPerCrsSurvey (Gbl.Scope.Current);
NumQstsPerSurvey = Svy_DB_GetNumQstsPerCrsSurvey (Gbl.Scope.Current);
}
/***** Begin box and table *****/

View File

@ -63,6 +63,7 @@
#include "swad_setting.h"
#include "swad_setting_database.h"
#include "swad_survey.h"
#include "swad_survey_database.h"
#include "swad_timeline.h"
#include "swad_timeline_database.h"
#include "swad_timeline_notification.h"

View File

@ -49,6 +49,7 @@
#include "swad_role.h"
#include "swad_setting.h"
#include "swad_survey.h"
#include "swad_survey_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
@ -123,16 +124,16 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys);
static void Svy_SetAllowedAndHiddenScopes (unsigned *ScopesAllowed,
unsigned *HiddenAllowed);
static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
static void Svy_DB_GetSurveyTxt (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
static void Svy_PutParamSvyCod (long SvyCod);
static long Svy_GetParamSvyCod (void);
static void Svy_PutButtonToResetSurvey (struct Svy_Surveys *Surveys);
static bool Svy_CheckIfSimilarSurveyExists (struct Svy_Survey *Svy);
static bool Svy_DB_CheckIfSimilarSurveyExists (const struct Svy_Survey *Svy);
static void Svy_SetDefaultAndAllowedScope (struct Svy_Survey *Svy);
static void Svy_ShowLstGrpsToEditSurvey (long SvyCod);
static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
static void Svy_DB_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
unsigned NumUsrsToBeNotifiedByEMail);
static void Svy_CreateSurvey (struct Svy_Survey *Svy,const char *Txt);
static void Svy_UpdateSurvey (struct Svy_Survey *Svy,const char *Txt);
@ -141,22 +142,22 @@ static void Svy_CreateGrps (long SvyCod);
static void Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (struct Svy_Survey *Svy);
static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod);
static unsigned Svy_GetNumQstsSvy (long SvyCod);
static unsigned Svy_DB_GetNumQstsSvy (long SvyCod);
static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys,
long SvyCod,struct Svy_Question *SvyQst,
char Txt[Cns_MAX_BYTES_TEXT + 1]);
static void Svy_InitQst (struct Svy_Question *SvyQst);
static void Svy_PutParamQstCod (long QstCod);
static long Svy_GetParamQstCod (void);
static void Svy_RemAnswersOfAQuestion (long QstCod);
static void Svy_DB_RemAnswersOfAQuestion (long QstCod);
static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTypeBD);
static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd);
static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res);
static bool Svy_DB_CheckIfAnswerExists (long QstCod,unsigned AnsInd);
static unsigned Svy_DB_GetAnswersQst (MYSQL_RES **mysql_res,long QstCod);
static bool Svy_AllocateTextChoiceAnswer (struct Svy_Question *SvyQst,unsigned NumAns);
static void Svy_FreeTextChoiceAnswers (struct Svy_Question *SvyQst,unsigned NumAnswers);
static void Svy_FreeTextChoiceAnswer (struct Svy_Question *SvyQst,unsigned NumAns);
static unsigned Svy_GetQstIndFromQstCod (long QstCod);
static unsigned Svy_DB_GetQstIndFromQstCod (long QstCod);
static unsigned Svy_GetNextQuestionIndexInSvy (long SvyCod);
static void Svy_ListSvyQuestions (struct Svy_Surveys *Surveys,
struct Svy_Survey *Svy);
@ -173,10 +174,10 @@ static void Svy_PutIconToRemoveOneQst (void *Surveys);
static void Svy_PutParamsRemoveOneQst (void *Surveys);
static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod);
static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd);
static void Svy_RegisterIHaveAnsweredSvy (long SvyCod);
static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod);
static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod);
static void Svy_DB_IncreaseAnswer (long QstCod,unsigned AnsInd);
static void Svy_DB_RegisterIHaveAnsweredSvy (long SvyCod);
static bool Svy_DB_CheckIfIHaveAnsweredSvy (long SvyCod);
static unsigned Svy_DB_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod);
/*****************************************************************************/
/*************************** Reset surveys context ***************************/
@ -694,7 +695,7 @@ static void Svy_ShowOneSurvey (struct Svy_Surveys *Surveys,
Svy_GetAndWriteNamesOfGrpsAssociatedToSvy (&Svy);
/* Text of the survey */
Svy_GetSurveyTxtFromDB (Svy.SvyCod,Txt);
Svy_DB_GetSurveyTxt (Svy.SvyCod,Txt);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Txt,Cns_MAX_BYTES_TEXT,false); // Convert from HTML to rigorous HTML
Str_InsertLinks (Txt,Cns_MAX_BYTES_TEXT,60); // Insert links
@ -1316,8 +1317,8 @@ void Svy_GetDataOfSurveyByCod (struct Svy_Survey *Svy)
Str_Copy (Svy->Title,row[9],sizeof (Svy->Title) - 1);
/* Get number of questions and number of users who have already answer this survey */
Svy->NumQsts = Svy_GetNumQstsSvy (Svy->SvyCod);
Svy->NumUsrs = Svy_GetNumUsrsWhoHaveAnsweredSvy (Svy->SvyCod);
Svy->NumQsts = Svy_DB_GetNumQstsSvy (Svy->SvyCod);
Svy->NumUsrs = Svy_DB_GetNumUsrsWhoHaveAnsweredSvy (Svy->SvyCod);
/* Am I logged with a valid role to answer this survey? */
Svy->Status.IAmLoggedWithAValidRoleToAnswer = (Svy->Roles & (1 << Gbl.Usrs.Me.Role.Logged));
@ -1350,7 +1351,7 @@ void Svy_GetDataOfSurveyByCod (struct Svy_Survey *Svy)
}
/* Have I answered this survey? */
Svy->Status.IHaveAnswered = Svy_CheckIfIHaveAnsweredSvy (Svy->SvyCod);
Svy->Status.IHaveAnswered = Svy_DB_CheckIfIHaveAnsweredSvy (Svy->SvyCod);
/* Can I answer survey? */
Svy->Status.ICanAnswer = (Svy->NumQsts != 0) &&
@ -1488,7 +1489,7 @@ void Svy_FreeListSurveys (struct Svy_Surveys *Surveys)
/********************** Get survey text from database ************************/
/*****************************************************************************/
static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
static void Svy_DB_GetSurveyTxt (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
{
/***** Get text of survey from database *****/
DB_QuerySELECTString (Txt,Cns_MAX_BYTES_TEXT,"can not get survey text",
@ -1848,7 +1849,7 @@ void Svy_UnhideSurvey (void)
/******************* Check if the title of a survey exists *******************/
/*****************************************************************************/
static bool Svy_CheckIfSimilarSurveyExists (struct Svy_Survey *Svy)
static bool Svy_DB_CheckIfSimilarSurveyExists (const struct Svy_Survey *Svy)
{
/***** Get number of surveys with a field value from database *****/
return (DB_QueryCOUNT ("can not get similar surveys",
@ -1935,7 +1936,7 @@ void Svy_RequestCreatOrEditSvy (void)
Err_NoPermissionExit ();
/* Get text of the survey from database */
Svy_GetSurveyTxtFromDB (Svy.SvyCod,Txt);
Svy_DB_GetSurveyTxt (Svy.SvyCod,Txt);
}
/***** Begin form *****/
@ -2298,7 +2299,7 @@ void Svy_ReceiveFormSurvey (void)
if (NewSvy.Title[0]) // If there's a survey title
{
/* If title of survey was in database... */
if (Svy_CheckIfSimilarSurveyExists (&NewSvy))
if (Svy_DB_CheckIfSimilarSurveyExists (&NewSvy))
{
NewSurveyIsCorrect = false;
Ale_ShowAlert (Ale_WARNING,Txt_Already_existed_a_survey_with_the_title_X,
@ -2331,7 +2332,7 @@ void Svy_ReceiveFormSurvey (void)
/***** Notify by email about the new survey *****/
if (NewSvy.Scope == HieLvl_CRS) // Notify only the surveys for a course, not for a degree or global
if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_SURVEY,NewSvy.SvyCod)))
Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (NewSvy.SvyCod,NumUsrsToBeNotifiedByEMail);
Svy_DB_UpdateNumUsrsNotifiedByEMailAboutSurvey (NewSvy.SvyCod,NumUsrsToBeNotifiedByEMail);
/***** Show surveys again *****/
Svy_ListAllSurveys (&Surveys);
@ -2341,7 +2342,7 @@ void Svy_ReceiveFormSurvey (void)
/*********** Update number of users notified in table of surveys *************/
/*****************************************************************************/
static void Svy_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
static void Svy_DB_UpdateNumUsrsNotifiedByEMailAboutSurvey (long SvyCod,
unsigned NumUsrsToBeNotifiedByEMail)
{
/***** Update number of users notified *****/
@ -2659,7 +2660,7 @@ static bool Svy_CheckIfICanDoThisSurveyBasedOnGrps (long SvyCod)
/******************* Get number of questions of a survey *********************/
/*****************************************************************************/
static unsigned Svy_GetNumQstsSvy (long SvyCod)
static unsigned Svy_DB_GetNumQstsSvy (long SvyCod)
{
/***** Get data of questions from database *****/
return (unsigned)
@ -2764,7 +2765,7 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys,
DB_FreeMySQLResult (&mysql_res);
/***** Get the answers from the database *****/
NumAnswers = Svy_GetAnswersQst (SvyQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
NumAnswers = Svy_DB_GetAnswersQst (&mysql_res,SvyQst->QstCod); // Result: AnsInd,NumUsrs,Answer
for (NumAns = 0;
NumAns < NumAnswers;
NumAns++)
@ -2949,7 +2950,7 @@ static long Svy_GetParamQstCod (void)
/********************* Remove answers of a survey question *******************/
/*****************************************************************************/
static void Svy_RemAnswersOfAQuestion (long QstCod)
static void Svy_DB_RemAnswersOfAQuestion (long QstCod)
{
/***** Remove answers *****/
DB_QueryDELETE ("can not remove the answers of a question",
@ -2979,7 +2980,7 @@ static Svy_AnswerType_t Svy_ConvertFromStrAnsTypDBToAnsTyp (const char *StrAnsTy
/*********** Check if an answer of a question exists in database *************/
/*****************************************************************************/
static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
static bool Svy_DB_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
{
/***** Get answers of a question from database *****/
return (DB_QueryCOUNT ("can not check if an answer exists",
@ -2994,7 +2995,7 @@ static bool Svy_CheckIfAnswerExists (long QstCod,unsigned AnsInd)
/************** Get answers of a survey question from database ***************/
/*****************************************************************************/
static unsigned Svy_GetAnswersQst (long QstCod,MYSQL_RES **mysql_res)
static unsigned Svy_DB_GetAnswersQst (MYSQL_RES **mysql_res,long QstCod)
{
unsigned NumAnswers;
@ -3193,7 +3194,7 @@ void Svy_ReceiveQst (void)
for (NumAns = 0;
NumAns < Svy_MAX_ANSWERS_PER_QUESTION;
NumAns++)
if (Svy_CheckIfAnswerExists (SvyQst.QstCod,NumAns)) // If this answer exists...
if (Svy_DB_CheckIfAnswerExists (SvyQst.QstCod,NumAns)) // If this answer exists...
{
if (SvyQst.AnsChoice[NumAns].Text[0]) // Answer is not empty
/* Update answer text */
@ -3242,7 +3243,7 @@ void Svy_ReceiveQst (void)
/************ Get question index from question code in a survey **************/
/*****************************************************************************/
static unsigned Svy_GetQstIndFromQstCod (long QstCod)
static unsigned Svy_DB_GetQstIndFromQstCod (long QstCod)
{
/***** Get question index from database *****/
return DB_QuerySELECTUnsigned ("can not get question index",
@ -3519,7 +3520,7 @@ static void Svy_WriteAnswersOfAQst (struct Svy_Survey *Svy,
char StrAns[32];
/***** Get answers of this question *****/
NumAnswers = Svy_GetAnswersQst (SvyQst->QstCod,&mysql_res); // Result: AnsInd,NumUsrs,Answer
NumAnswers = Svy_DB_GetAnswersQst (&mysql_res,SvyQst->QstCod); // Result: AnsInd,NumUsrs,Answer
/***** Write the answers *****/
if (NumAnswers)
@ -3706,7 +3707,7 @@ void Svy_RequestRemoveQst (void)
Err_WrongQuestionExit ();
/* Get question index */
SvyQst.QstInd = Svy_GetQstIndFromQstCod (SvyQst.QstCod);
SvyQst.QstInd = Svy_DB_GetQstIndFromQstCod (SvyQst.QstCod);
/***** Show question and button to remove question *****/
Surveys.SvyCod = SvyCod;
@ -3748,11 +3749,11 @@ void Svy_RemoveQst (void)
Err_WrongQuestionExit ();
/* Get question index */
SvyQst.QstInd = Svy_GetQstIndFromQstCod (SvyQst.QstCod);
SvyQst.QstInd = Svy_DB_GetQstIndFromQstCod (SvyQst.QstCod);
/***** Remove the question from all the tables *****/
/* Remove answers from this test question */
Svy_RemAnswersOfAQuestion (SvyQst.QstCod);
Svy_DB_RemAnswersOfAQuestion (SvyQst.QstCod);
/* Remove the question itself */
DB_QueryDELETE ("can not remove a question",
@ -3859,7 +3860,7 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
if (sscanf (UnsignedStr,"%u",&AnsInd) == 1)
// Parameter exists ==> user has checked this answer
// ==> store it in database
Svy_IncreaseAnswerInDB (QstCod,AnsInd);
Svy_DB_IncreaseAnswer (QstCod,AnsInd);
}
}
}
@ -3870,14 +3871,14 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
DB_FreeMySQLResult (&mysql_res);
/***** Register that you have answered this survey *****/
Svy_RegisterIHaveAnsweredSvy (SvyCod);
Svy_DB_RegisterIHaveAnsweredSvy (SvyCod);
}
/*****************************************************************************/
/************ Increase number of users who have marked one answer ************/
/*****************************************************************************/
static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd)
static void Svy_DB_IncreaseAnswer (long QstCod,unsigned AnsInd)
{
/***** Increase number of users who have selected the answer AnsInd in the question QstCod *****/
DB_QueryUPDATE ("can not register your answer to the survey",
@ -3893,7 +3894,7 @@ static void Svy_IncreaseAnswerInDB (long QstCod,unsigned AnsInd)
/***************** Register that I have answered this survey *****************/
/*****************************************************************************/
static void Svy_RegisterIHaveAnsweredSvy (long SvyCod)
static void Svy_DB_RegisterIHaveAnsweredSvy (long SvyCod)
{
DB_QueryINSERT ("can not register that you have answered the survey",
"INSERT INTO svy_users"
@ -3908,7 +3909,7 @@ static void Svy_RegisterIHaveAnsweredSvy (long SvyCod)
/************** Register that you have answered this survey ******************/
/*****************************************************************************/
static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod)
static bool Svy_DB_CheckIfIHaveAnsweredSvy (long SvyCod)
{
/***** Get number of surveys with a field value from database *****/
return (DB_QueryCOUNT ("can not check if you have answered a survey",
@ -3924,7 +3925,7 @@ static bool Svy_CheckIfIHaveAnsweredSvy (long SvyCod)
/*************** Register that you have answered this survey *****************/
/*****************************************************************************/
static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
static unsigned Svy_DB_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
{
/***** Get number of surveys with a field value from database *****/
return (unsigned)
@ -3941,7 +3942,7 @@ static unsigned Svy_GetNumUsrsWhoHaveAnsweredSvy (long SvyCod)
// Returns the number of courses with surveys for courses
// in this location (all the platform, current degree or current course)
unsigned Svy_GetNumCoursesWithCrsSurveys (HieLvl_Level_t Scope)
unsigned Svy_DB_GetNumCrssWithCrsSvys (HieLvl_Level_t Scope)
{
/***** Get number of courses with surveys from database *****/
switch (Scope)
@ -4145,7 +4146,7 @@ unsigned Svy_GetNumCrsSurveys (HieLvl_Level_t Scope,unsigned *NumNotif)
/************ Get average number of questions per course survey **************/
/*****************************************************************************/
double Svy_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope)
double Svy_DB_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope)
{
/***** Get number of questions per survey from database *****/
switch (Scope)
@ -4244,49 +4245,3 @@ double Svy_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope)
return 0.0; // Not reached
}
}
/*****************************************************************************/
/************ Get all user codes belonging to a survey, except me ************/
/*****************************************************************************/
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod)
{
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me
// 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM svy_surveys,"
"crs_users"
" WHERE svy_surveys.SvyCod=%ld"
" AND svy_surveys.SvyCod NOT IN"
" (SELECT SvyCod"
" FROM svy_groups"
" WHERE SvyCod=%ld)"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM svy_groups,"
"grp_users,"
"svy_surveys,"
"crs_users"
" WHERE svy_groups.SvyCod=%ld"
" AND svy_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND grp_users.UsrCod<>%ld"
" AND svy_groups.SvyCod=svy_surveys.SvyCod"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)",
SvyCod,
SvyCod,
Sco_GetDBStrFromScope (HieLvl_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod,
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (HieLvl_CRS));
}

View File

@ -120,10 +120,8 @@ void Svy_RemoveQst (void);
void Svy_ReceiveSurveyAnswers (void);
unsigned Svy_GetNumCoursesWithCrsSurveys (HieLvl_Level_t Scope);
unsigned Svy_DB_GetNumCrssWithCrsSvys (HieLvl_Level_t Scope);
unsigned Svy_GetNumCrsSurveys (HieLvl_Level_t Scope,unsigned *NumNotif);
double Svy_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope);
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod);
double Svy_DB_GetNumQstsPerCrsSurvey (HieLvl_Level_t Scope);
#endif

120
swad_survey_database.c Normal file
View File

@ -0,0 +1,120 @@
// swad_survey_database.c: surveys, 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 <linux/limits.h> // For PATH_MAX
// #include <stddef.h> // For NULL
// #include <stdio.h> // For asprintf
// #include <stdlib.h> // For calloc
// #include <string.h> // For string functions
// #include "swad_attendance.h"
// #include "swad_box.h"
#include "swad_database.h"
// #include "swad_error.h"
// #include "swad_figure.h"
// #include "swad_form.h"
#include "swad_global.h"
// #include "swad_group.h"
// #include "swad_group_database.h"
// #include "swad_HTML.h"
// #include "swad_notification.h"
// #include "swad_notification_database.h"
// #include "swad_pagination.h"
// #include "swad_parameter.h"
// #include "swad_role.h"
// #include "swad_setting.h"
// #include "swad_survey.h"
#include "swad_survey_database.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/***************************** Private constants *****************************/
/*****************************************************************************/
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private variables *****************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
/*****************************************************************************/
/************ Get all user codes belonging to a survey, except me ************/
/*****************************************************************************/
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod)
{
// 1. If the survey is available for the whole course ==> get users enroled in the course whose role is available in survey, except me
// 2. If the survey is available only for some groups ==> get users who belong to any of the groups and whose role is available in survey, except me
// Cases 1 and 2 are mutually exclusive, so the union returns the case 1 or 2
return (unsigned)
DB_QuerySELECT (mysql_res,"can not get users to be notified",
"(SELECT crs_users.UsrCod"
" FROM svy_surveys,"
"crs_users"
" WHERE svy_surveys.SvyCod=%ld"
" AND svy_surveys.SvyCod NOT IN"
" (SELECT SvyCod"
" FROM svy_groups"
" WHERE SvyCod=%ld)"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND crs_users.UsrCod<>%ld"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)"
" UNION "
"(SELECT DISTINCT grp_users.UsrCod"
" FROM svy_groups,"
"grp_users,"
"svy_surveys,"
"crs_users"
" WHERE svy_groups.SvyCod=%ld"
" AND svy_groups.GrpCod=grp_users.GrpCod"
" AND grp_users.UsrCod=crs_users.UsrCod"
" AND grp_users.UsrCod<>%ld"
" AND svy_groups.SvyCod=svy_surveys.SvyCod"
" AND svy_surveys.Scope='%s'"
" AND svy_surveys.Cod=crs_users.CrsCod"
" AND (svy_surveys.Roles&(1<<crs_users.Role))<>0)",
SvyCod,
SvyCod,
Sco_GetDBStrFromScope (HieLvl_CRS),
Gbl.Usrs.Me.UsrDat.UsrCod,
SvyCod,
Gbl.Usrs.Me.UsrDat.UsrCod,
Sco_GetDBStrFromScope (HieLvl_CRS));
}

44
swad_survey_database.h Normal file
View File

@ -0,0 +1,44 @@
// swad_survey_database.h: surveys, operations with database
#ifndef _SWAD_SVY_DB
#define _SWAD_SVY_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_date.h"
/*****************************************************************************/
/************************** Public types and constants ***********************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
unsigned Svy_DB_GetUsrsFromSurveyExceptMe (MYSQL_RES **mysql_res,long SvyCod);
#endif