Newer
Older
<?php defined('SYSPATH') || die('No direct script access.');
class Controller_Teacher_Discipline_Edit extends Controller_Environment_Teacher
{
/** @var Model_Discipline */
private $discipline;
const twigSource = 'teacher/discipline/edit/';
public function before() {
parent::before();
$id = (int) $this->request->param('id');
if (!(
$this->discipline->hasTeacher($this->user->TeacherID) ||
$this->user->isAdmin() || $this->user->isDean()
))
throw HTTP_Exception::factory(403, "Недостаточно прав для редактирования.");
$section = $this->request->param('section');
$this->twig->set_filename(static::twigSource . $section);
$this->twig->isAuthor = ($this->user->TeacherID == $this->discipline->AuthorID);
$this->setSemesterByDiscipline($this->discipline);
public function action_edit_settings() {
'SubjectsList' => Model_Faculty::with($this->discipline->FacultyID)->getSubjects(),
'GradesList' => Model_Grades::loadAll(),
'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation,
'DisciplineInternalInfo' => $this->discipline->getInternalInfo(),
]);
}
$this->twig->Map = $this->getMapInfo();
public function action_edit_groups() {
$this->twig->set([
'GroupsForDiscipline' => $this->discipline->getAllGroups()->as_array(),
'Groups' => $this->discipline->Faculty->getGroups($this->discipline->GradeID),
'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation,
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"]);
}
'Groups' => $students,
'GroupsAttached' => $attached,
'GroupsForDiscipline' => $groupInfo,
'GradesList' => Model_Grades::loadAll(),
'GroupsList' => $this->discipline->Faculty->getGroups($this->discipline->GradeID),
'SemesterID' => $this->discipline->SemesterID,
'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation,
public function action_edit_teachers() {
$this->twig->set([
'Discipline' => $this->discipline,
'FacultiesList' => Model_Faculties::load(),
'Departments' => $this->user->Faculty->getDepartments(),
'BindTeachers' => $this->discipline->getTeachers(),
'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation,
const LANDMARK = 0;
const CURRENT = 1;
const FULL_RATE = 2;
private function getMapInfo() {
$moduleList = Model_Map::getRoadmap($this->discipline->ID, 'rate')->as_array('ModuleID');
$bonus = false;
$maxRate = 0;
$modules = [];
$atLeastOneRegular = false;
foreach ($moduleList as &$submoduleList) {
$info = &$submoduleList[0];
if ($info['ModuleType'] === 'extra')
if (($info['ModuleType'] === 'regular') || ($info['ModuleType'] === 'bonus'))
$atLeastOneRegular = true;
$ctrlRate = self::countRates($submoduleList);
$bonus = $bonus || $info['ModuleType'] === 'bonus';
$maxRate += $ctrlRate[self::FULL_RATE];
$modules[] = [
'ID' => $info['ModuleID'],
'Type' => $info['ModuleType'],
'Name' => $info['ModuleName'],
'CurrentControl' => $ctrlRate[self::CURRENT],
'LandmarkControl' => $ctrlRate[self::LANDMARK],
'Rate' => $ctrlRate[self::FULL_RATE],
'Submodules' => &$submoduleList,
];
$allowCopy = ($this->discipline->AuthorID == $this->user->TeacherID) && !$atLeastOneRegular;
return [
'MaxRate' => $maxRate - (($bonus) ? 10 : 0),
'Modules' => &$modules,
'AllowCopy' => $allowCopy,
private function manageGroups(Model_Discipline $discipline, &$other, &$attached) {
$students = $discipline->getStudents();
$a = array_filter($students, function ($s) {
return $s->AttachType === 'attach';
});
$b = array_filter($students, function ($s) {
return $s->AttachType !== 'attach';
});
$attached = Arr::groupBy('GroupID', $a);
$other = Arr::groupBy('GroupID', $b);
private static function countRates(&$submoduleList) {
$controlRate = [0, 0, 0]; // control Rate
foreach ($submoduleList as &$submodule) {
$index = $submodule['SubmoduleType'] === 'CurrentControl'; // 1 - current, 0 - landmark
$controlRate[$index] += (int) $submodule['MaxRate'];
}
$controlRate[self::FULL_RATE] = $controlRate[self::CURRENT] + $controlRate[self::LANDMARK];
return $controlRate;
}