Skip to content
Snippets Groups Projects
Commit 1629d626 authored by Дарья Черепахина's avatar Дарья Черепахина
Browse files

Add specializations.

parent 295fe575
No related merge requests found
Showing with 268 additions and 5 deletions
......@@ -4,7 +4,7 @@
"Items": [
{ "Title": "Подразделения", "Anchor": "faculties" },
{ "Title": "Кафедры", "Anchor": "departments", "Disabled": "true" },
{ "Title": "Направления подготовки", "Anchor": "specializations", "Disabled": "true" }
{ "Title": "Направления подготовки", "Anchor": "specializations"}
]
},
{
......
......@@ -3,7 +3,7 @@
"Title": "Структура ЮФУ",
"Items": [
{ "Title": "Кафедры", "Anchor": "departments", "Disabled": "true" },
{ "Title": "Направления подготовки", "Anchor": "specializations", "Disabled": "true" }
{ "Title": "Направления подготовки", "Anchor": "specializations"}
]
},
{
......
$(function () {
function createSpec(name, abbr, callback) {
$.post(URLdir + 'handler/specializations/create', {
'facultyID': $('#facultySelect').val(),
'name': name,
'abbr': abbr
}, callback, 'json');
}
var $name = $('#SpecName');
var $abbr = $('#SpecAbbr');
function tryToAddSpec() {
if ($name.val().length == 0) {
$name.focus();
} else if (!$abbr.is(':focus') && $abbr.val().length == 0) {
$abbr.focus();
} else {
createSpec($name.val(), $abbr.val(), function (res) {
if (res.success)
$name.add($abbr).val('');
EventInspector.show(res.message, res.success ? 'success' : 'error');
$name.focus();
});
}
}
$('#addSpec').click(tryToAddSpec);
$name.add($abbr).keypress(function (event) {
if (event.keyCode == 13)
tryToAddSpec();
});
});
$(function () {
var data = [];
Dropzone.init([
function (file, content) {
if (file.type !== 'text/plain' && file.type !== 'application/vnd.ms-excel') {
return EventInspector.error('Неверный формат файла!');
}
$('.b-upload-first-step').hide();
$('.b-upload-second-step').show();
$('#problems').hide();
data = content;
}]);
$('#cancel').click(function () {
$('.b-upload-second-step').hide();
$('.b-upload-first-step').show();
$('#save').removeAttr('disabled').text('Сохранить');
data = [];
});
$('#save').click(function () {
$(this).attr('disabled', 'disabled')
.html('<i class="fa fa-circle-o-notch fa-spin"></i>');
$.post(g_URLdir + 'handler/specializations/upload', {
facultyID: $('#faculty').val(),
spec: data
}, function (res) {
console.log(res);
if (res.ErrorsCount > 0){
EventInspector.error('Обнаружены специальности, которые загрузить не удалось.');
} else if(res.RecordsExistsCount > 0) {
EventInspector.success('Обнаружены уже существующие специальности.');
} else {
EventInspector.success('Успешно сохранено!');
}
$('#problems').show();
$('.recordsCount').text(res.RecordsCount);
$('.errorsCount').text(res.ErrorsCount);
$('.recordsExistsCount').text(res.RecordsExistsCount);
$('#cancel').trigger('click');
},"json");
});
});
\ No newline at end of file
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Specializations extends Controller_Handler
{
public function before() {
parent::before();
$this->user->checkAccess(User::RIGHTS_ADMIN | User::RIGHTS_DEAN);
}
public function action_create() {
$facultyID = $this->user->isAdmin() ? $_POST['facultyID'] : $this->user->Faculty->ID;
$id = Model_Specialization::create($_POST['name'], $_POST['abbr'], $facultyID);
$res = [
'success' => ($id >= 0),
'error' => ($id < 0),
'message' =>
($id < 0 ?
'Специальность не добавлена!'
: ($id > 0 ?
'Специальность уже существует!'
: 'Специальность добавлена!')),
];
$this->response->body(json_encode($res));
}
public function action_upload() {
$faculty = $this->user->Faculty;
if ($this->user->isAdmin() && $_POST['facultyID'])
$faculty = Model_Faculty::with($_POST['facultyID']);
$res = FileParser::uploadItems($_POST['spec'],$_POST['facultyID'],1);
$this->response->body(json_encode($res));
}
}
......@@ -31,7 +31,7 @@ class Controller_Handler_Subjects extends Controller_Handler
if ($this->user->isAdmin() && $_POST['facultyID'])
$faculty = Model_Faculty::with($_POST['facultyID']);
$res = FileParser::uploadSubjects($_POST['subjects'],$_POST['facultyID']);
$res = FileParser::uploadItems($_POST['subjects'],$_POST['facultyID'],0);
$this->response->body(json_encode($res));
......
<?php
class Controller_Office_Specializations extends Controller_Environment_Office
{
public function action_index() {
$this->action_upload();
}
public function action_upload() {
$facultyID = $this->user->isAdmin() ? $_POST['facultyID'] : $this->user->Faculty->ID;
$result = [];
$this->twig->set([
'Example' => file_get_contents('static/other/specializations.txt'),
'Faculties' => $this->user->isAdmin() ? Model_Faculties::load() : [],
])->set_filename(static::OFFICE . 'specializations/upload');
}
}
......@@ -108,7 +108,7 @@ class FileParser
* @return array
*/
public static function uploadSubjects($content, $facultyID) {
public static function uploadItems($content, $facultyID, $item) {
$content = explode("\n", self::toUTF8($content)); // DO NOT REPLACE " BY ' THERE!
......@@ -126,7 +126,8 @@ class FileParser
if (empty($name))
continue;
$attempt = Model_Subject::create($name, $abbr, $facultyID);
$attempt = $item == 1 ? Model_Specialization::create($name, $abbr, $facultyID)
: Model_Subject::create($name, $abbr, $facultyID);
if ($attempt < 0) {
$errors[] = ['Row' => $count, 'Info' => implode(';', $line)];
......@@ -155,4 +156,5 @@ class FileParser
else
return $source_str;
}
}
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Specialization
{
public static function create($name, $abbr, $facultyID) {
$sql = "SELECT `CreateSpecialization`(:faculty, :name, :abbr) AS `Num`";
$res = DB::query(Database::SELECT, $sql)
->parameters([
':faculty' => $facultyID,
':name' => UTF8::clear($name),
':abbr' => UTF8::clear($abbr),
])->execute();
return (int) $res->get('Num');
}
}
{% extends "office/base" %}
{% block title %}Загрузка специальностей{% endblock %}
{% block media %}
{{ parent() }}
{{ HTML.style('static/components/office/upload/page.css')|raw }}
{{ HTML.style('static/components/office/dropzone/dz.css')|raw }}
{{ HTML.script('static/components/office/dropzone/dz.js')|raw }}
{{ HTML.script('static/js/office/upload-specializations.js')|raw }}
{{ HTML.script('static/js/office/upload-specialization.js')|raw }}
{% endblock %}
{% block office_content %}
<div class="b-upload-first-step">
<h2 class="Margin10 Bottom">Добавление специальности</h2>
<div class="ClearFix Margin10 Bottom">
{% if Faculties is not empty %}
<div class="goodClearFix defaultForm marginBetween">
<select id="facultySelect" name="facultyID" class="defaultForm">
<option value="0" selected="selected">— Выберите подразделение ЮФУ —</option>
{% for Faculty in Faculties %}
<option value="{{ Faculty.ID }}" {{ User.FacultyID == Faculty.ID ? "selected" }}>
{{ Faculty.Name }} ({{ Faculty.Abbr }})
</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="defaultForm P1Width FLeft ClearFix">
<input type="text" id="SpecName" placeholder="Название специальности" class="defaultForm HalfWidth FLeft"
style="width: 49% !important">
<input type="text" id="SpecAbbr" placeholder="Аббревиатура" class="defaultForm HalfWidth FLeft"
style="margin-left: 3px">
</div>
<button id="addSpec" class="defaultForm noMargin GreenButton P2Width FRight">Добавить</button>
</div>
<h2 class="Margin10 Bottom" style="margin-top: 20px">Пакетная загрузка специальностей</h2>
<p>Инструмент пакетной загрузки специальностей предоставляет возможность добавлять в систему множество наименований
направлений подготовки.</p>
<p>Файл со списком предметов представляет собой <code>.txt</code>-файл, который должен иметь следующий формат:
</p>
<p>
<pre>Название;Аббревиатура</pre>
</p>
<p>Пример:</p>
<div style="display: block; position: relative;">
{{ HTML.anchor('/static/other/specializations.txt', 'Скачать', { 'class': 'btn-clipboard', 'target': '_blank' }) |raw }}
<pre style="white-space:pre">{{ Example|raw }}</pre>
</div>
{{ HTML.component('office/dropzone/dz.twig')|raw }}
</div>
<div class="b-upload-second-step" style="display:none">
<h2 class="Margin10 Bottom">Пакетная загрузка специальностей</h2>
<form enctype="multipart/form-data" action="" method="POST">
{% if Faculties is not empty %}
<p>Выберите факультет, на который нужно загрузить специальности:</p>
<select id="faculty" class="defaultForm">
{% for row in Faculties %}
{% set selected = (row.ID == User.FacultyID ? 'selected="selected"') %}
<option value="{{ row.ID }}" {{ selected }}>
{{ row.Name }} ({{ row.Abbr }})
</option>
{% endfor %}
</select>
{% endif %}
</form>
<div style="float:right;margin-top:5px">
<button id="save" class="defaultForm BlueButton">Сохранить</button>
или <a id="cancel" href="#">отменить</a>
</div>
</div>
<div id="problems" style="margin-top: 20px; display:none">
<p>
Обработано: <span class="recordsCount"></span>,
в том числе с ошибками: <span class="errorsCount"></span> ,
найдены в базе: <span class="recordsExistsCount"></span>.
</p>
</div>
{% endblock %}
Механика и математическое моделирование;Мех
Прикладная математика и информатика;ПМиИ
Математика;Матем
\ No newline at end of file
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