Skip to content
Snippets Groups Projects
Commit f6a465a0 authored by PavelBegunkov's avatar PavelBegunkov
Browse files

remove aggregation from get teacher list for student.

parent 62421ef5
Branches
Tags
No related merge requests found
...@@ -449,55 +449,51 @@ END // ...@@ -449,55 +449,51 @@ END //
DROP PROCEDURE IF EXISTS GetTeachersListForStudent// DROP PROCEDURE IF EXISTS GetTeachersListForStudent//
CREATE PROCEDURE `GetTeachersListForStudent` ( CREATE PROCEDURE `GetTeachersListForStudent` (
IN `pStudentID` INT, IN `pStudentID` INT,
IN `pSemesterID` INT IN `pSemesterID` INT,
# todo: new parameter, pLoadAll. See Model_Student::getTeachers(). IN `pLoadAll` INT
) NO SQL ) NO SQL
BEGIN BEGIN
DECLARE vStudentGroup INT DEFAULT -1; DECLARE vStudentGroup INT DEFAULT -1;
SET vStudentGroup = GetStudentGroup(pStudentID, pSemesterID); SET vStudentGroup = GetStudentGroup(pStudentID, pSemesterID);
# select all disciplines for user
# select all disciplines for user
CREATE TEMPORARY TABLE IF NOT EXISTS tDisciplines AS ( CREATE TEMPORARY TABLE IF NOT EXISTS tDisciplines AS (
SELECT disc2.DisciplineID SELECT disc2.DisciplineID
FROM ( FROM (
SELECT disc1.DisciplineID, SELECT disc1.DisciplineID,
COALESCE(disc1.Type) AS 'Type' COALESCE(disc1.Type) AS 'Type'
FROM ( FROM (
SELECT disciplines_students.DisciplineID, SELECT disciplines_students.DisciplineID,
disciplines_students.Type disciplines_students.Type
FROM `disciplines_students` FROM `disciplines_students`
WHERE disciplines_students.StudentID = pStudentID WHERE disciplines_students.StudentID = pStudentID
UNION UNION
SELECT disciplines_groups.DisciplineID, SELECT disciplines_groups.DisciplineID,
NULL AS 'Type' NULL AS 'Type'
FROM `disciplines_groups` FROM `disciplines_groups`
WHERE disciplines_groups.GroupID = vStudentGroup WHERE disciplines_groups.GroupID = vStudentGroup
) AS disc1 ) AS disc1
INNER JOIN `disciplines` ON disciplines.ID = disc1.DisciplineID INNER JOIN `disciplines` ON disciplines.ID = disc1.DisciplineID
WHERE disciplines.SemesterID = pSemesterID WHERE disciplines.SemesterID = pSemesterID
GROUP BY disc1.DisciplineID GROUP BY disc1.DisciplineID
) AS disc2 ) AS disc2
WHERE NOT disc2.Type <=> 'detach' WHERE NOT disc2.Type <=> 'detach'
); );
SELECT tDisciplines.DisciplineID, SELECT tDisciplines.DisciplineID,
GROUP_CONCAT( teachers.ID AS 'TeacherID',
CONCAT(teachers.LastName, ' ', teachers.FirstName, ' ', teachers.SecondName) teachers.LastName,
ORDER BY teachers.ID = disciplines.AuthorID DESC, teachers.FirstName,
teachers.LastName ASC, teachers.SecondName
teachers.FirstName ASC FROM tDisciplines
SEPARATOR ';'
) AS 'FullNameList'
FROM tDisciplines
INNER JOIN `disciplines` ON disciplines.ID = tDisciplines.DisciplineID INNER JOIN `disciplines` ON disciplines.ID = tDisciplines.DisciplineID
LEFT JOIN `disciplines_teachers` ON disciplines_teachers.DisciplineID = tDisciplines.DisciplineID LEFT JOIN `disciplines_teachers` ON disciplines_teachers.DisciplineID = tDisciplines.DisciplineID
INNER JOIN `teachers` ON teachers.ID = disciplines_teachers.TeacherID INNER JOIN `teachers` ON teachers.ID = disciplines_teachers.TeacherID
GROUP BY tDisciplines.DisciplineID WHERE pLoadAll OR disciplines.Subtype IS NULL
ORDER BY tDisciplines.DisciplineID; ORDER BY tDisciplines.DisciplineID ASC,
teachers.LastName ASC,
# todo: aggregation teachers.FirstName ASC;
# todo: return teachers' ID
END // END //
......
...@@ -43,18 +43,22 @@ class Model_Student extends Model_Container ...@@ -43,18 +43,22 @@ class Model_Student extends Model_Container
// todo: don't load the full data at the Controller_Student_Index // todo: don't load the full data at the Controller_Student_Index
$semesterID = $semesterID ? $semesterID : User::instance()->SemesterID; $semesterID = $semesterID ? $semesterID : User::instance()->SemesterID;
$sql = 'CALL `GetTeachersListForStudent`(:id, :semester)'; $sql = 'CALL `GetTeachersListForStudent`(:id, :semester, :loadAll)';
$result = DB::query(Database::SELECT, $sql) $result = DB::query(Database::SELECT, $sql)
->param(':id', $this->ID) ->param(':id', $this->ID)
->param(':semester', $semesterID) ->param(':semester', $semesterID)
->param(':loadAll', $loadAll)
->execute(); ->execute();
$list = []; $list = [];
// TODO: use TeacherID. Split fullName?
foreach ($result as $row) { foreach ($result as $row) {
$names =& $list[$row['DisciplineID']]; $names =& $list[$row['DisciplineID']];
$names = explode(';', $row['FullNameList']); // todo: remove aggregation $fullName = $row['LastName'] .' '. $row['FirstName'] .' '. $row['SecondName'];
if (!$names)
$names = [];
array_push($names, $fullName);
} }
return $list; return $list;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment