Skip to content
Snippets Groups Projects
Commit de8ed7c8 authored by xamgore's avatar xamgore
Browse files

Speed up of students' index page loading

parent 4bef5587
Branches
Tags
No related merge requests found
......@@ -450,6 +450,7 @@ DROP PROCEDURE IF EXISTS GetTeachersListForStudent//
CREATE PROCEDURE `GetTeachersListForStudent` (
IN `pStudentID` INT,
IN `pSemesterID` INT
# todo: new parameter, pLoadAll. See Model_Student::getTeachers().
) NO SQL
BEGIN
DECLARE vStudentGroup INT DEFAULT -1;
......@@ -494,6 +495,9 @@ BEGIN
INNER JOIN `teachers` ON teachers.ID = disciplines_teachers.TeacherID
GROUP BY tDisciplines.DisciplineID
ORDER BY tDisciplines.DisciplineID;
# todo: aggregation
# todo: return teachers' ID
END //
......
......@@ -3,22 +3,19 @@
class Controller_Student_Index extends Controller_Environment_Student
{
public function action_index() {
$student_id = $this->user->StudentID;
$disciplines = Model_Student::load($student_id)->getDisciplines();
$teachers = [];
$student = Model_Student::load($this->user->StudentID);
$disciplines = $student->getDisciplines();
$marks = [];
foreach ($disciplines as $dis) {
// todo: Pavel will wrote an optimized query GetTeachersListForStudent
if (!$dis->Subtype)
$teachers[$dis->ID] = $dis->getTeachers();
# fixme: ExamRate is not defined in the `GetDisciplinesForStudent` function!
$dis->ColorScheme = Model_Subject::getECTSMark($dis->Rate, $dis->MaxCurrentRate, NULL /*$dis['examRate']*/);
if (isset($dis->Rate) && isset($dis->MaxCurrentRate))
$marks[$dis->ID] = Model_Subject::getECTSMark($dis->Rate, $dis->MaxCurrentRate, $exam = NULL);
}
$this->twig->set([
'Teachers' => $teachers,
'Marks' => $marks,
'Disciplines' => $disciplines,
'Teachers' => $student->getTeachers(),
'SemesterList' => Model_Semesters::loadAll(),
])->set_filename(static::STUDENT . 'index');
}
......
......@@ -39,6 +39,25 @@ class Model_Student extends Model_Container
return $list;
}
public function getTeachers($loadAll = false, $semesterID = null) {
// todo: don't load the full data at the Controller_Student_Index
$semesterID = $semesterID ? $semesterID : User::instance()->SemesterID;
$sql = 'CALL `GetTeachersListForStudent`(:id, :semester)';
$result = DB::query(Database::SELECT, $sql)
->param(':id', $this->ID)
->param(':semester', $semesterID)
->execute();
$list = [];
foreach ($result as $row) {
$names =& $list[$row['DisciplineID']];
$names = explode(';', $row['FullNameList']); // todo: remove aggregation
}
return $list;
}
// todo implementation
public function update() {
throw new BadMethodCallException('Method is not implemented yet!');
......
{% extends 'base' %}
{% macro subject(Discipline, Teachers, HTML) %}
{% macro subject(Discipline, Teachers, Marks, HTML) %}
<tr class="disciplineRow">
<td class="discProgress">
<span title="Успеваемость по дисциплине" class="Circle {{ Discipline.ColorScheme }}">
<span title="Успеваемость по дисциплине" class="Circle {{ Marks[Discipline.ID] }}">
{% if Discipline.MaxCurrentRate != 0 %}
{% if Discipline.Rate >= Discipline.MaxCurrentRate %}
100%
......@@ -77,7 +77,7 @@
<td>Текущие баллы</td>
</tr>
{% for i in Disciplines %}
{{ res.subject(i, Teachers, HTML) }}
{{ res.subject(i, Teachers, Marks, HTML) }}
{% else %}
<tr>
<td colspan="5"><h2 style="text-align: center;">В настоящий момент Вы не подписаны ни на одну из существующих дисциплин.</h2></td>
......
......@@ -14,8 +14,10 @@ class Kohana_Text {
// take array with (at least) LastName & FirstName keys
public static function abbreviateName($personInfo) {
if (is_string($personInfo))
return $personInfo;
if (is_string($personInfo)) {
list($last, $first, $second) = explode(' ', $personInfo);
$personInfo = ['LastName' => $last, 'FirstName' => $first, 'SecondName' => $second];
}
$fullName = $personInfo['LastName'] . ' ' . UTF8::substr($personInfo['FirstName'], 0, 1) . '. ';
if (!empty($personInfo['SecondName'])) {
......
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