Newer
Older
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Teacher_Rating extends Controller_Environment_Teacher
// make it possible to download files
Cookie::set('fD', 'true');
Антон Шалимов
committed
// Получить из кука SGID выбранную ранее группу для данной дисциплины
private function getFilterGroupID($disciplineID) {
$groups = json_decode(Cookie::get('SGID', null), true);
if ($groups && isset($groups[$disciplineID])) {
return $groups[$disciplineID];
// Шапка таблицы: структура УКД (модули и мероприятия)
private function getStructure($id, $type) {
$structure = Model_Map::getRoadmap($id, $type);
if ($structure->count() == 0) {
throw HTTP_Exception::factory(404, "Страница не найдена");
$maxRate = $i = 0;
$temp_moduleID = -1;
$try = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
foreach ($structure as $row) {
if ($row['ModuleID'] != $temp_moduleID) {
Антон Шалимов
committed
$temp_moduleID = $row['ModuleID'];
$structureHandled[$i]['SubmodulesCount'] = 0;
$structureHandled[$i]['MaxRate'] = 0;
$structureHandled[$i]['ModuleTitle'] = $row['ModuleName'];
$structureHandled[$i]['ModuleType'] = $row['ModuleType'];
$j = $structureHandled[$i]['SubmodulesCount'] += 1;
$structureHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
$cur_submodule['MaxRate'] = (int) $cur_submodule['MaxRate'];
if ($type == "rate") {
$maxRate += $row['MaxRate'];
} else { //$type == "exam"
if ($row['ModuleType'] == 'extra') {
$cur_submodule['Title'] = 'Добор баллов';
$maxRate += $row['MaxRate'];
if ($try === 0) {
$cur_submodule['Title'] = 'Основная сдача';
} else {
$cur_submodule['Title'] = 'Пересдача ' . $try;
}
$try++;
}
$structureHandled['MaxRate'] = (int) $maxRate;
return $structureHandled;
}
private function processGroupInfo($groupInfo) {
//GroupID, GroupNum, GradeNum, isAttached etc.
$out = $groupInfo;
//Формирование заголовка курса
$gradeNum = $groupInfo['GradeNum'];
if ($groupInfo['Degree'] == 'bachelor') {
if ($groupInfo['Degree'] == 'master') {
$out['GradeTitle'] = 'Магистратура, ' . $gradeNum . ' год';
}
$out['GroupTitle'] = $out['GradeTitle'] . " " . $groupInfo['GroupNum'] . " группа";
private function getRatesForRatingPage($info) {
foreach ($info as $row) {
++$i_r;
$cur_rate = [];
$rateResult += $cur_rate['Rate'] = $row['Rate'];
$moduleType = $row['ModuleType'];
$cur_rate['Type'] = $moduleType;
if ($moduleType == 'exam') {
$cur_rate['SubmoduleID'] = -1;
} else if ($moduleType == 'extra') {
$cur_rate['SubmoduleID'] = -2;
} else {
$cur_rate['SubmoduleID'] = $row['SubmoduleID'];
Антон Шалимов
committed
}
$rates['RateResult'] = $rateResult;
return $rates;
}
private function correctExtra(&$curStudent, $examType, $lastExtraIndex, $firstEmptyExtraIndex, $totalExtraRate) {
if ($curStudent['RateSemesterResult'] >= $bottomLimit &&
$curStudent['RateSemesterResult'] < $topLimit
) // студент задолженик
$maxExtraRate = $topLimit - $curStudent['RateSemesterResult'];
if ($lastExtraIndex >= 0) {
$curStudent['Rates'][$lastExtraIndex]['MaxRate'] = $maxExtraRate - $totalExtraRate
+ $curStudent['Rates'][$lastExtraIndex]['Rate'];
if ($firstEmptyExtraIndex >= 0) {
$curStudent['Rates'][$firstEmptyExtraIndex]['MaxRate'] = $maxExtraRate - $totalExtraRate;
}
private function getRatesForExamPage(&$curStudent, $rate, $examType, $disciplineID) {
$rowIndex = 0;
$lastExam = $lastExtraIndex = $lastNilExam = $firstEmptyExtra = -1;
$rateExtra = 0;
Антон Шалимов
committed
Антон Шалимов
committed
if (($curRate['ModuleType'] == 'exam') or ($curRate['ModuleType'] == 'extra')) {
$curStudent['Rates'][$rowIndex] = [
'SubmoduleID' => $curRate['SubmoduleID'],
'Rate' => $curRate['Rate'],
'ModuleType' => $curRate['ModuleType'],
'ExamPeriodOption' => $curRate['ExamPeriodOption'],
];
Антон Шалимов
committed
}
$rate = $curRate['Rate'];
switch ($curRate['ModuleType']) {
case 'regular':
$curStudent['RateSemesterResult'] += $rate;
if ($lastExam >= 0) {
$curStudent['Rates'][$lastExam]['Block'] = 'True';
}
$lastExam = $rowIndex;
if ($lastNilExam < 0) {
$lastNilExam = $rowIndex;
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
}
case 'extra':
if ($rate) {
if ($lastExtraIndex >= 0) {
$curStudent['Rates'][$lastExtraIndex]['Block'] = 'True';
}
$lastExtraIndex = $rowIndex;
$curStudent['Rate'] += $curRate['Rate'];
$rateExtra += $curRate['Rate'];
if ($firstEmptyExtra < 0) {
$firstEmptyExtra = $rowIndex;
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
}
break;
default:
throw HTTP_Exception::factory(500, "Некорректный тип модуля!");
}
// $total = Model_Rating->GetStudentRate($curStudent['ID'], $disciplineID);
// $total = ($total[0])?$total[0]['Num']:0;
// if ($total)
// $total = 0;
$curStudent['RateResult'] = $curStudent['RateSemesterResult'] + $rateExtra;
if ($lastExam >= 0) {
$curStudent['RateResult'] += $curStudent['Rates'][$lastExam]['Rate'];
}
$this->correctExtra($curStudent, $examType, $lastExtraIndex, $firstEmptyExtra, $rateExtra);
$pageType = $this->request->param('type'); // 'rate', 'exam'
$discipline['GroupID_Filter'] = $this->getFilterGroupID($id);
$discipline['LocalizedExamType'] = RusLang::tr($discipline->Type);
$rateHandled = [];
$groupsHandled = [];
$groupInd = $studentInd = $curGroupID = 0;
foreach ($students as $row) {
if ($curGroupID !== $row['GroupID']) {
$curGroupID = $row['GroupID'];
$groupInd++;
$studentInd = 0;
$rateHandled[$groupInd] = $this->processGroupInfo($row);
$groupsHandled[$curGroupID] = $rateHandled[$groupInd]['GroupTitle'];
// Студенты
$curStudent = $row; //ID, Name, isAttached
$rates = $this->getRatesForRatingPage($rates_raw);
$curStudent['RateResult'] = $rates['RateResult'];
unset($rates['RateResult']);
$curStudent['Rates'] = $rates;
$rateHandled[$groupInd]['Students'][$studentInd] = $curStudent;
$this->getRatesForExamPage($curStudent, $rate, $discipline->Type, $id);
$rateHandled[$groupInd]['Students'][$studentInd] = $curStudent;
$twigType = ($pageType == 'rate') ? 'rating' : $pageType;
'groups' => $groupsHandled,
'rateTable' => $rateHandled,
'headerRate' => $this->getStructure($id, $pageType),
'Discipline' => $discipline,
'Discipline_JSON' => json_encode($discipline),