Skip to content
Snippets Groups Projects
Commit 66ea1260 authored by Korvin's avatar Korvin Committed by Anton Bagliy
Browse files

add students and subgroups list, subgr add button, students attach-detach functions

parent d8b4add1
Branches
No related merge requests found
var $ = jQuery;
$(function() {
let $SubgroupStudentsList = $('.SubgroupStudentsList');
let $StudentsList = $('.StudentList');
if ($('.SelectSubgroup option:selected').attr('value') == '0')
$('.Action_BindStudent').turnOff();
$('.SelectSubgroup').change(function () {
if ($('.SelectSubgroup option:selected').attr('value') != '0')
$('.Action_BindStudent').turnOn();
});
$SubgroupStudentsList.on('click', 'div.hideListAction', function () {
$(this).parent().hide('normal');
$(this).parent().prev().children('.Action').text('Открыть список ▼');
});
$SubgroupStudentsList.on('click', '.ActionShowHideGroupContainer', function () {
let $groupContainer = $(this).next('.GroupContainer');
if ($groupContainer.css('display') == 'none') {
$(this).children('.Action').text('Скрыть список ▲');
$groupContainer.show();
} else {
$(this).children('.Action').text('Открыть список ▼');
$groupContainer.hide('normal');
}
});
$('.addSubgroupBtn').click(function () {
let data = {
"DisciplineID" : $('.HiddenInputDisciplineID').val(),
"TeacherID" : $('.HiddenInputAuthorID').val(),
};
$.postJSON(g_URLdir + 'handler/Subgroup/create/', data).success((data) => {
if (data['success'] === true) {
$(".Subgroup:last").next().after(
'<div class=\"Subgroup GradeAndGroupTitle ActionShowHideGroupContainer\" id=\"' + data["response"]["ID"] + '\">\n' +
' <span class=\"info\">' + 'Подгруппа ' + data["response"]["Title"] + '</span>\n' +
' <span class=\"Action\">Открыть список ▼</span>\n' +
"</div> <div class=\"GroupContainer\">\n" +
" <div class=\"hideListAction\"></div>\n" +
"</div>"
);
$('.SelectSubgroup option:last').after('<option value="'
+ data["response"]["ID"]
+ '"> Подгруппа '
+ data["response"]["Title"]
+ ' </option>');
Popup.success('Подгруппа создана')
} else
Popup.error(data['response'] || 'Ошибка при создании подгруппы');
}).fail(function () {
Popup.error(data['response'] || 'Неизвестная ошибка');
});
});
let unbindStudentHandler = (success) => {
return function() { // need `this`!
$(this).turnOff();
let data = {'StudentID' : +$(this).attr('id'),
'SubgroupID' : +$(this).parent().prev().attr('id')};
$.postJSON(`${g_URLdir}handler/Subgroup/detach_student/`, data, (data) => {
if (data.success === '-1') {
success($(this));
Popup.success('Студент откреплен');
}
else
Popup.error('Ошибка при откреплении студента');
$(this).turnOn();
});
};
};
let bindStudentHandler = (success) => {
return function () { // need `this`!
$(this).turnOff();
$('.SelectSubgroup').turnOff();
let data = {'StudentID' : +$(this).attr('id'),
'SubgroupID' : +$('.SelectSubgroup option:selected').attr('value')};
$.postJSON(`${g_URLdir}handler/Subgroup/attach_student/`, data, (data) => {
if (data.success === '1'){
success($(this));
Popup.success('Студент прикреплен');
}
else
Popup.error('Ошибка при добавлении студента');
$(this).turnOn();
$('.SelectSubgroup').turnOn();
});
};
};
$StudentsList.on('click', '.StatusUnbind', bindStudentHandler(($this) => {
let subgroup = +$('.SelectSubgroup option:selected').attr('value');
let $subgroup = $('.Subgroup#' + subgroup).next('.GroupContainer');
$subgroup.height($subgroup.height() + 42);
$this.detach();
$subgroup.append($this.clone());
let $new = $subgroup.children().last();
$new.removeClass('StatusUnbind').addClass('StatusBind');
$new.children('button').removeClass('Action_BindStudent').addClass('Action_UnbindStudent').html('Отсоединить студента');
}));
$SubgroupStudentsList.on('click', '.StatusBind', unbindStudentHandler(($this) => {
let subgroup = +$('.SelectSubgroup option:selected').attr('value');
let $subgroup = $('.Subgroup#' + subgroup).next('.GroupContainer');
$subgroup.height($subgroup.height() - 42);
$this.detach();
$('.SearchResult.StudentList').append($this.clone());
let $new = $('.StatusBind').last();
$new.removeClass('StatusBind').addClass('StatusUnbind');
$new.children('button').removeClass('Action_UnbindStudent').addClass('Action_BindStudent').html('Прикрепить студента');
}));
});
/*var $ = jQuery;
$(function() {
const DisciplineID = g_disciplineID;
const FacultyID = g_facultyID;
......@@ -13,7 +134,7 @@ $(function() {
let $attStudentList = $('div.AttachedStudentsList');
let $studentsList = $('.StudentsList');
let $generalStudentsList = $('.GeneralStudentsList');
*/
/**
* @param {object} group
......@@ -22,14 +143,14 @@ $(function() {
* @param {int} group.GradeNum
* @returns {string}
*/
let openGroupContainer = (group) => {
/* let openGroupContainer = (group) => {
return `<div class="GroupContainerAttached" id="${group.GroupID}">
<div class='groupInfo'><div class="groupInfoAlone">${group.GradeNum}.${group.GroupNum}</div></div>`;
};
let closeGroupContainer = () => {
return `</div>`;
};
};*/
/**
* @param {object} student
* @param {int} student.ID
......@@ -38,7 +159,7 @@ $(function() {
* @param {string} student.SecondName
* @returns {*}
*/
let constructUnbindStudent = (student) => {
/*let constructUnbindStudent = (student) => {
return `<div id="${student.ID}" class="Student StatusUnbind">
<span class='Name'>${student.LastName} ${student.FirstName} ${student.SecondName}</span>
<span id='0' class='From'></span>
......@@ -216,4 +337,4 @@ $(function() {
$parent.css('height', $parent.height() - 40);
}));
});
});*/
<?php defined('SYSPATH') || die('No direct script access.');
class Controller_Handler_Subgroup extends Controller_Handler
{
private $titles = ['А','Б','В','Г','Д','Е','Ё','Ж','З'];
public function before() {
parent::before();
$this->user->checkAccess(User::RIGHTS_ADMIN | User::RIGHTS_DEAN || User::RIGHTS_TEACHER);
}
public function action_create() {
$disciplineId = $_POST["DisciplineID"];
$teacherId = $_POST["TeacherID"];
$subgroups = Model_Subgroup::getSubgroupsForDiscipline($disciplineId);
$title = NULL;
foreach ($this->titles as $letter){
$free = true;
foreach ($subgroups as $subgr) {
if ($subgr['Title'] == $letter)
$free = false;
}
if ($free) {
$title = $letter;
break;
}
}
if ($title == NULL) {
$this->response->body(json_encode(['success' => false, 'response' => 'Вы превысили допустимое количество подгрупп']));
} else {
$subgroup = Model_Subgroup::make()
->title($title)
->teacherID($teacherId)
->disciplineID($disciplineId)
->create();
$this->response->body(json_encode([ 'success' => true, 'response' => $subgroup]));
}
}
public function action_get_students(){
$students = Model_Subgroup::get_students($_POST["SubgroupID"], $_POST["DisciplineID"]);
$this->response->body(json_encode(['students' => $students]));
}
public function action_attach_student(){
$student = $_POST["StudentID"];
$subgroup = $_POST["SubgroupID"];
$response['success'] = Model_Subgroup::attachStudent($student, $subgroup);
$this->response->body(json_encode($response));
}
public function action_detach_student(){
$student = $_POST["StudentID"];
$subgroup = $_POST["SubgroupID"];
Kohana::$log->add(Log::WARNING, $student. ' '.$subgroup);
$response['success'] = Model_Subgroup::detachStudent($student, $subgroup);
$this->response->body(json_encode($response));
}
}
\ No newline at end of file
......@@ -50,22 +50,28 @@ class Controller_Teacher_Discipline_Edit extends Controller_Environment_Teacher
}
public function action_edit_students() {
$this->manageGroups($this->discipline, $students, $attached);
$allGroups = $this->discipline->getAllGroups()->as_array();
$groupInfo = array();
foreach($allGroups as $group) {
$groupInfo[$group["ID"]] = array('SpecName' => $group["SpecName"]);
//$this->manageGroups($this->discipline, $students, $attached);
$students = $this->discipline->getStudents();
$groups = $this->discipline->getAllGroups()->as_array();
$subgroups = Model_Subgroup::getSubgroupsForDiscipline($this->discipline->ID);
foreach ($subgroups as &$subgroup) {
$subgroup["Students"]= Model_Subgroup::get_students($subgroup["ID"], $this->discipline->ID);
foreach ($students as $key =>&$student) {
foreach ($subgroup["Students"] as $subgroup_student){
if ($subgroup_student["ID"] == $student["ID"])
unset($students[$key]);
}
}
}
$this->twig->set([
'Groups' => $students,
'GroupsAttached' => $attached,
'GroupsForDiscipline' => $groupInfo,
'UnbindStudents' => $students,
'Groups' => $groups,
'GradesList' => Model_Grades::loadAll(),
'GroupsList' => $this->discipline->Faculty->getGroups($this->discipline->GradeID),
'SemesterID' => $this->discipline->SemesterID,
'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation,
'Subgroups' => $subgroups
]);
}
......
<?php
class Model_Helper_SubgroupBuilder extends Model_Helper_Builder
{
public function create() {
$this->data += [
'TeacherID' => null,
];
$required = [
'Title', 'DisciplineID'
];
if (array_diff($required, array_keys($this->data)))
throw new InvalidArgumentException('Not enough arguments');
return new Model_Subgroup($this->data, false);
}
function & title($string) {
$string = trim($string);
if (!strlen($string))
throw new InvalidArgumentException('Title can\'t be empty');
$this->data['Title'] = UTF8::clear($string);
return $this;
}
function & teacherID($id) {
if (!is_numeric($id) || $id <= 0)
throw new InvalidArgumentException('Teacher id is incorrect');
$this->data['TeacherID'] = (int) $id;
return $this;
}
function & disciplineID($id) {
if (!is_numeric($id) || $id <= 0)
throw new InvalidArgumentException('Discipline id is incorrect');
$this->data['DisciplineID'] = (int) $id;
return $this;
}
}
<?php defined('SYSPATH') || die('No direct script access.');
class Model_Subgroup extends Model_Container
{
protected function getRawData($id) {
$sql = 'CALL `Subgroup_GetInfo`(:id)';
$info = DB::query(Database::SELECT, $sql)
->param(':id', $id)->execute();
if ($info->count() == 0)
throw new InvalidArgumentException('Subgroup was not found');
return $info[0];
}
public static function make() {
return new Model_Helper_SubgroupBuilder();
}
# todo: conflict with self::load()
public static function with($id) {
return self::load($id);
}
protected function create() {
$sql = 'SELECT `CreateSubgroup`(Title, TeacherID, DisciplineID) AS `ID`';
$this->data[self::$ID_FIELD] = DB::query(Database::SELECT, $sql)
->parameters($this->data)
->execute()[0]['ID'];
}
public static function get_students($id, $discipline) {
$sql = 'CALL `Subgroup_GetStudents`(:SubgroupID)';
$rows = DB::query(Database::SELECT, $sql)
->parameters([
':SubgroupID' => $id,
])->execute()->as_array();
$discipline = Model_Discipline::load($discipline);
$groups = $discipline->getAllGroups();
foreach ($rows as $key => &$row){
$find_flag = false;
foreach ($groups as $group) {
if ($group['ID'] == $row["GroupID"]){
$find_flag = true;
break;
}
}
if (!$find_flag)
unset($rows[$key]);
}
return $rows;
}
public static function attachStudent($studentId, $subgroupId) {
$sql = 'SELECT `Subgroup_BindStudent`(:pStudentID, :pSubgroupID) AS `res`';
return DB::query(Database::SELECT, $sql)
->parameters([
':pStudentID' => $studentId,
':pSubgroupID' => $subgroupId
])->execute()->get('res');
}
public static function detachStudent($studentId, $subgroupId) {
$sql = 'SELECT `Subgroup_UnbindStudent`(:pStudentID, :pSubgroupID) AS `res`';
return DB::query(Database::SELECT, $sql)
->parameters([
':pStudentID' => $studentId,
':pSubgroupID' => $subgroupId
])->execute()->get('res');
}
public static function getSubgroupsForDiscipline($disciplineId) {
$sql = 'CALL `Discipline_GetSubgroups`(:DisciplineID)';
return DB::query(Database::SELECT, $sql)
->parameters([
':DisciplineID' => $disciplineId,
])->execute()->as_array();
}
}
......@@ -8,16 +8,14 @@
{{ HTML.style('static/css/teacher/discipline/edit/students.css')|raw }}
{% endblock %}
{% macro outputStudent(Student, DisciplineCreationISAllowed) %}
<div id="{{ Student.ID }}" class="Student {% if Student.AttachType == 'detach' %}StatusUnbind{% else %}StatusBind{% endif %}">
<span class="Name">{{ Student.LastName }} {{ Student.FirstName }} {{ Student.SecondName }}</span>
{% if DisciplineCreationISAllowed %}
{% if Student.AttachType == 'detach' %}
<button class="action Action_BindStudent">Прикрепить студента</button>
{% else %}
<button class="action Action_UnbindStudent">Отсоединить студента</button>
{% endif %}
{% macro outputStudent(Student, StudentToDetach) %}
<div id="{{ Student.ID }}" class="Student {% if StudentToDetach %}StatusBind{% else %}StatusUnbind{% endif %}">
<span class="Name">{{ Student.LastName }} {{ Student.FirstName }} {{ Student.SecondName }}</span>
{% if StudentToDetach %}
<button class="action Action_UnbindStudent">Отсоединить студента</button>
{% else %}
<button class="action Action_BindStudent">Прикрепить студента</button>
{% endif %}
</div>
{% endmacro %}
......@@ -27,75 +25,153 @@
{% block map_content %}
{% if SemesterID >=7 %}
<div style="text-align: center; color: red;">
<p>Список студентов определяется учебным планом, сформированным в 1С</p>
</div>
<div style="text-align: center; color: red;">
<p>Список студентов определяется учебным планом, сформированным в 1С</p>
</div>
{% endif %}
<div class="StudentsList">
<input type="hidden" class="HiddenInputFacultyID" value="{{ Discipline.FacultyID }}">
<div class="GeneralStudentsList">
<input type="hidden" class="HiddenInputDisciplineID" value="{{ Discipline.ID }}">
<input type="hidden" class="HiddenInputAuthorID" value="{{ Discipline.AuthorID }}">
{# <div class="GeneralStudentsList">
<h2 class="BlueTitle">Основные студенты</h2>
{% for groupID, group in Groups %}
<div class="GradeAndGroupTitle ActionShowHideGroupContainer" id="{{ groupID }}">
<span class="info">{{ Rus[group[0].Degree] }}, курс {{ group[0].GradeNum }} группа {{ group[0].GroupNum }} | {{ GroupsForDiscipline[group[0].GroupID]["SpecName"] }}</span>
<span class="Action">Открыть список ▼</span>
<div class="GroupContainer">
<div class="hideListAction"></div>
{% for student in group %}
{{ idx.outputStudent(student, DisciplineCreationISAllowed) }}
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{#<div class="AttachedStudentsList">
<h2 class="BlueTitle">Прикрепленные студенты</h2>
{% for groupID, group in GroupsAttached %}
<div class="GroupContainerAttached" id="{{ groupID }}">
<div class="groupInfo"><div class = "groupInfoAlone">{{ group[0].GradeNum }}.{{ group[0].GroupNum }}</div></div>
{% for student in group %}
{{ idx.outputStudent(student, DisciplineCreationISAllowed) }}
{% endfor %}
</div>
{% endfor %}
</div>
{% if DisciplineCreationISAllowed %}
<div class="SearchStudents">
<h2 class="BlueTitle">Поиск студентов</h2>
<div class="SearchSettings">
<select class="SelectGrade defaultForm">
<option value="0">Выберите курс:</option>
{% for Grade in GradesList %}
{% set Title = (Grade['Degree'] == 'master' ? 'Магистратура' : 'Курс') %}
<option value="{{ Grade.ID }}" {% if Grade.ID == Discipline.GradeID %}selected{% endif %}>
{{ Title }} {{ Grade.Num }}
</option>
{% endfor %}
</select>
<select class="SelectStudyGroup defaultForm FLeft">
<option value="0">Выберите группу:</option>
{% for Group in GroupsList %}
<option value="{{ Group.ID }}">Группа {{ Group.GroupNum }} - {{ Group.SpecName }}</option>
{% endfor %}
</select>
<div class="ClearFix">
<input type="text" class="InputStudentName defaultForm FLeft P1Width" placeholder="Фамилия Имя Отчество"
value="">
<div class="defaultForm FRight P2Width Margin10 Top">
<button class="defaultForm BlueButton FullWidth noMargin searchBtn">Поиск</button>
</div>
</div>
</div>
<div class="SearchResult"></div>
</div>
{% endif %}
#}
<div class="SubgroupStudentsList Margin10 Top">
<h2 class="BlueTitle">Подгруппы</h2>
<div class="Subgroup"></div>
{% for Subgroup in Subgroups %}
<div class="Subgroup GradeAndGroupTitle ActionShowHideGroupContainer" id="{{ Subgroup.ID }}">
<span class="info">Подгруппа {{ Subgroup.Title }}</span>
<span class="Action">Открыть список ▼</span>
</div>
<div class="GroupContainer">
<div class="hideListAction"></div>
{% for student in group %}
{{ idx.outputStudent(student, DisciplineCreationISAllowed) }}
{% for Student in Subgroup.Students %}
{{ idx.outputStudent(Student, true) }}
{% endfor %}
</div>
{% endfor %}
<div class="defaultForm P2Width Margin10 Top">
<button class="addSubgroupBtn defaultForm BlueButton FullWidth noMargin">Добавить</button>
</div>
</div>
<div class="AttachedStudentsList">
<h2 class="BlueTitle">Прикрепленные студенты</h2>
{% for groupID, group in GroupsAttached %}
<div class="GroupContainerAttached" id="{{ groupID }}">
<div class="groupInfo"><div class = "groupInfoAlone">{{ group[0].GradeNum }}.{{ group[0].GroupNum }}</div></div>
{% for student in group %}
{{ idx.outputStudent(student, DisciplineCreationISAllowed) }}
<div class="SearchStudents">
<h2 class="BlueTitle">Поиск студентов</h2>
<div class="SearchSettings">
<p>Выберите подгруппу, в которую хотите добавить студента, а затем воспользуйтесь фильтром по группе и/или
ФИО студента.</p>
<select class="SelectStudyGroup HalfWidth defaultForm">
<option value="0">Выберите группу:</option>
{% for Group in GroupsList %}
<option value="{{ Group.ID }}">Группа {{ Group.GroupNum }} - {{ Group.SpecName }}</option>
{% endfor %}
</div>
{% endfor %}
</div>
</select>
{% if DisciplineCreationISAllowed %}
<div class="SearchStudents">
<h2 class="BlueTitle">Поиск студентов</h2>
<div class="SearchSettings">
<select class="SelectGrade defaultForm">
<option value="0">Выберите курс:</option>
{% for Grade in GradesList %}
{% set Title = (Grade['Degree'] == 'master' ? 'Магистратура' : ( Grade['Degree'] == 'bachelor' ? 'Бакалавриат' : (Grade['Degree'] == 'specialist' ? 'Специалитет' : 'Аспирантура'))) %}
<option value="{{ Grade.ID }}" {% if Grade.ID == Discipline.GradeID %}selected{% endif %}>
{{ Title }} {{ Grade.Num }}
</option>
{% endfor %}
</select>
{% if DisciplineCreationISAllowed %}
<div class="SearchStudents">
<h2 class="BlueTitle">Поиск студентов</h2>
<select class="SelectStudyGroup defaultForm FLeft">
<option value="0">Выберите группу:</option>
{% for Group in GroupsList %}
<option value="{{ Group.ID }}">Группа {{ Group.GroupNum }} - {{ Group.SpecName }}</option>
{% endfor %}
</select>
<div class="SearchSettings">
<select class="SelectGrade defaultForm">
<option value="0">Выберите курс:</option>
{% for Grade in GradesList %}
{% set Title = (Grade['Degree'] == 'master' ? 'Магистратура' : ( Grade['Degree'] == 'bachelor' ? 'Бакалавриат' : (Grade['Degree'] == 'specialist' ? 'Специалитет' : 'Аспирантура'))) %}
<option value="{{ Grade.ID }}" {% if Grade.ID == Discipline.GradeID %}selected{% endif %}>
{{ Title }} {{ Grade.Num }}
</option>
{% endfor %}
</select>
<select class="SelectSubgroup HalfWidth defaultForm FloatRight">
{% for Subgroup in Subgroups %}
<option value="{{ Subgroup.ID }}"> Подгруппа {{ Subgroup.Title }} </option>
{% else %}
<option value="0">Добавьте подгруппы</option>
{% endfor %}
</select>
<div class="ClearFix">
<input type="text" class="InputStudentName defaultForm FLeft P1Width" placeholder="Фамилия Имя Отчество"
value="">
<div class="defaultForm FRight P2Width Margin10 Top">
<button class="defaultForm BlueButton FullWidth noMargin searchBtn">Поиск</button>
<div class="ClearFix">
<input type="text" class="InputStudentName defaultForm FLeft P1Width"
placeholder="Фамилия Имя Отчество"
value="">
<div class="defaultForm FRight P2Width Margin10 Top">
<button class="defaultForm BlueButton FullWidth noMargin searchBtn">Поиск</button>
</div>
</div>
</div>
<div class="SearchResult StudentList">
{% for student in UnbindStudents %}
{{ idx.outputStudent(student, false) }}
{% endfor %}
</div>
</div>
<div class="SearchResult"></div>
</div>
{% endif %}
</div>
{% endblock %}
{% 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