mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-03 15:25:22 +02:00
Version 22.65: Mar 01, 2023 New module swad_rubric for rubrics. Not finished.
This commit is contained in:
parent
2f7bbefe59
commit
769096e0fb
1445
swad_rubric.c
Normal file
1445
swad_rubric.c
Normal file
File diff suppressed because it is too large
Load Diff
119
swad_rubric.h
Normal file
119
swad_rubric.h
Normal file
|
@ -0,0 +1,119 @@
|
|||
// swad_rubric.h: assessment rubrics
|
||||
|
||||
#ifndef _SWAD_RUB
|
||||
#define _SWAD_RUB
|
||||
/*
|
||||
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-2022 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_date.h"
|
||||
#include "swad_scope.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Public types and constants ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Rub_MAX_CHARS_TITLE (128 - 1) // 127
|
||||
#define Rub_MAX_BYTES_TITLE ((Rub_MAX_CHARS_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
|
||||
|
||||
#define Rub_AFTER_LAST_CRITERION ((unsigned)((1UL << 31) - 1)) // 2^31 - 1, don't change this number because it is used in database
|
||||
|
||||
struct Rub_Rubric
|
||||
{
|
||||
long RubCod; // Rubric code
|
||||
long CrsCod; // Course code
|
||||
long UsrCod; // Author code
|
||||
char Title[Rub_MAX_BYTES_TITLE + 1];
|
||||
unsigned NumCriteria; // Number of criteria in the rubric
|
||||
};
|
||||
|
||||
struct Rub_Rubrics
|
||||
{
|
||||
bool LstIsRead; // Is the list already read from database...
|
||||
// ...or it needs to be read?
|
||||
unsigned Num; // Total number of rubrics
|
||||
long *Lst; // List of rubric codes
|
||||
unsigned CurrentPage;
|
||||
struct Rub_Rubric Rubric; // Selected/current rubric
|
||||
};
|
||||
|
||||
struct Rub_Criterion
|
||||
{
|
||||
long RubCod; // Rubric code
|
||||
long CriCod; // Course code
|
||||
char Title[Rub_MAX_BYTES_TITLE + 1];
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_ResetRubrics (struct Rub_Rubrics *Rubrics);
|
||||
void Rub_ResetRubric (struct Rub_Rubric *Rubric);
|
||||
|
||||
void Rub_SeeAllRubrics (void);
|
||||
void Rub_ListAllRubrics (struct Rub_Rubrics *Rubrics);
|
||||
void Rub_SeeOneRubric (void);
|
||||
void Rub_ShowOnlyOneRubric (struct Rub_Rubrics *Rubrics,
|
||||
bool ListRubricDims);
|
||||
void Rub_ShowOnlyOneRubricBegin (struct Rub_Rubrics *Rubrics,
|
||||
bool ListRubricDims);
|
||||
void Rub_ShowOnlyOneRubricEnd (void);
|
||||
|
||||
void Rub_SetCurrentRubCod (long GamCod);
|
||||
void Rub_PutParams (void *Rubrics);
|
||||
void Rub_PutParamRubCod (long RubCod);
|
||||
long Rub_GetParamRubCod (void);
|
||||
long Rub_GetParams (struct Rub_Rubrics *Rubrics);
|
||||
|
||||
void Rub_GetListRubrics (struct Rub_Rubrics *Rubrics);
|
||||
void Rub_GetDataOfRubricByCod (struct Rub_Rubric *Rubric);
|
||||
void Rub_GetDataOfRubricByFolder (struct Rub_Rubric *Rubric);
|
||||
void Rub_FreeListRubrics (struct Rub_Rubrics *Rubrics);
|
||||
|
||||
void Rub_AskRemRubric (void);
|
||||
void Rub_RemoveRubric (void);
|
||||
void Rub_RemoveCrsRubrics (long CrsCod);
|
||||
|
||||
void Rub_ListRubric (void);
|
||||
|
||||
void Rub_RequestCreatOrEditRubric (void);
|
||||
|
||||
void Rub_ReceiveFormRubric (void);
|
||||
|
||||
//------------------------------- Criteria ------------------------------------
|
||||
void Rub_CriterionConstructor (struct Rub_Criterion *Criterion);
|
||||
void Rub_CriterionDestructor (struct Rub_Criterion *Criterion);
|
||||
void Rub_PutParamCriCod (void *CriCod);
|
||||
bool Rub_GetCriterionDataFromDB (struct Rub_Criterion *Criterion);
|
||||
void Rub_ListCriterionForEdition (struct Rub_Criterion *Criterion,
|
||||
unsigned CriInd,bool CriterionExists,
|
||||
const char *Anchor);
|
||||
void Rub_WriteNumCriterion (unsigned NumDim,const char *Class);
|
||||
void Rub_WriteCriterionTitle (const char *Title,const char *ClassTitle,bool Visible);
|
||||
|
||||
//-------------------------------- Figures ------------------------------------
|
||||
void Rub_GetAndShowRubricsStats (void);
|
||||
|
||||
#endif
|
672
swad_rubric_database.c
Normal file
672
swad_rubric_database.c
Normal file
|
@ -0,0 +1,672 @@
|
|||
// swad_rubric_database.c: assessment rubrics, 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-2022 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 <stdio.h> // For asprintf
|
||||
#include <stdlib.h> // For free
|
||||
|
||||
#include "swad_database.h"
|
||||
#include "swad_error.h"
|
||||
#include "swad_rubric.h"
|
||||
#include "swad_rubric_database.h"
|
||||
#include "swad_global.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** External global variables from others modules ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Create a new rubric *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Rub_DB_CreateRubric (const struct Rub_Rubric *Rubric,const char *Txt)
|
||||
{
|
||||
return
|
||||
DB_QueryINSERTandReturnCode ("can not create new rubric",
|
||||
"INSERT INTO rub_rubrics"
|
||||
" (CrsCod,UsrCod,Title,Txt)"
|
||||
" VALUES"
|
||||
" (%ld,%ld,'%s','%s')",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Gbl.Usrs.Me.UsrDat.UsrCod,
|
||||
Rubric->Title,
|
||||
Txt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************** Update an existing rubric ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_UpdateRubric (const struct Rub_Rubric *Rubric,const char *Txt)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update rubric",
|
||||
"UPDATE rub_rubrics"
|
||||
" SET CrsCod=%ld,"
|
||||
"Title='%s',"
|
||||
"Txt='%s'"
|
||||
" WHERE RubCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Rubric->Title,
|
||||
Txt,
|
||||
Rubric->RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************** Get list of all rubrics in the current course ****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Rub_DB_GetListRubrics (MYSQL_RES **mysql_res)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get rubrics",
|
||||
"SELECT RubCod" // row[0]
|
||||
" FROM rub_rubrics"
|
||||
" WHERE CrsCod=%ld"
|
||||
" ORDER BY Title",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************* Get rubric data using its code ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Rub_DB_GetDataOfRubricByCod (MYSQL_RES **mysql_res,long RubCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get rubric data",
|
||||
"SELECT RubCod," // row[0]
|
||||
"CrsCod," // row[1]
|
||||
"UsrCod," // row[2]
|
||||
"Title" // row[3]
|
||||
" FROM rub_rubrics"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
RubCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Get rubric title from database ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_GetRubricTitle (long RubCod,char Title[Rub_MAX_BYTES_TITLE + 1])
|
||||
{
|
||||
DB_QuerySELECTString (Title,Rub_MAX_BYTES_TITLE,"can not get rubric title",
|
||||
"SELECT Title" // row[0]
|
||||
" FROM rub_rubrics"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
RubCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Get rubric text from database ************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_GetRubricTxt (long RubCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
|
||||
{
|
||||
DB_QuerySELECTString (Txt,Cns_MAX_BYTES_TEXT,"can not get rubric text",
|
||||
"SELECT Txt" // row[0]
|
||||
" FROM rub_rubrics"
|
||||
" WHERE RubCod=%ld",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Check if the title of a rubric exists *******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
bool Rub_DB_CheckIfSimilarRubricExists (const struct Rub_Rubric *Rubric)
|
||||
{
|
||||
return
|
||||
DB_QueryEXISTS ("can not check similar rubrics",
|
||||
"SELECT EXISTS"
|
||||
"(SELECT *"
|
||||
" FROM rub_rubrics"
|
||||
" WHERE CrsCod=%ld"
|
||||
" AND Title='%s'"
|
||||
" AND RubCod<>%ld)",
|
||||
Gbl.Hierarchy.Crs.CrsCod,
|
||||
Rubric->Title,
|
||||
Rubric->RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************** Get number of courses with rubrics *********************/
|
||||
/*****************************************************************************/
|
||||
// Returns the number of courses with rubrics in this location
|
||||
|
||||
unsigned Rub_DB_GetNumCoursesWithRubrics (HieLvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of courses with rubrics from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case HieLvl_SYS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM rub_rubrics");
|
||||
case HieLvl_CTY:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT rub_rubrics.CrsCod)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case HieLvl_INS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT rub_rubrics.CrsCod)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case HieLvl_CTR:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT rub_rubrics.CrsCod)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case HieLvl_DEG:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT rub_rubrics.CrsCod)"
|
||||
" FROM crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case HieLvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of courses with rubrics",
|
||||
"SELECT COUNT(DISTINCT CrsCod)"
|
||||
" FROM rub_rubrics"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************************** Get number of rubrics ***************************/
|
||||
/*****************************************************************************/
|
||||
// Returns the number of rubrics in this location
|
||||
|
||||
unsigned Rub_DB_GetNumRubrics (HieLvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of rubrics from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case HieLvl_SYS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM rub_rubrics");
|
||||
case HieLvl_CTY:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
case HieLvl_INS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case HieLvl_CTR:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case HieLvl_DEG:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM crs_courses,"
|
||||
"rub_rubrics"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case HieLvl_CRS:
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of rubrics",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM rub_rubrics"
|
||||
" WHERE CrsCod=%ld",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************************** Remove rubric ******************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_RemoveRubric (long RubCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove rubric",
|
||||
"DELETE FROM rub_rubrics"
|
||||
" WHERE RubCod=%ld",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********************** Remove the rubrics of a course ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_RemoveCrsRubrics (long CrsCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove course rubrics",
|
||||
"DELETE FROM rub_rubrics"
|
||||
" WHERE CrsCod=%ld",
|
||||
CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Insert criterion in the table of criteria *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_InsertCriterionInRubric (long RubCod,unsigned CriInd,long CriCod)
|
||||
{
|
||||
DB_QueryINSERT ("can not add criterion to rubric",
|
||||
"INSERT INTO rub_criteria"
|
||||
" (RubCod,CriInd,CriCod)"
|
||||
" VALUES"
|
||||
" (%ld,%u,%ld)",
|
||||
RubCod,
|
||||
CriInd,
|
||||
CriCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Update indexes of criteria greater than a given one ***********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_UpdateIndexesOfCriteriaGreaterThan (long RubCod,unsigned CriInd)
|
||||
{
|
||||
DB_QueryUPDATE ("can not update indexes of criteria",
|
||||
"UPDATE rub_criteria"
|
||||
" SET CriInd=CriInd-1"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriInd>%u",
|
||||
RubCod,
|
||||
CriInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Change index of a criterion in a rubric ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_UpdateCriterionIndex (long CriInd,long RubCod,long CriCod)
|
||||
{
|
||||
DB_QueryUPDATE ("can not exchange indexes of criteria",
|
||||
"UPDATE rub_criteria"
|
||||
" SET CriInd=%ld"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriCod=%ld",
|
||||
CriInd,
|
||||
RubCod,
|
||||
CriCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Lock table to make the exchange of criteria atomic ***********/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_LockTable (void)
|
||||
{
|
||||
DB_Query ("can not lock tables to move rubric criterion",
|
||||
"LOCK TABLES rub_criteria WRITE");
|
||||
DB_SetThereAreLockedTables ();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******************* Get number of criteria of a rubric *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Rub_DB_GetNumCriteriaInRubric (long RubCod)
|
||||
{
|
||||
/***** Get nuumber of criteria in a rubric from database *****/
|
||||
return (unsigned)
|
||||
DB_QueryCOUNT ("can not get number of criteria of a rubric",
|
||||
"SELECT COUNT(*)"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Get the criteria of a rubric ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Rub_DB_GetRubricCriteriaBasic (MYSQL_RES **mysql_res,long RubCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get rubric criteria",
|
||||
"SELECT CriCod," // row[0]
|
||||
"CriInd" // row[1]
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" ORDER BY CriInd",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get criterion code given rubric and index of criterion ************/
|
||||
/*****************************************************************************/
|
||||
|
||||
long Rub_DB_GetCriCodFromCriInd (long RubCod,unsigned CriInd)
|
||||
{
|
||||
long CriCod;
|
||||
|
||||
CriCod = DB_QuerySELECTCode ("can not get criterion code",
|
||||
"SELECT CriCod"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriInd=%u",
|
||||
RubCod,
|
||||
CriInd);
|
||||
if (CriCod <= 0)
|
||||
Err_WrongCriterionExit ();
|
||||
|
||||
return CriCod;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********** Get criterion index given rubric and code of criterion ***********/
|
||||
/*****************************************************************************/
|
||||
// Return 0 is criterion is not present in rubric
|
||||
|
||||
unsigned Rub_DB_GetCriIndFromCriCod (long RubCod,long CriCod)
|
||||
{
|
||||
return DB_QuerySELECTUnsigned ("can not get criterion index",
|
||||
"SELECT CriInd"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriCod=%ld",
|
||||
RubCod,
|
||||
CriCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Get maximum criterion index in a rubric ********************/
|
||||
/*****************************************************************************/
|
||||
// Criterion index can be 1, 2, 3...
|
||||
// Return 0 if no criteria
|
||||
|
||||
unsigned Rub_DB_GetMaxCriterionIndexInRubric (long RubCod)
|
||||
{
|
||||
/***** Get maximum criterion index in a rubric from database *****/
|
||||
return DB_QuerySELECTUnsigned ("can not get last criterion index",
|
||||
"SELECT MAX(CriInd)"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/********* Get previous criterion index to a given index in a rubric *********/
|
||||
/*****************************************************************************/
|
||||
// Input criterion index can be 1, 2, 3... n-1
|
||||
// Return criterion index will be 1, 2, 3... n if previous criterion exists, or 0 if no previous criterion
|
||||
|
||||
unsigned Rub_DB_GetPrevCriterionIndexInRubric (long RubCod,unsigned CriInd)
|
||||
{
|
||||
/***** Get previous criterion index in a rubric from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get previous criterion index",
|
||||
"SELECT COALESCE(MAX(CriInd),0)"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriInd<%u",
|
||||
RubCod,
|
||||
CriInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********** Get next criterion index to a given index in a rubric ***********/
|
||||
/*****************************************************************************/
|
||||
// Input criterion index can be 0, 1, 2, 3... n-1
|
||||
// Return criterion index will be 1, 2, 3... n if next criterion exists, or big number if no next criterion
|
||||
|
||||
unsigned Rub_DB_GetNextCriterionIndexInRubric (long RubCod,unsigned CriInd)
|
||||
{
|
||||
/***** Get next criterion index in a rubric from database *****/
|
||||
// Although indexes are always continuous...
|
||||
// ...this implementation works even with non continuous indexes
|
||||
return DB_QuerySELECTUnsigned ("can not get next criterion index",
|
||||
"SELECT COALESCE(MIN(CriInd),%u)"
|
||||
" FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriInd>%u",
|
||||
Rub_AFTER_LAST_CRITERION, // End of criteria has been reached
|
||||
RubCod,
|
||||
CriInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/****************** Get data of a criterion from database ********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
unsigned Rub_DB_GetCriterionData (MYSQL_RES **mysql_res,long CriCod)
|
||||
{
|
||||
return (unsigned)
|
||||
DB_QuerySELECT (mysql_res,"can not get a criterion",
|
||||
"SELECT Title" // row[0]
|
||||
" FROM rub_criteria"
|
||||
" WHERE QstCod=%ld"
|
||||
" AND CrsCod=%ld", // Extra check
|
||||
CriCod,
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Get average number of criteria per rubric ******************/
|
||||
/*****************************************************************************/
|
||||
|
||||
double Rub_DB_GetNumCriteriaPerRubric (HieLvl_Level_t Scope)
|
||||
{
|
||||
/***** Get number of criteria per rubric from database *****/
|
||||
switch (Scope)
|
||||
{
|
||||
case HieLvl_SYS:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable");
|
||||
case HieLvl_CTY:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM ins_instits,"
|
||||
"ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE ins_instits.CtyCod=%ld"
|
||||
" AND ins_instits.InsCod=ctr_centers.InsCod"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable",
|
||||
Gbl.Hierarchy.Cty.CtyCod);
|
||||
case HieLvl_INS:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM ctr_centers,"
|
||||
"deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE ctr_centers.InsCod=%ld"
|
||||
" AND ctr_centers.CtrCod=deg_degrees.CtrCod"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable",
|
||||
Gbl.Hierarchy.Ins.InsCod);
|
||||
case HieLvl_CTR:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM deg_degrees,"
|
||||
"crs_courses,"
|
||||
"rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE deg_degrees.CtrCod=%ld"
|
||||
" AND deg_degrees.DegCod=crs_courses.DegCod"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable",
|
||||
Gbl.Hierarchy.Ctr.CtrCod);
|
||||
case HieLvl_DEG:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM crs_courses,"
|
||||
"rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE crs_courses.DegCod=%ld"
|
||||
" AND crs_courses.CrsCod=rub_rubrics.CrsCod"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable",
|
||||
Gbl.Hierarchy.Deg.DegCod);
|
||||
case HieLvl_CRS:
|
||||
return
|
||||
DB_QuerySELECTDouble ("can not get number of criteria per rubric",
|
||||
"SELECT AVG(NumCriteria)"
|
||||
" FROM (SELECT COUNT(rub_criteria.QstCod) AS NumCriteria"
|
||||
" FROM rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE rub_rubrics.Cod=%ld"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod"
|
||||
" GROUP BY rub_criteria.RubCod) AS NumCriteriaTable",
|
||||
Gbl.Hierarchy.Crs.CrsCod);
|
||||
default:
|
||||
Err_WrongScopeExit ();
|
||||
return 0.0; // Not reached
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** Remove criterion from a rubric **********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_RemoveCriterionFromRubric (long RubCod,unsigned CriInd)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove a criterion",
|
||||
"DELETE FROM rub_criteria"
|
||||
" WHERE RubCod=%ld"
|
||||
" AND CriInd=%u",
|
||||
RubCod,
|
||||
CriInd);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Remove rubric criteria *************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_RemoveRubricCriteria (long RubCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove rubric criteria",
|
||||
"DELETE FROM rub_criteria"
|
||||
" WHERE RubCod=%ld",
|
||||
RubCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************** Remove the criteria in rubrics of a course *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Rub_DB_RemoveCrsRubricCriteria (long CrsCod)
|
||||
{
|
||||
DB_QueryDELETE ("can not remove criteria in course rubrics",
|
||||
"DELETE FROM rub_criteria"
|
||||
" USING rub_rubrics,"
|
||||
"rub_criteria"
|
||||
" WHERE rub_rubrics.CrsCod=%ld"
|
||||
" AND rub_rubrics.RubCod=rub_criteria.RubCod",
|
||||
CrsCod);
|
||||
}
|
75
swad_rubric_database.h
Normal file
75
swad_rubric_database.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
// swad_rubric_database.h: assessment rubrics, operations with database
|
||||
|
||||
#ifndef _SWAD_RUB_DB
|
||||
#define _SWAD_RUB_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-2022 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_game.h"
|
||||
#include "swad_hierarchy_level.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
//-------------------------------- Rubrics ------------------------------------
|
||||
long Rub_DB_CreateRubric (const struct Rub_Rubric *Rubric,const char *Txt);
|
||||
void Rub_DB_UpdateRubric (const struct Rub_Rubric *Rubric,const char *Txt);
|
||||
void Rub_DB_HideOrUnhideRubric (long RubCod,bool Hide);
|
||||
|
||||
unsigned Rub_DB_GetListRubrics (MYSQL_RES **mysql_res);
|
||||
unsigned Rub_DB_GetDataOfRubricByCod (MYSQL_RES **mysql_res,long RubCod);
|
||||
void Rub_DB_GetRubricTitle (long RubCod,char Title[Rub_MAX_BYTES_TITLE + 1]);
|
||||
void Rub_DB_GetRubricTxt (long RubCod,char Txt[Cns_MAX_BYTES_TEXT + 1]);
|
||||
bool Rub_DB_CheckIfSimilarRubricExists (const struct Rub_Rubric *Rubric);
|
||||
unsigned Rub_DB_GetNumCoursesWithRubrics (HieLvl_Level_t Scope);
|
||||
unsigned Rub_DB_GetNumRubrics (HieLvl_Level_t Scope);
|
||||
|
||||
void Rub_DB_RemoveRubric (long RubCod);
|
||||
void Rub_DB_RemoveCrsRubrics (long CrsCod);
|
||||
|
||||
//--------------------------- Rubric criteria -------------------------------
|
||||
void Rub_DB_InsertCriterionInRubric (long RubCod,unsigned CriInd,long CriCod);
|
||||
void Rub_DB_UpdateIndexesOfCriteriaGreaterThan (long RubCod,unsigned CriInd);
|
||||
void Rub_DB_UpdateCriterionIndex (long CriInd,long RubCod,long CriCod);
|
||||
void Rub_DB_LockTable (void);
|
||||
|
||||
unsigned Rub_DB_GetNumCriteriaInRubric (long RubCod);
|
||||
unsigned Rub_DB_GetRubricCriteriaBasic (MYSQL_RES **mysql_res,long RubCod);
|
||||
long Rub_DB_GetCriCodFromCriInd (long RubCod,unsigned QstInd);
|
||||
unsigned Rub_DB_GetCriIndFromCriCod (long RubCod,long QstCod);
|
||||
unsigned Rub_DB_GetMaxCriterionIndexInRubric (long RubCod);
|
||||
unsigned Rub_DB_GetPrevCriterionIndexInRubric (long RubCod,unsigned QstInd);
|
||||
unsigned Rub_DB_GetNextCriterionIndexInRubric (long RubCod,unsigned QstInd);
|
||||
unsigned Rub_DB_GetCriterionData (MYSQL_RES **mysql_res,long CriCod);
|
||||
double Rub_DB_GetNumCriteriaPerRubric (HieLvl_Level_t Scope);
|
||||
|
||||
void Rub_DB_RemoveCriterionFromRubric (long RubCod,unsigned CriInd);
|
||||
void Rub_DB_RemoveRubricCriteria (long RubCod);
|
||||
void Rub_DB_RemoveCrsRubricCriteria (long CrsCod);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user