francoisjacquet / rosariosis

RosarioSIS Student Information System for school management.
https://www.rosariosis.org
GNU General Public License v2.0
505 stars 347 forks source link

Mass Create Assignments #255

Closed gondas33 closed 4 years ago

gondas33 commented 4 years ago

Hello! Just came across a bug:

The Mass Create Assignments doesn't care about the teacher_id when it gets the data to insert an assignment for a certain assignment category. Therefore if I have something like this: image

(two different course periods for the same course but different teachers). Currently your code uses:

  $assignment_type_teacher_RET = DBGet( "SELECT ASSIGNMENT_TYPE_ID, STAFF_ID
                FROM GRADEBOOK_ASSIGNMENT_TYPES
                WHERE COURSE_ID=(SELECT COURSE_ID
                    FROM COURSE_PERIODS
                    WHERE COURSE_PERIOD_ID='" . $cp_id . "'
                    AND SYEAR='" . UserSyear() . "'
                    AND SCHOOL_ID='" . UserSchool() . "'
                    LIMIT 1)
                AND TRIM(TITLE)='" . $_REQUEST['assignment_type'] . "'
                LIMIT 1" );
$cp_teacher = $assignment_type_teacher_RET[1]['STAFF_ID'];
$cp_assignment_type = $assignment_type_teacher_RET[1]['ASSIGNMENT_TYPE_ID'];

as you can see, there is no identification related to staff, so the two variables will contain whatever the SQL query gets first as result(the sql query will normaly output two results if the LIMIT wouldnt be there)

Therefore, it makes it impossible for me to mass create assignments for the second period, all will go to the first course_period_id

Easy fix with following:

    $tcid=DBGet("SELECT TEACHER_ID
                    FROM COURSE_PERIODS
                    WHERE COURSE_PERIOD_ID='" . $cp_id . "'
                    AND SYEAR='" . UserSyear() . "'
                    AND SCHOOL_ID='" . UserSchool() . "'
                    LIMIT 1"); 
                $assignment_type_teacher_RET = DBGet( "SELECT ASSIGNMENT_TYPE_ID, STAFF_ID
                FROM GRADEBOOK_ASSIGNMENT_TYPES
                WHERE COURSE_ID=(SELECT COURSE_ID
                    FROM COURSE_PERIODS
                    WHERE COURSE_PERIOD_ID='" . $cp_id . "'
                    AND SYEAR='" . UserSyear() . "'
                    AND SCHOOL_ID='" . UserSchool() . "'
                    LIMIT 1)
                AND TRIM(TITLE)='" . $_REQUEST['assignment_type'] . "'
                AND STAFF_ID='".$tcid[1]['TEACHER_ID']."'
                LIMIT 1" );
francoisjacquet commented 4 years ago

Hello @an4rei

Thank you for spotting this issue and for providing a quick fix. The fix will be out in version 5.5.

gondas33 commented 4 years ago

Hello! after few tests I realized that $assignment_type_teacher_RET can give empty results with my added sql condition(STAFF_ID) as there might be a teacher_id which is new and doesn't have the assignment_type created under his id. if this query will return empty, the sql error will come from something like(duplicate inserts):

INSERT INTO "gradebook_assignments" INSERT INTO "gradebook_assignments" (ASSIGNMENT_ID,MARKING_PERIOD_ID,"title","points","default_points","description","assigned_date",ASSIGNMENT_TYPE_ID,STAFF_ID,COURSE_PERIOD_ID) values(nextval('GRADEBOOK_ASSIGNMENTS_SEQ'),'6','asda','100','22','asdaxaxa','2019-10-22','1','4','3');

Any ideas? or should I wait until 5.5 gets released.

Thanks!

francoisjacquet commented 4 years ago

Hello @an4rei

You are right, the $sql build part was moved after the CP assignment type logic.