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 = $try = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
$lastModuleID = -1;
foreach ( $structure as $row ) {
if ( $row['ModuleID'] != $lastModuleID ) {
$lastModuleID = $row['ModuleID'];
$structureHandled[++$i] = [
'SubmodulesCount' => 0,
'MaxRate' => 0,
'ModuleTitle' => $row['ModuleName'],
'ModuleType' => $row['ModuleType'],
];
$j = $structureHandled[$i]['SubmodulesCount'] += 1;
$structureHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
$structureHandled[$i][$j] = $row;
$curSubmodule = &$structureHandled[$i][$j];
$curSubmodule['MaxRate'] = (int) $curSubmodule['MaxRate'];
$maxRate += $row['MaxRate'];
} else { //$type == "exam"
if ($row['ModuleType'] == 'extra') {
$structureHandled['MaxRate'] = (int) $maxRate;
return $structureHandled;
}
private function processGroupInfo($groupInfo) {
//GroupID, GroupNum, GradeNum, isAttached etc.
$out = $groupInfo;
//Формирование заголовка курса
$gradeNum = $groupInfo['GradeNum'];
if ( $degree == 'bachelor' || $degree == 'specialist' )
{
$out['GradeTitle'] = 'Магистратура, ' . $gradeNum . ' год';
}
$out['GroupTitle'] = $out['GradeTitle'] . " " . $groupInfo['GroupNum'] . " группа";
private function getRatesForRatingPage($info, &$rateResult) {
Антон Шалимов
committed
switch ( $moduleType ) {
case 'exam':
$submoduleID = -1;
break;
case 'extra':
$submoduleID = -2;
break;
default:
$submoduleID = $row['SubmoduleID'];
}
$rates[] = [
'Type' => $moduleType,
'SubmoduleID' => $submoduleID,
'Rate' => $row['Rate'],
];
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'];
$rateHandled[$groupInd]['Students'][$studentInd] = $row;
$curStudent = &$rateHandled[$groupInd]['Students'][$studentInd++]; //ID, Name, isAttached
$curStudent['Rates'] = $this->getRatesForRatingPage($rates_raw, $curStudent['RateResult']);
$this->getRatesForExamPage($curStudent, $rate, $discipline->Type, $id);
$twigType = ($pageType == 'rate') ? 'rating' : $pageType;
'groups' => $groupsHandled,
'rateTable' => $rateHandled,
'headerRate' => $this->getStructure($id, $pageType),
'Discipline' => $discipline,
'Discipline_JSON' => json_encode($discipline),