Newer
Older
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Teacher_Rating extends Controller_UserEnvi {
Антон Шалимов
committed
Cookie::set('fD', 'true'); // Ставим кук fD, чтоб иметь возможность скачать отчет TODO
$this->model_rating = new Model_Teacher_Rating;
$this->model_discipline = new Model_Teacher_Map;
Антон Шалимов
committed
// Получить из кука SGID выбранную ранее группу для данной дисциплины
Антон Шалимов
committed
$SG_array = json_decode(Cookie::get('SGID', null), true);
if ($SG_array !== null && array_key_exists($id, $SG_array)) {
Антон Шалимов
committed
return $SG_array[$id];
Антон Шалимов
committed
// Настройки дисциплины и выбранная группа(для фильтра)
private function getDisciplineInformation($id) {
Антон Шалимов
committed
$temp = $this->model_discipline->getDisciplineInfoByID($id);
Антон Шалимов
committed
$disciplineInfo['ID'] = $id;
$disciplineInfo['StudyGroupID_Filter'] = $this->getStudyGroupID_ForFilter($id);
Антон Шалимов
committed
return $disciplineInfo;
}
// Шапка таблицы: структура УКД (модули и мероприятия)
private function getStructure($id, $type)
$teacherID = $this->UserInfo['TeacherID'];
if ($type == "rating") {
$structure = $this->model_rating->getMapForDiscipline($teacherID, $id);
} else {
$structure = $this->model_rating->GetMapForDisciplineExam($teacherID, $id);
}
if($structure->count() == 0) {
throw HTTP_Exception::factory (404, "Страница не найдена");
}
$structureHandled = array();
$maxRate = $i = 0;
$temp_moduleID = -1;
$try = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
Антон Шалимов
committed
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 = array();
$cur_submodule = $row;
$cur_submodule['MaxRate'] = (int)$cur_submodule['MaxRate'];
if ($type == "rating") {
$maxRate += $row['MaxRate'];
} else { //$type == "exam"
if ($row['ModuleType'] == 'extra') {
$cur_submodule['Title'] = 'Добор баллов';
$maxRate += $row['MaxRate'];
}
else {
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') {
$out['GradeTitle'] = $gradeNum.' курс';
} else if ($groupInfo['Degree'] == 'specialist') {
$out['GradeTitle'] = $gradeNum.' курс';
} if ($groupInfo['Degree'] == 'master') {
$out['GradeTitle'] = 'Магистратура, '.$gradeNum.' год';
}
//Формирование заголовка группы
$out['GroupTitle'] = $out['GradeTitle']." ".$groupInfo['GroupNum']." группа";
return $out;
}
private function getRatesForRatingPage($info)
{
$rates = array();
$i_r = 0;
$rateResult = 0;
foreach($info as $row) {
++$i_r;
$cur_rate = array();
$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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
$rates[$i_r] = $cur_rate;
}
$rates['RateResult'] = $rateResult;
return $rates;
}
private function correctExtra(&$curStudent, $examType, $lastExtra, $nextExtra) {
$bottomLimit = 0;
$max_extra_rate = 0;
$topLimit = ($examType == 'exam') ? 38 : 60;
if ($curStudent['RateSemesterResult'] >= $bottomLimit &&
$curStudent['RateSemesterResult'] < $topLimit) // студент задолженик
{
$max_extra_rate = $topLimit - $curStudent['RateSemesterResult'];
}
if ($lastExtra >= 0) {
$curStudent['Rates'][$lastExtra]['MaxRate'] = $max_extra_rate;
}
if ($nextExtra >= 0) {
$curStudent['Rates'][$nextExtra]['MaxRate'] = $max_extra_rate;
}
}
private function getRatesForExamPage(&$curStudent, $rate, $examType, $disciplineID)
{
$i_r = 0;
$lastExam = $lastExtra = $lastNilExam = $lastNilExtra = -1;
Антон Шалимов
committed
$curStudent['RateSemesterResult'] = 0;
foreach($rate as $r) {
Антон Шалимов
committed
if (($r['ModuleType'] == 'exam') or ($r['ModuleType'] == 'extra')) {
$curStudent['Rates'][$i_r] = array();
Антон Шалимов
committed
$curStudent['Rates'][$i_r]['SubmoduleID'] = $r['SubmoduleID'];
$curStudent['Rates'][$i_r]['Rate'] = $r['Rate'];
$curStudent['Rates'][$i_r]['ModuleType'] = $r['ModuleType'];
Антон Шалимов
committed
}
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
switch ($r['ModuleType'])
{
case 'regular':
$curStudent['RateSemesterResult'] += $r['Rate'];
break;
case 'exam':
if (!is_null($r['Rate'])) {
if ($lastExam >= 0) {
$curStudent['Rates'][$lastExam]['Block'] = 'True';
}
$lastExam = $i_r;
} else {
if ($lastNilExam < 0) {
$lastNilExam = $i_r;
} else {
$curStudent['Rates'][$i_r]['Block'] = 'True';
}
}
break;
case 'bonus':
$curStudent['Bonus'] = $r['Rate'];
break;
case 'extra':
if (!is_null($r['Rate'])) {
if ($lastExtra >= 0) {
$curStudent['Rates'][$lastExtra]['Block'] = 'True';
}
$lastExtra = $i_r;
$curStudent['Rate'] += $r['Rate'];
} else {
if ($lastNilExtra < 0) {
$lastNilExtra = $i_r;
} else {
$curStudent['Rates'][$i_r]['Block'] = 'True';
}
}
break;
default:
throw HTTP_Exception::factory (500, "Некорректный тип модуля!");
}
$total = $this->model_rating->GetStudentRate($curStudent['ID'], $disciplineID);
$total = $total[0]['Num'];
if (is_null($total)) $total = 0;
if ($lastExam >= 0) {
$curStudent['RateResult'] += $curStudent['Rates'][$lastExam]['Rate'];
}
$curStudent['RateResult'] = $total;
$this->correctExtra($curStudent, $examType, $lastExtra, $lastNilExtra);
protected function stub_action($page_type) //$page_type: rating, exam
$twig = Twig::factory("teacher/".$page_type); //TODO: validate twig
$disciplineInfo = $this->getDisciplineInformation($id);
$structureHandled = $this->getStructure($id, $page_type);
Антон Шалимов
committed
$students = $this->model_rating->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
if ($curGroup !== $row['GroupID']) {
$curGroup = $row['GroupID'];
$rateHandled[$i_g] = $this->processGroupInfo($row);
$groupsHandled[$curGroup] = $rateHandled[$i_g]['GroupTitle'];
// Студенты
$curStudent = $row; //ID, Name, isAttached
if ($page_type == "rating") {
$rates_raw = $this->model_rating->getMapForStudent($row['ID'], $id);
$rates = $this->getRatesForRatingPage($rates_raw);
$curStudent['RateResult'] = $rates['RateResult'];
unset($rates['RateResult']);
$curStudent['Rates'] = $rates;
$rateHandled[$i_g]['Students'][$i_s] = $curStudent;
} else {
$rate = $this->model_rating->getMapForStudentExam($row['ID'], $id);
$this->getRatesForExamPage($curStudent, $rate, $disciplineInfo['ExamType'], $id);
$rateHandled[$i_g]['Students'][$i_s] = $curStudent;
Антон Шалимов
committed
// На вывод
$twig->User = $this->UserInfo;
$twig->headerRate = $structureHandled; // Шапка таблицы: структура УКД (модули и мероприятия)
$twig->rateTable = $rateHandled;
$twig->groups = $groupsHandled;
Антон Шалимов
committed
$twig->disciplineInfo_JSON = json_encode($twig->disciplineInfo);
}
// Страница оценивания в течение семестра
public function action_edit() {
$this->stub_action("rating");
}
// Страница оценивания в сессию
public function action_exam() {
$this->stub_action("exam");