Skip to content

Commit

Permalink
Version 24.50: Dec 17, 2024 Rubrics associated to assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
acanas committed Dec 16, 2024
1 parent 229fbca commit 1d4bd8f
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sql/swad.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ CREATE TABLE IF NOT EXISTS asg_groups (
GrpCod INT NOT NULL,
UNIQUE INDEX(AsgCod,GrpCod));
--
-- Table asg_rubrics: stores the rubrics associated to assigments
--
CREATE TABLE IF NOT EXISTS asg_rubrics (
AsgCod INT NOT NULL,
RubCod INT NOT NULL,
UNIQUE INDEX(AsgCod));
--
-- Table att_events: stores events used to control attendance
--
CREATE TABLE IF NOT EXISTS att_events (
Expand Down
83 changes: 83 additions & 0 deletions swad_assignment.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#include "swad_parameter_code.h"
#include "swad_photo.h"
#include "swad_role.h"
#include "swad_rubric_database.h"
#include "swad_rubric_type.h"
#include "swad_setting.h"
#include "swad_string.h"

Expand Down Expand Up @@ -100,7 +102,10 @@ static void Asg_GetAssignmentDataFromRow (MYSQL_RES **mysql_res,
static void Asg_ResetAssignment (struct Asg_Assignment *Asg);
static void Asg_FreeListAssignments (struct Asg_Assignments *Assignments);
static void Asg_HideUnhideAssignment (HidVis_HiddenOrVisible_t HiddenOrVisible);

static void Asg_EditRubrics (long AsgRubCod);
static void Asg_ShowLstGrpsToEditAssignment (long AsgCod);

static void Asg_CreateAssignment (struct Asg_Assignment *Asg,const char *Txt);
static void Asg_UpdateAssignment (struct Asg_Assignment *Asg,const char *Txt);
static void Asg_CreateGroups (long AsgCod);
Expand Down Expand Up @@ -961,6 +966,7 @@ static void Asg_ResetAssignment (struct Asg_Assignment *Asg)
Asg->Title[0] = '\0';
Asg->SendWork = Asg_DONT_SEND_WORK;
Asg->Folder[0] = '\0';
Asg->RubCod = -1L;
Asg->ICanDo = Usr_CAN_NOT;
}

Expand Down Expand Up @@ -1184,6 +1190,7 @@ void Asg_ReqCreatOrEditAsg (void)
Assignments.Asg.Title[0] = '\0';
Assignments.Asg.SendWork = Asg_DONT_SEND_WORK;
Assignments.Asg.Folder[0] = '\0';
Assignments.Asg.RubCod = -1L;
Assignments.Asg.ICanDo = Usr_CAN_NOT;
}
else
Expand All @@ -1193,6 +1200,9 @@ void Asg_ReqCreatOrEditAsg (void)

/* Get text of the assignment from database */
Asg_DB_GetAssignmentTxt (Assignments.Asg.AsgCod,Txt);

/* Get rubric associated to the assignment from database */
Assignments.Asg.RubCod = Asg_DB_GetAssignmentRubCod (Assignments.Asg.AsgCod);
}

/***** Begin form *****/
Expand Down Expand Up @@ -1273,6 +1283,10 @@ void Asg_ReqCreatOrEditAsg (void)

HTM_TR_End ();

/***** Rubrics *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) // TODO: Remove when finished
Asg_EditRubrics (Assignments.Asg.RubCod);

/***** Groups *****/
Asg_ShowLstGrpsToEditAssignment (Assignments.Asg.AsgCod);

Expand All @@ -1290,6 +1304,68 @@ void Asg_ReqCreatOrEditAsg (void)
Asg_ShowAllAssignments (&Assignments);
}

/*****************************************************************************/
/***************** Edit rubrics associated to an assignment ******************/
/*****************************************************************************/

static void Asg_EditRubrics (long AsgRubCod)
{
extern const char *Par_CodeStr[Par_NUM_PAR_COD];
extern const char *Txt_Rubric;
extern const char *Txt_no_rubric;
MYSQL_RES *mysql_res;
unsigned NumRubrics;
unsigned NumRub;
long RubCod;
char Title[Rub_MAX_BYTES_TITLE + 1];

/***** Begin row *****/
HTM_TR_Begin (NULL);

/* Label */
Frm_LabelColumn ("Frm_C1 RT","",Txt_Rubric);

/* Rubrics */
HTM_TD_Begin ("class=\"Frm_C2 LT\"");

/* Get rubrics for current course from database */
NumRubrics = Rub_DB_GetListRubrics (&mysql_res);

HTM_SELECT_Begin (HTM_NO_ATTR,NULL,
"name=\"%s\" class=\"PrjCfg_RUBRIC_SEL\"",
Par_CodeStr[ParCod_Rub]);

/* First option to indicate that no rubric is selected */
HTM_OPTION (HTM_Type_STRING,"-1",
HTM_NO_ATTR,
"[%s]",Txt_no_rubric);

/* One selector for each rubric */
for (NumRub = 0;
NumRub < NumRubrics;
NumRub++)
{
RubCod = DB_GetNextCode (mysql_res);

/* One option for each rubric in this course */
Rub_DB_GetRubricTitle (RubCod,Title,Rub_MAX_BYTES_TITLE);
HTM_OPTION (HTM_Type_LONG,&RubCod,
(RubCod == AsgRubCod) ? HTM_SELECTED :
HTM_NO_ATTR,
"%s",Title);
}

HTM_SELECT_End ();

/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);

HTM_TD_End ();

/***** End row *****/
HTM_TR_End ();
}

/*****************************************************************************/
/**************** Show list of groups to edit and assignment *****************/
/*****************************************************************************/
Expand Down Expand Up @@ -1352,6 +1428,7 @@ void Asg_ReceiveAssignment (void)
bool NewAssignmentIsCorrect = true;
unsigned NumUsrsToBeNotifiedByEMail;
char Description[Cns_MAX_BYTES_TEXT + 1];
long NewRubCod;

/***** Reset assignments *****/
Asg_ResetAssignments (&Assignments);
Expand Down Expand Up @@ -1451,6 +1528,12 @@ void Asg_ReceiveAssignment (void)
/***** Create a new assignment or update an existing one *****/
if (NewAssignmentIsCorrect)
{
/* Check if current rubric code must be changed */
OldAsg.RubCod = Asg_DB_GetAssignmentRubCod (OldAsg.AsgCod);
NewRubCod = ParCod_GetPar (ParCod_Rub);
if (NewRubCod != Assignments.Asg.RubCod)
Asg_DB_UpdateRubCod (OldAsg.AsgCod,NewRubCod);

/* Get groups for this assignments */
Grp_GetParCodsSeveralGrps ();

Expand Down
1 change: 1 addition & 0 deletions swad_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct Asg_Assignment
char Title[Asg_MAX_BYTES_ASSIGNMENT_TITLE + 1];
Asg_SendWork_t SendWork;
char Folder[Brw_MAX_BYTES_FOLDER + 1];
long RubCod;
Usr_Can_t ICanDo; // I can do this assignment
// (it is associated to no groups
// or, if associated to groups,
Expand Down
55 changes: 55 additions & 0 deletions swad_assignment_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,61 @@ void Asg_DB_RemoveAssignment (long AsgCod)
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
}

/*****************************************************************************/
/****************** Get assignment rubric from database **********************/
/*****************************************************************************/

long Asg_DB_GetAssignmentRubCod (long AsgCod)
{
return DB_QuerySELECTCode ("can not get assignment rubric",
"SELECT asg_rubrics.RubCod"
" FROM asg_rubrics,"
"rub_rubrics"
" WHERE asg_rubrics.AsgCod=%ld"
" AND asg_rubrics.RubCod=rub_rubrics.RubCod"
" AND rub_rubrics.CrsCod=%ld", // Extra check
AsgCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod);
}

/*****************************************************************************/
/************** Update the rubric associated to an assignment ****************/
/*****************************************************************************/

void Asg_DB_UpdateRubCod (long AsgCod,long RubCod)
{
/***** Trivial check *****/
if (AsgCod <= 0)
return;

/***** Update the rubric of the assignment *****/
if (RubCod > 0)
{
/* Check that rubric belongs to this course */
if (DB_QueryEXISTS ("can not check rubric",
"SELECT EXISTS"
"(SELECT *"
" FROM rub_rubrics"
" WHERE RubCod=%ld"
" AND CrsCod=%ld)",
RubCod,
Gbl.Hierarchy.Node[Hie_CRS].HieCod))
/* Update the rubric of the assignment */
DB_QueryREPLACE ("can not update assignment rubric",
"REPLACE INTO asg_rubrics"
" (AsgCod,RubCod)"
" VALUES"
" (%ld,%ld)",
AsgCod,RubCod);
}
else
/* Remove the rubric from the assignment */
DB_QueryDELETE ("can not remove assignment",
"DELETE FROM asg_rubrics"
" WHERE AsgCod=%ld",
AsgCod);
}

/*****************************************************************************/
/********************* Check if I can do an assignment ***********************/
/*****************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions swad_assignment_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ bool Asg_DB_CheckIfSimilarAssignmentExists (const char *Field,const char *Value,

long Asg_DB_CreateAssignment (const struct Asg_Assignment *Asg,const char *Txt);
void Asg_DB_UpdateAssignment (const struct Asg_Assignment *Asg,const char *Txt);

void Asg_DB_HideOrUnhideAssignment (long AsgCod,
HidVis_HiddenOrVisible_t HiddenOrVisible);

void Asg_DB_RemoveAssignment (long AsgCod);

// -------------------- Rubric associated to assignment -----------------------
long Asg_DB_GetAssignmentRubCod (long AsgCod);
void Asg_DB_UpdateRubCod (long AsgCod,long RubCod);

Usr_Can_t Asg_DB_CheckIfICanDoAsgBasedOnGroups (long AsgCod);

unsigned Asg_DB_GetGrps (MYSQL_RES **mysql_res,long AsgCod);
Expand Down
8 changes: 7 additions & 1 deletion swad_changelog.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,16 @@ TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la ho
TODO: Al confirmar el DNI de un profesor, sale "Wrong action" en el horario de tutor�as.
*/

#define Log_PLATFORM_VERSION "SWAD 24.49 (2024-12-16)"
#define Log_PLATFORM_VERSION "SWAD 24.50 (2024-12-17)"
#define CSS_FILE "swad24.48.1.css"
#define JS_FILE "swad23.89.js"
/*
Version 24.50: Dec 17, 2024 Rubrics associated to assignments. (344868 lines)
1 change necessary in database:
CREATE TABLE IF NOT EXISTS asg_rubrics (AsgCod INT NOT NULL,RubCod INT NOT NULL,UNIQUE INDEX(AsgCod));
If you want to use MyISAM:
ALTER TABLE asg_rubrics ENGINE=MyISAM;

Version 24.49: Dec 16, 2024 Changes and code refactoring in rubrics. (344723 lines)
Version 24.48.2: Dec 16, 2024 Changes in rubrics. (344708 lines)
Version 24.48.1: Dec 12, 2024 Changes in layout of trees. (344704 lines)
Expand Down
16 changes: 16 additions & 0 deletions swad_database.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ mysql> DESCRIBE asg_groups;
"GrpCod INT NOT NULL,"
"UNIQUE INDEX(AsgCod,GrpCod))");

/***** Table asg_rubrics *****/
/*
mysql> DESCRIBE asg_rubrics;
+--------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------+------+-----+---------+-------+
| AsgCod | int | NO | PRI | NULL | |
| RubCod | int | NO | | NULL | |
+--------+------+------+-----+---------+-------+
2 rows in set (0,00 sec)
*/
DB_CreateTable ("CREATE TABLE IF NOT EXISTS asg_rubrics ("
"AsgCod INT NOT NULL,"
"RubCod INT NOT NULL,"
"UNIQUE INDEX(AsgCod))");

/***** Table att_events *****/
/*
mysql> DESCRIBE att_events;
Expand Down

0 comments on commit 1d4bd8f

Please sign in to comment.