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 //
DROP PROCEDURE IF EXISTS GetTeachersListForStudent//
CREATE PROCEDURE `GetTeachersListForStudent` (
IN `pStudentID` INT,
IN `pSemesterID` INT
# todo: new parameter, pLoadAll. See Model_Student::getTeachers().
IN `pSemesterID` INT,
IN `pLoadAll` INT
) NO SQL
BEGIN
DECLARE vStudentGroup INT DEFAULT -1;
SET vStudentGroup = GetStudentGroup(pStudentID, pSemesterID);
# select all disciplines for user
# select all disciplines for user
CREATE TEMPORARY TABLE IF NOT EXISTS tDisciplines AS (
SELECT disc2.DisciplineID
FROM (
SELECT disc1.DisciplineID,
COALESCE(disc1.Type) AS 'Type'
FROM (
SELECT disciplines_students.DisciplineID,
disciplines_students.Type
FROM `disciplines_students`
WHERE disciplines_students.StudentID = pStudentID
UNION
SELECT disciplines_groups.DisciplineID,
NULL AS 'Type'
FROM `disciplines_groups`
WHERE disciplines_groups.GroupID = vStudentGroup
) AS disc1
INNER JOIN `disciplines` ON disciplines.ID = disc1.DisciplineID
WHERE disciplines.SemesterID = pSemesterID
GROUP BY disc1.DisciplineID
) AS disc2
SELECT disc1.DisciplineID,
COALESCE(disc1.Type) AS 'Type'
FROM (
SELECT disciplines_students.DisciplineID,
disciplines_students.Type
FROM `disciplines_students`
WHERE disciplines_students.StudentID = pStudentID
UNION
SELECT disciplines_groups.DisciplineID,
NULL AS 'Type'
FROM `disciplines_groups`
WHERE disciplines_groups.GroupID = vStudentGroup
) AS disc1
INNER JOIN `disciplines` ON disciplines.ID = disc1.DisciplineID
WHERE disciplines.SemesterID = pSemesterID
GROUP BY disc1.DisciplineID
) AS disc2
WHERE NOT disc2.Type <=> 'detach'
);
SELECT tDisciplines.DisciplineID,
GROUP_CONCAT(
CONCAT(teachers.LastName, ' ', teachers.FirstName, ' ', teachers.SecondName)
ORDER BY teachers.ID = disciplines.AuthorID DESC,
teachers.LastName ASC,
teachers.FirstName ASC
SEPARATOR ';'
) AS 'FullNameList'
FROM tDisciplines
teachers.ID AS 'TeacherID',
teachers.LastName,
teachers.FirstName,
teachers.SecondName
FROM tDisciplines
INNER JOIN `disciplines` ON disciplines.ID = tDisciplines.DisciplineID
LEFT JOIN `disciplines_teachers` ON disciplines_teachers.DisciplineID = tDisciplines.DisciplineID
INNER JOIN `teachers` ON teachers.ID = disciplines_teachers.TeacherID
GROUP BY tDisciplines.DisciplineID
ORDER BY tDisciplines.DisciplineID;
# todo: aggregation
# todo: return teachers' ID
WHERE pLoadAll OR disciplines.Subtype IS NULL
ORDER BY tDisciplines.DisciplineID ASC,
teachers.LastName ASC,
teachers.FirstName ASC;
END //
......
......@@ -43,18 +43,22 @@ class Model_Student extends Model_Container
// todo: don't load the full data at the Controller_Student_Index
$semesterID = $semesterID ? $semesterID : User::instance()->SemesterID;
$sql = 'CALL `GetTeachersListForStudent`(:id, :semester)';
$sql = 'CALL `GetTeachersListForStudent`(:id, :semester, :loadAll)';
$result = DB::query(Database::SELECT, $sql)
->param(':id', $this->ID)
->param(':semester', $semesterID)
->param(':loadAll', $loadAll)
->execute();
$list = [];
// TODO: use TeacherID. Split fullName?
foreach ($result as $row) {
$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;
}
......
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