Skip to content
Snippets Groups Projects
Commit 770b1db6 authored by Anton's avatar Anton
Browse files

fix rating

parent 835d3c45
Branches
Tags
No related merge requests found
...@@ -10,6 +10,7 @@ class Controller_Handler_Rating extends Controller_Handler { ...@@ -10,6 +10,7 @@ class Controller_Handler_Rating extends Controller_Handler {
public function action_setRate() public function action_setRate()
{ {
$data['success'] = false;
$this->post -> rule('student', 'not_empty') $this->post -> rule('student', 'not_empty')
-> rule('student', 'digit') -> rule('student', 'digit')
-> rule('submodule', 'not_empty') -> rule('submodule', 'not_empty')
...@@ -17,15 +18,17 @@ class Controller_Handler_Rating extends Controller_Handler { ...@@ -17,15 +18,17 @@ class Controller_Handler_Rating extends Controller_Handler {
-> rule('rate', 'digit') -> rule('rate', 'digit')
-> rule('rate', 'range', array(':value', 0, 100)); -> rule('rate', 'range', array(':value', 0, 100));
if($this->post->check()) { if($this->post->check()) {
$this->model->setRate($this->user['TeacherID'], $this->post->offsetGet('student'), $this->post->offsetGet('submodule'), $this->post->offsetGet('rate')); $result = $this->model->setRate($this->user['TeacherID'], $this->post->offsetGet('student'), $this->post->offsetGet('submodule'), $this->post->offsetGet('rate'));
$this->response->body(json_encode('Ok, setRate!')); var_dump($this->post);
if ($result[0]['Num'] == 0)
$data['success'] = true;
} }
else $this->response->body(json_encode($data));
$this->response->body(json_encode('Error, setRate'));
} }
public function action_changeRate() public function action_changeRate()
{ {
$data['success'] = false;
$this->post -> rule('student', 'not_empty') $this->post -> rule('student', 'not_empty')
-> rule('student', 'digit') -> rule('student', 'digit')
-> rule('submodule', 'not_empty') -> rule('submodule', 'not_empty')
...@@ -33,11 +36,11 @@ class Controller_Handler_Rating extends Controller_Handler { ...@@ -33,11 +36,11 @@ class Controller_Handler_Rating extends Controller_Handler {
-> rule('rate', 'digit') -> rule('rate', 'digit')
-> rule('rate', 'range', array(':value', 0, 100)); -> rule('rate', 'range', array(':value', 0, 100));
if($this->post->check()) { if($this->post->check()) {
$this->model->changeRate($this->user['TeacherID'], $this->post->offsetGet('student'), $this->post->offsetGet('submodule'), $this->post->offsetGet('rate')); $result = $this->model->changeRate($this->user['TeacherID'], $this->post->offsetGet('student'), $this->post->offsetGet('submodule'), $this->post->offsetGet('rate'));
$this->response->body(json_encode('Ok, changeRate!')); if ($result[0]['Num'] == 0)
$data['success'] = true;
} }
else $this->response->body(json_encode($data));
$this->response->body(json_encode('Error, changeRate'));
} }
} }
\ No newline at end of file
...@@ -47,52 +47,28 @@ class Controller_Teacher_Rating extends Controller_UserEnvi { ...@@ -47,52 +47,28 @@ class Controller_Teacher_Rating extends Controller_UserEnvi {
$twig->headerRate = $disciplineHandled; $twig->headerRate = $disciplineHandled;
// Студенты и баллы // Студенты и баллы
$students = $db->GetStudentsForDiscipline($this->UserInfo['TeacherID'], $id); $students = $db->GetStudentsForRating($this->UserInfo['TeacherID'], $id);
$studentsHandled = array(); $studentsHandled = array();
$i = 0; $MigrantsCount = 0; $i = 0;
foreach($students as $row) { foreach($students as $row) {
if ($row['isAttached'] == '0') { $i++;
// Не Мигранты $studentsHandled[$i]['StudentID'] = $row['StudentID'];
$i++; $studentsHandled[$i]['LastName'] = $row['LastName'];
$studentsHandled[$i]['StudentID'] = $row['StudentID']; $studentsHandled[$i]['FirstName'] = $row['FirstName'];
$studentsHandled[$i]['LastName'] = $row['StudentLast']; $studentsHandled[$i]['SecondName'] = $row['SecondName'];
$studentsHandled[$i]['FirstName'] = $row['StudentFirst']; $studentsHandled[$i]['Grade'] = $row['Grade'];
$studentsHandled[$i]['SecondName'] = $row['StudentSecond']; $studentsHandled[$i]['GroupNum'] = $row['GroupNum'];
$studentsHandled[$i]['Grade'] = $row['Grade']; $rate = $db->getMapForStudent($row['StudentID'], $id);
$studentsHandled[$i]['GroupNum'] = $row['GroupNum']; $j = 0;
$rate = $db->getMapForStudent($row['StudentID'], $id); foreach($rate as $r) {
$j = 0; $j += 1;
foreach($rate as $r) { $studentsHandled[$i][$j]['SubmoduleID'] = $r['SubmoduleID'];
$j += 1; $studentsHandled[$i][$j]['Rate'] = $r['Rate'];
$studentsHandled[$i][$j]['SubmoduleID'] = $r['SubmoduleID'];
$studentsHandled[$i][$j]['Rate'] = $r['Rate'];
}
$studentsHandled[$i]['RateCount'] = $j;
}
else {
// Мигранты
$MigrantsCount++;
$MigrantsHandled[$MigrantsCount]['StudentID'] = $row['StudentID'];
$MigrantsHandled[$MigrantsCount]['StudentID'] = $row['StudentID'];
$MigrantsHandled[$MigrantsCount]['LastName'] = $row['StudentLast'];
$MigrantsHandled[$MigrantsCount]['FirstName'] = $row['StudentFirst'];
$MigrantsHandled[$MigrantsCount]['SecondName'] = $row['StudentSecond'];
$MigrantsHandled[$MigrantsCount]['Grade'] = $row['Grade'];
$MigrantsHandled[$MigrantsCount]['GroupNum'] = $row['GroupNum'];
$rate = $db->getMapForStudent($row['StudentID'], $id);
$j = 0;
foreach($rate as $r) {
$j += 1;
$MigrantsHandled[$MigrantsCount][$j]['SubmoduleID'] = $r['SubmoduleID'];
$MigrantsHandled[$MigrantsCount][$j]['Rate'] = $r['Rate'];
}
$MigrantsHandled[$MigrantsCount]['RateCount'] = $j;
} }
$studentsHandled[$i]['RateCount'] = $j;
} }
$twig->tableRate = $studentsHandled; $twig->tableRate = $studentsHandled;
if (isset($MigrantsHandled))
$twig->migrantsRate = $MigrantsHandled;
$this->response->body($twig); $this->response->body($twig);
} }
......
...@@ -7,6 +7,12 @@ class Model_Teacher_Rating extends Model ...@@ -7,6 +7,12 @@ class Model_Teacher_Rating extends Model
$sql = "CALL `getStudentsForDiscipline`('$teacherID', '$disciplineID'); "; $sql = "CALL `getStudentsForDiscipline`('$teacherID', '$disciplineID'); ";
return DB::query(Database::SELECT, $sql)->execute(); return DB::query(Database::SELECT, $sql)->execute();
} }
public function GetStudentsForRating($teacherID, $disciplineID)
{
$sql = "CALL `GetStudentsForRating`('$teacherID', '$disciplineID'); ";
return DB::query(Database::SELECT, $sql)->execute();
}
public function getMapForDiscipline($teacherID, $disciplineID) public function getMapForDiscipline($teacherID, $disciplineID)
{ {
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
{% block media %} {# head -> css, js #} {% block media %} {# head -> css, js #}
{{ HTML.script('media/js/functions.js')|raw }} {{ HTML.script('media/js/functions.js')|raw }}
{{ HTML.script('media/js/event_inspector/event_inspector.js')|raw }}
{{ HTML.style('media/js/event_inspector/event_inspector.css')|raw }}
{{ HTML.style('media/css/setRate.css')|raw }} {{ HTML.style('media/css/setRate.css')|raw }}
{{ HTML.script('media/js/setRate.js')|raw }} {{ HTML.script('media/js/setRate.js')|raw }}
{% endblock %} {% endblock %}
...@@ -14,7 +17,7 @@ ...@@ -14,7 +17,7 @@
<p style="font-size: 15px; margin-left: 2.5%">Обратить внимание, что пустая клетка эквивалентна нулю</p> <p style="font-size: 15px; margin-left: 2.5%">Обратить внимание, что пустая клетка эквивалентна нулю</p>
<table class="studentsRate" border="0" cellspacing="0" cellpadding="0"> <table class="studentsRate" border="0" cellspacing="0" cellpadding="0">
<tr> <tr>
<td class="title" width="150px">Модуль/номер</td> <td class="title" width="150px">Модуль</td>
{% for i in 1..headerRate.ModulesCount %} {% for i in 1..headerRate.ModulesCount %}
<td class="subject" colspan="{{headerRate[i].SubmodulesCount}}">{{ headerRate[i].ModuleTitle }}</td> <td class="subject" colspan="{{headerRate[i].SubmodulesCount}}">{{ headerRate[i].ModuleTitle }}</td>
{% endfor %} {% endfor %}
...@@ -46,26 +49,5 @@ ...@@ -46,26 +49,5 @@
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
{% set GroupNum = 0 %}
{% for student in migrantsRate %}
{% if loop.first == 1 %}
<tr>
<td class="group" colspan="{{ CellCount + 1 }}">Мигранты</td>
</tr>
{% endif %}
{% set row = row + 1 %}
{% if student.GroupNum != GroupNum %}
{% set GroupNum = student.GroupNum %}
<tr>
<td class="group" colspan="{{ CellCount + 1 }}">{{ student.GroupNum }} группа</td>
</tr>
{% endif %}
<tr>
<td class="row_{{ row }} student" id="{{ student.StudentID }}">{{ student.LastName }} {{ student.FirstName }}</td>
{% for i in 1..CellCount %}
<td class="row_{{ row }} col_{{ i }} rateCell {% if student[i].Rate > 0 %}edit{% endif %}"><input value="{{ student[i].Rate }}"></td>
{% endfor %}
</tr>
{% endfor %}
</table> </table>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -18,7 +18,7 @@ $(function() { ...@@ -18,7 +18,7 @@ $(function() {
if(data.success === true) { if(data.success === true) {
$('.AddDiscipline').hide(); $('.AddDiscipline').hide();
EventInspector_ShowMsg('Ок, AddDiscipline', 'success'); EventInspector_ShowMsg('Ок, AddDiscipline', 'success');
setTimeout('location.replace("/~dev_rating/map/'+data.DisciplineID+'")',5000); setTimeout('location.replace("/~dev_rating/map/'+data.DisciplineID+'")',1000);
} else EventInspector_ShowMsg('Error, AddDiscipline', 'error'); } else EventInspector_ShowMsg('Error, AddDiscipline', 'error');
} }
); );
......
...@@ -52,20 +52,28 @@ $(function() { ...@@ -52,20 +52,28 @@ $(function() {
if (edit) { if (edit) {
$.post('/~dev_rating/handler/rating/changeRate', {'student': StudentID, 'submodule': SubmoduleID, 'rate': NewRate }, $.post('/~dev_rating/handler/rating/changeRate', {'student': StudentID, 'submodule': SubmoduleID, 'rate': NewRate },
function(data){ function(data){
alert(data); data = $.parseJSON(data);
if(data.success === true)
EventInspector_ShowMsg('Балл изменен', 'success');
else EventInspector_ShowMsg('Не удалось изменить балл', 'error');
} }
); );
} }
else { else {
$.post('/~dev_rating/handler/rating/setRate', {'student': StudentID, 'submodule': SubmoduleID, 'rate': NewRate }, $.post('/~dev_rating/handler/rating/setRate', {'student': StudentID, 'submodule': SubmoduleID, 'rate': NewRate },
function(data){ function(data){
alert(data); data = $.parseJSON(data);
if(data.success === true)
EventInspector_ShowMsg('Балл добавлен', 'success');
else EventInspector_ShowMsg('Не удалось добавить балл', 'error');
} }
); );
} }
} }
else else {
alert('Текущий балл превышает максимальный для данного модуля.'); thisObj.children('input').val('0');
EventInspector_ShowMsg('Текущий балл превышает максимальный для данного модуля', 'error');
}
} }
$('.rateCell').mouseenter(function(){ $('.rateCell').mouseenter(function(){
...@@ -97,6 +105,11 @@ $(function() { ...@@ -97,6 +105,11 @@ $(function() {
tdUnFocus($(this)); tdUnFocus($(this));
}); });
// При нажатие на элемент rateCell дочерный input получает фокус
$('.rateCell ').click(function(){
$(this).children('input').focus();
} );
// В inputCredit (где баллы вводить) разрешаем вводить только цифры // В inputCredit (где баллы вводить) разрешаем вводить только цифры
$('.rateCell').children('input').keydown(function(event) { $('.rateCell').children('input').keydown(function(event) {
KeyDownOnlyNumber(event); KeyDownOnlyNumber(event);
......
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