<?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'); $this->discipline = Model_Discipline::load($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->Discipline = $this->discipline; $this->twig->isAuthor = ($this->user->TeacherID == $this->discipline->AuthorID); $this->setSemesterByDiscipline($this->discipline); } public function action_edit_settings() { $this->twig->set([ 'SubjectsList' => Model_Faculty::with($this->discipline->FacultyID)->getSubjects(), 'GradesList' => Model_Grades::loadAll(), 'DisciplineCreationISAllowed' => Model_System::loadConfig()->Functional->DisciplineCreation, 'DisciplineInternalInfo' => $this->discipline->getInternalInfo(), ]); } public function action_edit_structure() { $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() { $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["RecordBookID"] == $student["RecordBookID"]) unset($students[$key]); } } } $teachers = $this->discipline->getTeachers(); $teachersByID = []; foreach ($teachers as $teacher) $teachersByID[$teacher["ID"]] = $teacher; $this->twig->set([ 'UnbindStudents' => $students, 'Groups' => $groups, 'GradesList' => Model_Grades::loadAll(), 'GroupsList' => $this->discipline->Faculty->getGroups($this->discipline->GradeID), 'SemesterID' => $this->discipline->SemesterID, 'BindTeachers' => $teachersByID, 'Subgroups' => $subgroups ]); } 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') continue; 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; } }