Skip to content
Snippets Groups Projects
Select Git revision
  • 38a8636de24ea7ab1c2ddaf53098fef9df9955ca
  • develop default
  • master
  • issue609_stub_nolink
  • hotfix/v2.9.3
  • issue608_journal_tristate
  • hotfix/v2.9.2
  • issue606_global_woes
  • issue299_add_subgroups
  • issue592_student_movement
  • issue606_globaldiscipline_bind
  • issue595_discipline_info
  • issue574_dash_norates
  • issue591_warn_global1c
  • issue593_1cexport_semester
  • issue327_admin_auth
  • issue590_issue_subject
  • issue589_tab_numbers
  • issue583_logaccount_formexport
  • issue584_block_formexport
  • issue527_exam_detached
  • v2.1.5
  • v2.0.3
  • v2.0.2
  • v2.0.1
  • v2.0.0
  • v1.1.2
  • v1.1.1
  • v1.1.0
  • v0.9.3
  • v0.9.1
  • v0.9.2
  • v1.03
  • v1.02
  • v1.01
  • v1.0
36 results

FinalReport.php

Blame
  • Forked from it-lab / grade
    Source project has a limited visibility.
    Discipline.php 8.03 KiB
    <?php defined('SYSPATH') || die('No direct script access.');
    
    class Controller_Handler_Discipline extends Controller_Handler_Api
    {
        /** @var  Model_User_Teacher */
        protected $user;
    
        # /handler/discipline/
        public function action_index() {
            $id = (int) $this->request->post('id');
            return Model_Discipline::load($id);
        }
    
        # /handler/discipline/create
        public function action_create() {
            if (!Model_System::loadConfig()->Functional->DisciplineCreation)
                throw HTTP_Exception::factory(404);
    
            $this->user->checkAccess(User::RIGHTS_TEACHER);
    
            $discipline = Model_Discipline::make()
                ->author  ($this->user->TeacherID)
                ->semester($this->post['semesterID'])
                ->faculty ($this->post['facultyID'])
                ->subject ($this->post['subjectID'])
                ->grade   ($this->post['gradeID'])
                ->lectures($this->post['lectures'])
                ->practice($this->post['practice'])
                ->labs    ($this->post['labs'])
                ->type    ($this->post['type'])
                ->create();
    
            if ($this->post['bonus'] == "true")
                Model_Map::of($discipline)->addModuleBonus($this->user->TeacherID);
    
            return ['ID' => $discipline->ID];
        }
    
        public function action_getCompounds() {
            $ret = '<option value="0"> -- Нет -- </option>';
            $compounds = Model_Grades::getCompoundDisciplinesForGrade($this->post['gradeID']);
            foreach($compounds as $cmp){
                $cmpID = $cmp['ID'];
                $cmpName = $cmp['Name'];
                $ret .= "<option value = $cmpID> $cmpName </option>";
            }
            return $ret;
        }
    
        # /handler/discipline/update
        public function action_update() {
            $this->user->checkAccess(User::RIGHTS_TEACHER);
    
            $id = (int) $this->request->post('id');
    
            if ($id <= 0)
                throw new InvalidArgumentException(Error::ID_IS_INCORRECT);
    
            throw new LogicException('Not implemented yet');
        }
    
        # /handler/discipline/clear
        public function action_clear() {
            # todo: implement me
            $this->user->checkAccess(User::RIGHTS_ADMIN);
    
            $id = (int) $this->request->post('id');
    //        Model_Discipline::load($id)->clear()->delete();
        }
    
        # /handler/discipline/delete
        public function action_delete() {
            if (!Model_System::loadConfig()->Functional->DisciplineCreation)
                throw HTTP_Exception::factory(404);
    
            $discipline = $this->loadDisciplineAndAuthorCheck();
            if ($discipline->IsLocked)
                throw new LogicException(Error::DISCIPLINE_IS_LOCKED);
            if (Model_Rating::count($discipline) > 0)
                throw new LogicException(Error::DISCIPLINE_IS_LOCKED);
    
            $discipline->delete();
        }
    
        public function action_delegate() {
    //        if (!Model_System::loadConfig()->Functional->DisciplineCreation)
    //            throw HTTP_Exception::factory(404);
    
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = (int) $this->request->post('teacherID');
            $teacher = Model_Teacher::with($teacherID);
            $discipline->delegateTo($teacher);
        }
    
        public function action_bind() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = (int) $this->request->post('teacherID');
            $teacher = Model_Teacher::with($teacherID);
            $discipline->bind($teacher);
        }
    
        public function action_unbind() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = (int) $this->request->post('teacherID');
            $teacher = Model_Teacher::with($teacherID);
            $discipline->unbind($teacher);
        }
    
        public function action_copyStructure() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = (int) $this->request->post('teacherID');
            $disciplineFromID = (int) $this->request->post('disciplineFromID');
            $discipline->copyDisciplineStructureFrom($teacherID, $disciplineFromID);
        }
    
        public function action_copyMap() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
    
            $disciplineFromID = (int) $this->request->post('disciplineFromID');
            $disciplineFrom = Model_Discipline::load($disciplineFromID);
            if ($discipline->Type === 'exam' && ($disciplineFrom->Type === 'credit' || $disciplineFrom->Type === 'grading_credit')) {
                return array(
                    'return_code' => 2,
                    'success' => false,
                );
            }
            $result = $discipline->copyDisciplineMapFrom($discipline->ID, $disciplineFromID);
            return array(
                'return_code' => $result,
                'success' => $result === 0,
            );
        }
    
        public function action_clearModules() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = $this->user->TeacherID;
            $code = $discipline->clearModules($teacherID);
            $code = $code.'';
            return json_encode($code);
        }
    
        public function action_hasModules() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $code = $discipline->hasModules();
            $code = $code.'';
            return json_encode($code);
        }
    
        public function action_setInactive() {
            $this->user->checkAccess(User::RIGHTS_TEACHER);
            $id = (int)$this->request->post('id');
            $discipline = Model_Discipline::load($id);
            if (($discipline->AuthorID != $this->user->TeacherID) && !($this->user->isDean() || $this->user->isAdmin()))
                throw new LogicException(Error::ACCESS_DENIED);
            $code = $discipline->setInactive();
            $code = $code.'';
            return json_encode($code);
        }
    
        public function action_setActive() {
            $this->user->checkAccess(User::RIGHTS_TEACHER);
            $id = (int)$this->request->post('id');
            $discipline = Model_Discipline::load($id);
            if (($discipline->AuthorID != $this->user->TeacherID) && !($this->user->isDean() || $this->user->isAdmin()))
                throw new LogicException(Error::ACCESS_DENIED);
            $code = $discipline->setActive();
            $code = $code.'';
            return json_encode($code);
        }
    
        public function action_getSimilarDisciplines() {
            $discipline = $this->loadDisciplineAndAuthorCheck();
            $teacherID = (int) $this->user->TeacherID;
            $teacher = Model_Teacher::with($teacherID);
            $sameSemester = $this->request->post('sameSemester') === 'true';
            $sameSubject = $this->request->post('sameSubject') === 'true';
            $subjectID = $discipline->SubjectID;
            if (!$sameSubject) {
                $subjectID = null;
            }
            $semesterID = $discipline->SemesterID;
            if (!$sameSemester) {
                $semesterID = null;
            }
            return json_encode($teacher->getSimilarDisciplines($subjectID, $semesterID));
        }
    
        public function action_getDisciplinesForGroup() {
            $groupID = $this->request->post('groupID');
            $semesterID = User::instance()->SemesterID;
            //$students = Model_Students::ofGroup($groupID, $semesterID);
    
            // TODO: refactor after new groups implemented
            $disciplines = Model_Group::with($groupID)->getDisciplinesForExport(false, $semesterID);
    
            return json_encode($disciplines);
        }
    
        public function action_setDisciplineErrorForGroup() {
            $groupID = $this->request->post('groupID');
            $disciplineID = $this->request->post('disciplineID');
            $semesterID = User::instance()->SemesterID;
            $error = $this->request->post('error');
    
            $res = Model_Logs::setLastFormExportError($disciplineID, $groupID, $semesterID, $error);
            return json_encode($res);
        }
    
        /**
         * @return Model_Discipline
         */
        private function loadDisciplineAndAuthorCheck() {
            $this->user->checkAccess(User::RIGHTS_TEACHER);
    
            $id = (int)$this->request->post('id');
            $discipline = Model_Discipline::load($id);
            if (($discipline->IsInactive) || ($discipline->AuthorID != $this->user->TeacherID) && !($this->user->isDean() || $this->user->isAdmin()))
                throw new LogicException(Error::ACCESS_DENIED);
            return $discipline;
        }
    }