Skip to content
Snippets Groups Projects
Commit 8848a23a authored by PavelBegunkov's avatar PavelBegunkov
Browse files

php rating refactoring

parent 72375be2
No related merge requests found
......@@ -869,10 +869,9 @@ END //
# get all disciplines, that student take.
DROP PROCEDURE IF EXISTS GetDisciplinesForStudent//
CREATE PROCEDURE `GetDisciplinesForStudent` (
IN `pStudentID` INT,
IN `pSemesterID` INT
)
NO SQL
IN `pStudentID` INT,
IN `pSemesterID` INT
) NO SQL
BEGIN
DECLARE vStudentGroup INT DEFAULT -1;
SET vStudentGroup = GetStudentGroup(pStudentID, pSemesterID);
......@@ -1180,10 +1179,11 @@ END //
# -------------------------------------------------------------------------------------------
# Label: disciplines
# Label: roadMaps
# Label: roadmaps
# -------------------------------------------------------------------------------------------
# TODO: order hardcode
# TODO: merge with GetRoadmapExam
# get roadmap of discipline
DROP PROCEDURE IF EXISTS GetRoadmap//
CREATE PROCEDURE `GetRoadmap`
......@@ -1237,34 +1237,6 @@ END //
# -------------------------------------------------------------------------------------------
# Label: requests
# -------------------------------------------------------------------------------------------
# DROP PROCEDURE IF EXISTS GetRequests
# CREATE PROCEDURE `GetRequests` ( IN `AccountID` INT,
# IN `Type` INT # 0 to me, 1 - from me, 3 - all
# )
# NO SQL
# BEGIN
# SELECT requests.ID,
# requests.To,
# requests.From,
# requests.Field1,
# requests.Field2,
# requests.Field3,
# requests.Data,
# requests.DataExt,
# requests.Date,
# requests.Type,
# requests.Status
# FROM `requests`
# WHERE ((Type & 1) != 0 AND requests.To = AccountID) OR
# ((Type & 2) != 0 AND requests.From = AccountID)
# ORDER BY requests.To = AccountID DESC, requests.Type ASC, requests.ID ASC;
# END
# -------------------------------------------------------------------------------------------
# Label: recovery
......@@ -1307,6 +1279,10 @@ END //
# -------------------------------------------------------------------------------------------
# Label: miscellaneous
# -------------------------------------------------------------------------------------------
DROP PROCEDURE IF EXISTS GetFinalFormInfo//
CREATE PROCEDURE `GetFinalFormInfo` (
IN `pDisciplineID` INT,
......
......@@ -271,11 +271,11 @@ Route::set('discipline:edit', 'discipline/<id>((/)<section>)', ['id' => '\d+'])
'section' => 'structure',
]);
Route::set('teacher:rating', 'rate/<id>', array('id' => '[0-9]+'))
Route::set('teacher:rating', '<type>/<id>', ['type' => '(rate|exam)', 'id' => '[0-9]+'])
->defaults(array(
'directory' => 'teacher',
'controller' => 'rating',
'action' => 'edit'
'action' => 'rate'
));
Route::set('teacher:exam', 'exam/<id>', array('id' => '[0-9]+'))
->defaults(array(
......
......@@ -9,33 +9,31 @@ class Controller_Teacher_Rating extends Controller_Environment_Teacher
}
// Получить из кука SGID выбранную ранее группу для данной дисциплины
private function getGroupID_ForFilter($id) {
# $id = disciplineID
$SG_array = json_decode(Cookie::get('SGID', null), true);
if ($SG_array !== null && array_key_exists($id, $SG_array)) {
return $SG_array[$id];
private function getFilterGroupID($disciplineID) {
$groups = json_decode(Cookie::get('SGID', null), true);
if ($groups && isset($groups[$disciplineID])) {
return $groups[$disciplineID];
}
return 0;
}
// Шапка таблицы: структура УКД (модули и мероприятия)
private function getStructure($id, $type) {
$structure = ($type == "rating")
$structure = ($type == "rate")
? Model_Rating::getMapForDiscipline($id)
: Model_Rating::getMapForDisciplineExam($id);
if($structure->count() == 0) {
throw HTTP_Exception::factory (404, "Страница не найдена");
if ($structure->count() == 0) {
throw HTTP_Exception::factory(404, "Страница не найдена");
}
$structureHandled = [];
$maxRate = $i = 0;
$temp_moduleID = -1;
$try = 0; // try = 1 - экзамен, = 2, 3 - пересдачи
foreach($structure as $row) {
if($row['ModuleID'] != $temp_moduleID)
{
foreach ($structure as $row) {
if ($row['ModuleID'] != $temp_moduleID) {
++$i; // todo
$temp_moduleID = $row['ModuleID'];
$structureHandled[$i]['SubmodulesCount'] = 0;
......@@ -48,17 +46,16 @@ class Controller_Teacher_Rating extends Controller_Environment_Teacher
$structureHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
$cur_submodule = $row;
$cur_submodule['MaxRate'] = (int)$cur_submodule['MaxRate'];
if ($type == "rating") {
$cur_submodule['MaxRate'] = (int) $cur_submodule['MaxRate'];
if ($type == "rate") {
$cur_submodule['Title'] = $row['SubmoduleName'];
$maxRate += $row['MaxRate'];
} else { //$type == "exam"
if ($row['ModuleType'] == 'extra') {
$cur_submodule['Title'] = 'Добор баллов';
$maxRate += $row['MaxRate'];
}
else {
} else {
if ($try === 0) {
$cur_submodule['Title'] = 'Основная сдача';
} else {
......@@ -73,35 +70,36 @@ class Controller_Teacher_Rating extends Controller_Environment_Teacher
$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.' курс';
$out['GradeTitle'] = $gradeNum . ' курс';
} else if ($groupInfo['Degree'] == 'specialist') {
$out['GradeTitle'] = $gradeNum.' курс';
} if ($groupInfo['Degree'] == 'master') {
$out['GradeTitle'] = 'Магистратура, '.$gradeNum.' год';
$out['GradeTitle'] = $gradeNum . ' курс';
}
if ($groupInfo['Degree'] == 'master') {
$out['GradeTitle'] = 'Магистратура, ' . $gradeNum . ' год';
}
//Формирование заголовка группы
$out['GroupTitle'] = $out['GradeTitle']." ".$groupInfo['GroupNum']." группа";
$out['GroupTitle'] = $out['GradeTitle'] . " " . $groupInfo['GroupNum'] . " группа";
return $out;
}
private function getRatesForRatingPage($info) {
$rates = array();
$rates = [];
$i_r = 0;
$rateResult = 0;
foreach($info as $row) {
++$i_r;
$cur_rate = array();
foreach ($info as $row) {
++$i_r;
$cur_rate = [];
$rateResult += $cur_rate['Rate'] = $row['Rate'];
$moduleType = $row['ModuleType'];
$cur_rate['Type'] = $moduleType;
......@@ -114,91 +112,94 @@ class Controller_Teacher_Rating extends Controller_Environment_Teacher
}
$rates[$i_r] = $cur_rate;
}
$rates['RateResult'] = $rateResult;
return $rates;
}
private function correctExtra(&$curStudent, $examType, $lastExtraIndex, $firstEmptyExtraIndex, $totalExtraRate) {
$bottomLimit = 0;
$maxExtraRate = 0;
$topLimit = ($examType == 'exam') ? 38 : 60;
if ($curStudent['RateSemesterResult'] >= $bottomLimit &&
$curStudent['RateSemesterResult'] < $topLimit) // студент задолженик
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;
$curStudent['RateSemesterResult'] = 0;
foreach($rate as $curRate) {
foreach ($rate as $curRate) {
if (($curRate['ModuleType'] == 'exam') or ($curRate['ModuleType'] == 'extra')) {
$curStudent['Rates'][$rowIndex] = array();
$curStudent['Rates'][$rowIndex]['SubmoduleID'] = $curRate['SubmoduleID'];
$curStudent['Rates'][$rowIndex]['Rate'] = $curRate['Rate'];
$curStudent['Rates'][$rowIndex]['ModuleType'] = $curRate['ModuleType'];
$curStudent['Rates'][$rowIndex]['ExamPeriodOption'] = $curRate['ExamPeriodOption'];
$curStudent['Rates'][$rowIndex] = [
'SubmoduleID' => $curRate['SubmoduleID'],
'Rate' => $curRate['Rate'],
'ModuleType' => $curRate['ModuleType'],
'ExamPeriodOption' => $curRate['ExamPeriodOption'],
];
}
switch ($curRate['ModuleType'])
{
case 'regular':
$curStudent['RateSemesterResult'] += $curRate['Rate'];
$rate = $curRate['Rate'];
switch ($curRate['ModuleType']) {
case 'regular':
$curStudent['RateSemesterResult'] += $rate;
break;
case 'exam':
if (!is_null($curRate['Rate'])) {
case 'exam':
if (!is_null($rate)) {
if ($lastExam >= 0) {
$curStudent['Rates'][$lastExam]['Block'] = 'True';
}
$lastExam = $rowIndex;
} else {
if ($lastNilExam < 0) {
$lastNilExam = $rowIndex;
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
}
if ($lastNilExam < 0) {
$lastNilExam = $rowIndex;
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
}
}
break;
case 'bonus':
$curStudent['Bonus'] = $curRate['Rate'];
case 'bonus':
$curStudent['Bonus'] = $rate;
break;
case 'extra':
if ($curRate['Rate']) {
if ($lastExtraIndex >= 0) {
$curStudent['Rates'][$lastExtraIndex]['Block'] = 'True';
}
$lastExtraIndex = $rowIndex;
$curStudent['Rate'] += $curRate['Rate'];
$rateExtra += $curRate['Rate'];
} else {
if ($firstEmptyExtra < 0) {
$firstEmptyExtra = $rowIndex;
case 'extra':
if ($rate) {
if ($lastExtraIndex >= 0) {
$curStudent['Rates'][$lastExtraIndex]['Block'] = 'True';
}
$lastExtraIndex = $rowIndex;
$curStudent['Rate'] += $curRate['Rate'];
$rateExtra += $curRate['Rate'];
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
if ($firstEmptyExtra < 0) {
$firstEmptyExtra = $rowIndex;
} else {
$curStudent['Rates'][$rowIndex]['Block'] = 'True';
}
}
}
break;
default:
throw HTTP_Exception::factory (500, "Некорректный тип модуля!");
break;
default:
throw HTTP_Exception::factory(500, "Некорректный тип модуля!");
}
$rowIndex++;
}
// $total = Model_Rating->GetStudentRate($curStudent['ID'], $disciplineID);
// $total = ($total[0])?$total[0]['Num']:0;
// if ($total)
......@@ -212,81 +213,65 @@ class Controller_Teacher_Rating extends Controller_Environment_Teacher
}
/**
* @param $page_type: rating, exam
* @param $page_type : rating, exam
* @throws HTTP_Exception
*/
protected function stub_action($page_type) {
if ($page_type != 'exam' && $page_type != 'rating')
throw new RuntimeException('invalid $page_type param');
protected function action_rate() {
$id = $this->request->param('id');
$pageType = $this->request->param('type');
$discipline = Model_Discipline::load($id);
$discipline['GroupID_Filter'] = $this->getGroupID_ForFilter($id);
$discipline['LocalizedExamType'] = RusLang::tr($discipline->Type);
$discipline['GroupID_Filter'] = $this->getFilterGroupID($id);
$discipline['LocalizedExamType'] = RusLang::tr($discipline->Type);
// Студенты и их баллы
$students = Model_Rating::GetStudentsForRating($id);
$rateHandled = array();
$groupsHandled = array();
$i_g = $i_s = $curGroup = 0;
foreach($students as $row) {
if ($curGroup !== $row['GroupID']) {
$curGroup = $row['GroupID'];
$i_g++;
$i_s = 0;
$rateHandled[$i_g] = $this->processGroupInfo($row);
$groupsHandled[$curGroup] = $rateHandled[$i_g]['GroupTitle'];
$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
$curStudent['RateResult'] = 0;
// Баллы студента
if ($page_type == "rating") {
if ($pageType == 'rate') {
$rates_raw = Model_Rating::getRates($id, $row['ID']);
$rates = $this->getRatesForRatingPage($rates_raw);
$curStudent['RateResult'] = $rates['RateResult'];
unset($rates['RateResult']);
$curStudent['Rates'] = $rates;
$rateHandled[$i_g]['Students'][$i_s] = $curStudent;
$rateHandled[$groupInd]['Students'][$studentInd] = $curStudent;
} else {
$rate = Model_Rating::getExamRates($id, $row['ID']);
$this->getRatesForExamPage($curStudent, $rate, $discipline->Type, $id);
$rateHandled[$i_g]['Students'][$i_s] = $curStudent;
$rateHandled[$groupInd]['Students'][$studentInd] = $curStudent;
}
$i_s++;
$studentInd++;
}
$editRights = Model_Teacher::with($this->user->TeacherID)
->getRightsForDiscipline($discipline);
$twigType = ($pageType == 'rate') ? 'rating' : $pageType;
// Шапка таблицы: структура УКД (модули и мероприятия)
$this->twig->set([
'groups' => $groupsHandled,
'rateTable' => $rateHandled,
'headerRate' => $this->getStructure($id, $page_type),
'editRights' => (1 == $editRights),
'groups' => $groupsHandled,
'rateTable' => $rateHandled,
'headerRate' => $this->getStructure($id, $pageType),
'Discipline' => $discipline,
'Discipline_JSON' => json_encode($discipline),
])->set_filename("teacher/" . $page_type);
])->set_filename("teacher/" . $twigType);
}
// Страница оценивания в течение семестра
public function action_edit() {
$this->stub_action("rating");
}
// Страница оценивания в сессию
public function action_exam() {
$this->stub_action("exam");
}
}
\ No newline at end of file
......@@ -160,4 +160,4 @@
{{ discipline_JSON|raw }}
</div>
<input type="hidden" id="pageType" value="rating"/>
{% endblock %}
\ No newline at end of file
{% endblock %}
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