Skip to content
Snippets Groups Projects
Discipline.php 10.7 KiB
Newer Older
<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Teacher_Discipline extends Controller_UserEnvi {
    public function action_CreateDiscipline()
        $twig = Twig::factory('teacher/discipline/CreateDiscipline');
        $twig->User = $this->UserInfo;
        $twig->FacultiesList = Model_Faculties::create()->common()->asArray();
        $twig->SubjectsList = Model_Subjects::create()->byFaculty($this->UserInfo['FacultyID'])->asArray();
        $twig->GradesList = Model_Grades::create()->common()->asArray();
PavelBegunkov's avatar
PavelBegunkov committed
    
    public function action_EditSettings()
        $twig = Twig::factory('teacher/discipline/EditSettings');
PavelBegunkov's avatar
PavelBegunkov committed
        
        $twig->User = $this->UserInfo;
        //$twig->FacultiesList = Model_Faculties::create()->common()->asArray();
        $twig->Discipline = $this->GetDisciplineInfo($db, $id);
        $twig->SubjectsList = Model_Subjects::create()->byFaculty($this->UserInfo['FacultyID'])->asArray();
        $twig->GradesList = Model_Grades::create()->common()->asArray();
PavelBegunkov's avatar
PavelBegunkov committed
        
        $this->response->body($twig);
    }
PavelBegunkov's avatar
PavelBegunkov committed
    public function action_EditStructure()
    {
        $id = $this->request->param('id');
        $db = new Model_Teacher_Map;
        $twig = Twig::factory('teacher/discipline/EditStructure');
        $twig->User = $this->UserInfo; 
PavelBegunkov's avatar
PavelBegunkov committed
        $twig->Discipline = $this->GetDisciplineInfo($db, $id);
PavelBegunkov's avatar
PavelBegunkov committed
        $twig->Map = $this->GetMapInfo($db->getMapForDiscipline($id));
PavelBegunkov's avatar
PavelBegunkov committed
        
        $this->response->body($twig);
    }
    
    public function action_EditGroups()
    {
        $id = $this->request->param('id');
        $db = new Model_Teacher_Map;
        $twig = Twig::factory('teacher/discipline/EditGroups');
PavelBegunkov's avatar
PavelBegunkov committed
        
        $twig->User = $this->UserInfo;
        $twig->Discipline = $this->GetDisciplineInfo($db, $id);
PavelBegunkov's avatar
PavelBegunkov committed

        $twig->GroupsForDiscipline = Model_Groups::create()->forDiscipline($id)->asArray();
        $twig->Groups = Model_Groups::create()->ordByGroups($twig->Discipline['GradeID'], $twig->Discipline['FacultyID'])->asArray();
PavelBegunkov's avatar
PavelBegunkov committed
        
        $this->response->body($twig);
    }
    
    public function action_EditStudents()
    {
        $id = $this->request->param('id');
        $db = new Model_Teacher_Map;
        $twig = Twig::factory('teacher/discipline/EditStudents');
PavelBegunkov's avatar
PavelBegunkov committed
        
        $twig->User = $this->UserInfo;
        $twig->Discipline = $this->GetDisciplineInfo($db, $id);
        $twig->GradesList = Model_Grades::create()->common()->asArray();
        $twig->Groups = Model_Groups::create()->ordByGroups($twig->Discipline['GradeID'], $twig->Discipline['FacultyID'])->asArray();
Антон Шалимов's avatar
Антон Шалимов committed

PavelBegunkov's avatar
PavelBegunkov committed
        $students = $db->getStudentsForDiscipline($id);
Антон Шалимов's avatar
Антон Шалимов committed
        $stdHandled = array();
        $attachStdHandled = array();
PavelBegunkov's avatar
PavelBegunkov committed
        $groupID = 0; 
        $i = 0; 
        $k = 0;
        $n = 0;
        $j = 0;
Антон Шалимов's avatar
Антон Шалимов committed
        foreach($students as $row) {
PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['AttachType'] == 'attach'){
PavelBegunkov's avatar
PavelBegunkov committed
                if ($row['GroupID'] != $groupID) {
                    $groupID = $row['GroupID'];
                    $k++;
                    $n = 0;
                    $attachStdHandled[$k]['GroupID'] = $row['GroupID'];
                    $attachStdHandled[$k]['GradeID'] = $row['GradeID'];
                    $attachStdHandled[$k]['GradeNum'] = $row['GradeNum'];
                    $attachStdHandled[$k]['GroupNum'] = $row['GroupNum'];
                    $attachStdHandled[$k]['Degree'] = Model_Grades::getDegreeTitle($row['Degree']);
PavelBegunkov's avatar
PavelBegunkov committed
                }
                $n++;
PavelBegunkov's avatar
PavelBegunkov committed
                $attachStdHandled[$k]['students'][$n]['ID'] = $row['ID'];
PavelBegunkov's avatar
PavelBegunkov committed
                $attachStdHandled[$k]['students'][$n]['LastName'] = $row['LastName'];
                $attachStdHandled[$k]['students'][$n]['FirstName'] = $row['FirstName'];
                $attachStdHandled[$k]['students'][$n]['SecondName'] = $row['SecondName'];
PavelBegunkov's avatar
PavelBegunkov committed
                $attachStdHandled[$k]['students'][$n]['AttachType'] = $row['AttachType'];
PavelBegunkov's avatar
PavelBegunkov committed

                // $k++;
                // $attachStdHandled['StdCount'] += 1;
                // $attachStdHandled[$k]['StudentID'] = $row['StudentID'];
                // $attachStdHandled[$k]['LastName'] = $row['LastName'];
                // $attachStdHandled[$k]['FirstName'] = $row['FirstName'];
                // $attachStdHandled[$k]['SecondName'] = $row['SecondName'];
                // $attachStdHandled[$k]['StudentID'] = $row['StudentID'];
                // $attachStdHandled[$k]['GroupID'] = $row['GroupID'];
                // $attachStdHandled[$k]['GradeID'] = $row['GradeID'];
                // $attachStdHandled[$k]['GradeNum'] = $row['GradeNum'];
                // $attachStdHandled[$k]['GroupNum'] = $row['GroupNum'];
                // $attachStdHandled[$k]['Degree'] = $row['Degree'];
Антон Шалимов's avatar
Антон Шалимов committed
            }
            else
            {
                if ($row['GroupID'] != $groupID) {
                    $groupID = $row['GroupID'];
                    $i++;
                    $j = 0;
                    $stdHandled[$i]['GroupID'] = $row['GroupID'];
                    $stdHandled[$i]['GradeID'] = $row['GradeID'];
                    $stdHandled[$i]['GradeNum'] = $row['GradeNum'];
                    $stdHandled[$i]['GroupNum'] = $row['GroupNum'];
                    $stdHandled[$i]['Degree'] = Model_Grades::getDegreeTitle($row['Degree']);
Антон Шалимов's avatar
Антон Шалимов committed
                }
Антон Шалимов's avatar
Антон Шалимов committed
                $j++;
PavelBegunkov's avatar
PavelBegunkov committed
                $stdHandled[$i]['students'][$j]['ID'] = $row['ID'];
PavelBegunkov's avatar
PavelBegunkov committed
                $stdHandled[$i]['students'][$j]['LastName'] = $row['LastName'];
                $stdHandled[$i]['students'][$j]['FirstName'] = $row['FirstName'];
                $stdHandled[$i]['students'][$j]['SecondName'] = $row['SecondName'];
PavelBegunkov's avatar
PavelBegunkov committed
                $stdHandled[$i]['students'][$j]['AttachType'] = $row['AttachType'];
PavelBegunkov's avatar
PavelBegunkov committed
        $twig->Groups = $stdHandled;
        $twig->GroupsAttached = $attachStdHandled;
Антон Шалимов's avatar
Антон Шалимов committed

PavelBegunkov's avatar
PavelBegunkov committed
        $this->response->body($twig);
    }
    
    public function action_EditTeachers()
    {
        $id = $this->request->param('id');
        $db = new Model_Teacher_Map;
        $twig = Twig::factory('teacher/discipline/EditTeachers');
PavelBegunkov's avatar
PavelBegunkov committed
        
        $twig->User = $this->UserInfo;
        $twig->Discipline = $this->getDisciplineInfo($db, $id);
        $twig->BindTeachersList = Model_Teachers::create()->forDiscipline($id)->asArray();
        $twig->FacultiesList = Model_Faculties::create()->common()->asArray();
        $twig->Departments = Model_Departments::byFaculty($this->UserInfo['FacultyID']);
PavelBegunkov's avatar
PavelBegunkov committed
        
        $this->response->body($twig);
    }
    
    private function GetMapInfo($map) {
PavelBegunkov's avatar
PavelBegunkov committed

PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['ModuleType'] == 'extra')
                continue;
PavelBegunkov's avatar
PavelBegunkov committed
            if($row['ModuleID'] != $module)
            {
                $i++;
                $module = $row['ModuleID'];
                $mapHandled[$i]['ModuleID'] = $row['ModuleID'];
                $mapHandled[$i]['ModuleType'] = $row['ModuleType'];
                if ($row['ModuleType'] == 'bonus')
                    $mapHandled['isSetBonus'] = true;
                $mapHandled[$i]['CurrentControl'] = 0;
                $mapHandled[$i]['LandmarkControl'] = 0;
            }
            if(!isset($mapHandled[$i]['SubmodulesCount']))
            {
                $mapHandled[$i]['SubmodulesCount'] = 0;
                $mapHandled[$i]['MaxRate'] = 0;
            }
PavelBegunkov's avatar
PavelBegunkov committed
            $mapHandled[$i]['IsExam'] = $row['IsExam'];
PavelBegunkov's avatar
PavelBegunkov committed
            $j = $mapHandled[$i]['SubmodulesCount'] += 1;
            $mapHandled[$i]['MaxRate'] += (int) $row['MaxRate'];
            $mapHandled[$i]['ModuleTitle'] = $row['ModuleName'];
            $mapHandled[$i][$j]['SubmoduleID'] = $row['SubmoduleID'];
PavelBegunkov's avatar
PavelBegunkov committed
            $mapHandled[$i][$j]['Title'] = $row['SubmoduleName'];
PavelBegunkov's avatar
PavelBegunkov committed
            $mapHandled[$i][$j]['Description'] = $row['SubmoduleDescription'];
PavelBegunkov's avatar
PavelBegunkov committed
            $mapHandled[$i][$j]['SubmoduleControl'] = $row['SubmoduleType'];
PavelBegunkov's avatar
PavelBegunkov committed
            $mapHandled[$i][$j]['MaxRate'] = (int) $row['MaxRate'];
            $maxRate += $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['SubmoduleType'] == 'CurrentControl')
PavelBegunkov's avatar
PavelBegunkov committed
                 $mapHandled[$i]['CurrentControl'] += (int) $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
            if ($row['SubmoduleType'] == 'LandmarkControl')
PavelBegunkov's avatar
PavelBegunkov committed
                 $mapHandled[$i]['LandmarkControl'] += (int) $row['MaxRate'];
PavelBegunkov's avatar
PavelBegunkov committed
        $mapHandled['ModulesCount'] = $i;
        $mapHandled['MaxRate'] = (int) $maxRate; 
        if ($mapHandled['isSetBonus'] == true)
            $mapHandled['MaxRate'] = $mapHandled['MaxRate'] - 10;
    public function GetDisciplineInfo(Model_Teacher_Map $db, $id)
        if($info->count() == 0)
           throw HTTP_Exception::factory(404, "Учебная карта дисциплины с ID $id не найдена!");
PavelBegunkov's avatar
PavelBegunkov committed
        else
            $info = $info->offsetGet(0);
        
        $subject['AuthorID'] = $info['AuthorID'];
Антон Шалимов's avatar
Антон Шалимов committed
        if($this->UserInfo['TeacherID'] != $subject['AuthorID'])
           throw HTTP_Exception::factory(403, "Недостаточно прав для редактирования.");
PavelBegunkov's avatar
PavelBegunkov committed
        
        $subject['DisciplineID'] = $id;
        $subject['DepID'] = $info['DepID'];
        $subject['FacultyID'] = $info['FacultyID'];
PavelBegunkov's avatar
PavelBegunkov committed
        $subject['FacultyName'] = $info['FacultyName'];
PavelBegunkov's avatar
PavelBegunkov committed
        $subject['IsLocked'] = $info['IsLocked'];
        $subject['IsBonus'] = $info['IsBonus'];
PavelBegunkov's avatar
PavelBegunkov committed
        
        $subject['SemesterID'] = $info['SemesterID'];
        $semester = Model_Semesters::getInfo($subject['SemesterID']);
        $subject['SemesterNum'] = $semester['SemesterNum'] == 1 ? 'Осенний' : 'Весенний';
        $subject['SemesterYear'] = $semester['SemesterYear'];
        $teachers = Model_Teachers::create()->forDiscipline($id)->asArray();
PavelBegunkov's avatar
PavelBegunkov committed
        $subject['SubjectID'] = $info['SubjectID'];
        $subject['ExamType'] = $info['ExamType'];
PavelBegunkov's avatar
PavelBegunkov committed
        $subject['LectureHours'] = $info['LectureCount'];
PavelBegunkov's avatar
PavelBegunkov committed
        $subject['LabHours'] = $info['LabCount'];
        $subject['GradeID'] = $info['GradeID'];
        
PavelBegunkov's avatar
PavelBegunkov committed
            $teachersHandled[$i] = $row['LastName'].' '.$row['FirstName'].'';
            if(!empty($row['SecondName']))
PavelBegunkov's avatar
PavelBegunkov committed
                $teachersHandled[$i] .= ' '.$row['SecondName'];
PavelBegunkov's avatar
PavelBegunkov committed
        
        return $subject;