Skip to content
Snippets Groups Projects
Select Git revision
  • 84e9b957e5a19e5889b312dd9490b87131f0e43d
  • 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

Map.php

Blame
  • Forked from it-lab / grade
    Source project has a limited visibility.
    Map.php 19.95 KiB
    <?php defined('SYSPATH') or die('No direct script access.');
    
    class Controller_Handler_Map extends Controller_Handler {
    		
            public function before() {
                $this->model = new Model_Teacher_Map;
                $this->setAccessLevel(self::ACCESS_USER);
                parent::before();
            }
            
    		private function privateDeleteSubmodule($SubmoduleID) {
    			$result = $this->model->deleteSubmodule($this->user['TeacherID'], $SubmoduleID);
    			return $result[0]['Num'];
    		}
    		
    		// Добавление преподавателем дисциплины
    		public function action_AddDiscipline() {
    			$data['success'] = false;
                $this->post -> rule('Grade', 'not_empty')
                            -> rule('Grade', 'digit')
    						-> rule('SubjectID', 'not_empty')
                            -> rule('SubjectID', 'digit')
    						-> rule('BonusRate', 'not_empty')
    						-> rule('ExamType', 'not_empty')
    						-> rule('LectionCount', 'not_empty')
                            -> rule('LectionCount', 'digit')
    						-> rule('PracticeCount', 'not_empty')
                            -> rule('PracticeCount', 'digit')
    						-> rule('LabCount', 'not_empty')
                            -> rule('LabCount', 'digit')
    						-> rule('FacultyID', 'not_empty')
                            -> rule('FacultyID', 'digit');
                if($this->post->check()) {
    					$result = $this->model->AddDiscipline(
    						$this->user['TeacherID'],
    						$this->post->offsetGet('Grade'),
    						$this->post->offsetGet('SubjectID'),
    						$this->post->offsetGet('ExamType'),
    						$this->post->offsetGet('LectionCount'),
    						$this->post->offsetGet('PracticeCount'),
    						$this->post->offsetGet('LabCount'),
    						$this->post->offsetGet('FacultyID')
    					);
    					$data['DisciplineID'] = $result[0]['Num'];
    					if ($this->post->offsetGet('BonusRate') == "true")
    						$result = $this->model->AddModuleBonus(
    							$this->user['TeacherID'],
    							$data['DisciplineID']
    						);
    					if ($data['DisciplineID'] > 0)
    						$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    
    		// Удаление дисциплины
    		public function action_DeleteDiscipline() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit');
    			if($this->post->check()) {
    				$result = $this->model->DeleteDiscipline(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID')		
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Передача дисциплины
    		public function action_DelegateDiscipline() {
    			$data['success'] = false;
                $this->post -> rule('NewAuthorID', 'not_empty')
                            -> rule('NewAuthorID', 'digit')
                           	-> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit');
    			if($this->post->check()) {
    				$BindTeachersList = DataArray::factory('Teachers')->forDiscipline($id)->asArray();
    				$binded = false;
    				foreach ($BindTeachersList as $teacher)
    				{
    					if ($teacher['TeacherID'] == $this->post->offsetGet('NewAuthorID')) {
    						$binded = true;
    						break;
    					}
    				}
    				if ($binded == false) {
    					$result = $this->model->BindTeacher($this->user['TeacherID'], $this->post->offsetGet('NewAuthorID'), $this->post->offsetGet('DisciplineID'));
    				}
    
    				$result = $this->model->DelegateDiscipline(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('NewAuthorID'),
    					$this->post->offsetGet('DisciplineID')		
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    	// --- Изменения базовых параметров дисциплины ---
    	
    		// Изменение предмета
    		public function action_ChangeDisciplineSubject() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('SubjectID', 'not_empty')
                            -> rule('SubjectID', 'digit');
    			if($this->post->check()) {
    				$result = $this->model->ChangeDisciplineSubject(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID'),
    					$this->post->offsetGet('SubjectID')			
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Изменение статуса бонусного модуля
    		public function action_ChangeStatusBonusModule() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('BonusRate', 'not_empty');
    			if($this->post->check()) {
    				if ($this->post->offsetGet('BonusRate') == 'true') {
    					$result = $this->model->AddModuleBonus(
    						$this->user['TeacherID'],
    						$this->post->offsetGet('DisciplineID')
    					);
    					$data['action'] = 'add';
    				}
    				else {
    					$result = $this->model->DeleteModuleBonus(
    						$this->user['TeacherID'],
    						$this->post->offsetGet('DisciplineID')	
    					);
    					$data['action'] = 'delete';
    				}
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Изменение курса
    		public function action_ChangeDisciplineGrade() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('GradeID', 'not_empty')
                            -> rule('GradeID', 'digit');
    			if($this->post->check()) {
    				$result = $this->model->ChangeDisciplineGrade(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID'),
    					$this->post->offsetGet('GradeID')			
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Изменение контроля
    		public function action_ChangeDisciplineControl() {
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('Control', 'not_empty');
    			if($this->post->check()) {
    				$result = $this->model->ChangeDisciplineControl(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID'),
    					$this->post->offsetGet('Control')		
    				);
    				$data['success'] = $result[0]['Num'];
    			}
    			else
    				$data['success'] = 0;
    			$this->response->body(json_encode($data));
    		}
    		
    		// Изменение лекционных часов и практических часов
    		public function action_ChangeDisciplineHours() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('Hours', 'not_empty')
                            -> rule('Hours', 'digit')
    						-> rule('Type', 'not_empty')
                            -> rule('Type', 'digit');
    			if($this->post->check()) {
    				$result = $this->model->ChangeDisciplineHours(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID'),
    					$this->post->offsetGet('Hours'),
    					$this->post->offsetGet('Type')	
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    	// ----------------
    		
    		// Список предметов по первым буквам
    		public function action_GetSubjectsList()
    		{
    			$data['success'] = false;
                $this->post -> rule('FacultyID', 'not_empty')
                            -> rule('FacultyID', 'digit');
                if($this->post->check()) {
    				$SubjectsList = DataArray::factory('Subjects')->byFaculty($this->post->offsetGet('FacultyID'))->asJSON();
    				$data['success'] = true;
    			}
    			$this->response->body($SubjectsList);
    		}
    		
    		// Добавить модуль и к модулю 1 мероприятие
    		public function action_AddModule(){
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit');
                if($this->post->check()) {
    				// Добавление модуля
                    $result = $this->model->AddModule(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('DisciplineID'),
    					''
    				);
    				$data['moduleID'] = $result[0]['Num'];
    				if ($data['moduleID'] > 0) {
    					// Добавление мероприятия
    					// Т.к. модуль должен содержать хотя бы
    					// 1 мероприятие
    					$result = $this->model->AddSubmodule(
    						$this->user['TeacherID'],
    						$data['moduleID'],
    						'0', //MaxRate
    						'',
    						'', //Description
    						'CurrentControl'
    					);
    					$data['submoduleID'] = $result[0]['Num'];
    					if ($data['submoduleID'] > 0)
    						$data['success'] = true;
    				}
    					
                }
    			$this->response->body(json_encode($data));
    		}
    		
    		// Добавление мероприятия
    		public function action_AddSubmodule() {
    			$data['success'] = false;
    			return;
                $this->post -> rule('submoduleID', 'not_empty')
                            -> rule('submoduleID', 'digit');
                if($this->post->check()) {
    					$result = $this->model->AddSubmodule(
    						$this->user['TeacherID'],
    						$this->post->offsetGet('submoduleID'),
    						'0', //MaxRate
    						'',
    						'', //Description
    						'CurrentControl'
    					);
    					$data['submoduleID'] = $result[0]['Num'];
    					if ($data['submoduleID'] > 0)
    						$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Поменять имя модуля
    		public function action_ChangeModuleName() {
    			$data['success'] = false;
                $this->post -> rule('ModuleID', 'not_empty')
                            -> rule('ModuleID', 'digit')
    						-> rule('ModuleName', 'not_empty');
                if($this->post->check()) {
                    $result = $this->model->ChangeModuleName($this->user['TeacherID'], $this->post->offsetGet('ModuleID'), $this->post->offsetGet('ModuleName'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Поменять имя мероприятия
    		public function action_ChangeSubmoduleName() {
    			$data['success'] = false;
                $this->post -> rule('SubmoduleID', 'not_empty')
                            -> rule('SubmoduleID', 'digit')
    						-> rule('SubmoduleName', 'not_empty');
                if($this->post->check()) {
                    $result = $this->model->ChangeSubmoduleName($this->user['TeacherID'], $this->post->offsetGet('SubmoduleID'), $this->post->offsetGet('SubmoduleName'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    		
    		// СВАП порядка двух модулей
    		public function action_SwapModuleOrder() {
    			$data['success'] = false;
                $this->post -> rule('ModuleID1', 'not_empty')
                            -> rule('ModuleID1', 'digit')
    						-> rule('ModuleID2', 'not_empty')
    						-> rule('ModuleID2', 'digit');
                if($this->post->check()) {
    				$result = $this->model->SwapModuleOrder(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('ModuleID1'),
    					$this->post->offsetGet('ModuleID2')
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
    			}
    			$this->response->body(json_encode($data));
    		}
    		
    		// Свап порядка двух мероприятий
    		public function action_SwapSubmoduleOrder(){
    			$data['success'] = false;
                $this->post -> rule('SubmoduleID1', 'not_empty')
                            -> rule('SubmoduleID1', 'digit')
    						-> rule('SubmoduleID2', 'not_empty')
    						-> rule('SubmoduleID2', 'digit');
                if($this->post->check()) {
    				$result = $this->model->SwapSubmoduleOrder(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('SubmoduleID1'),
    					$this->post->offsetGet('SubmoduleID2')
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
                $this->response->body(json_encode($data));
    		}
    		
    		// Удалить модуль и его мероприятия
    		public function action_DeleteModule() {
    			$data['success'] = false;
                $this->post -> rule('ModuleID', 'not_empty')
                            -> rule('ModuleID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->deleteModule(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('ModuleID')
    				);
    				$data['success'] = ($result[0]['Num'] == 0);
                }
                $this->response->body(json_encode($data));
            }
    		
    		// Удалить мероприятие
    		public function action_DeleteSubmodule() {
    			$data['success'] = false;
                $this->post -> rule('SubmoduleID', 'not_empty')
                            -> rule('SubmoduleID', 'digit');
                if($this->post->check()) {
                    $result = $this->privateDeleteSubmodule($this->post->offsetGet('SubmoduleID'));
    				$data['success'] = ($result == 0);
    			}
    			$this->response->body(json_encode($data));
            }
    
    		public function action_ChangeSubmoduleMaxAndControl() {
    			$data['success'] = false;
                $this->post -> rule('SubmoduleID', 'not_empty')
                            -> rule('SubmoduleID', 'digit')
    						-> rule('MaxRate', 'not_empty')
    						-> rule('ControlType', 'not_empty');
                if($this->post->check()) {
                     $result = $this->model->ChangeSubmoduleMaxAndControl(
    					$this->user['TeacherID'],
    					$this->post->offsetGet('SubmoduleID'), 
    					$this->post->offsetGet('MaxRate'),
    					$this->post->offsetGet('ControlType')
    				);
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    	
    		// Прикрепить группу
    		public function action_BindGroup() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('StudyGroupID', 'not_empty')
    						-> rule('StudyGroupID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->BindGroup($this->user['TeacherID'], $this->post->offsetGet('DisciplineID'), $this->post->offsetGet('StudyGroupID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    	
    		// Отсоединить группу
    		public function action_UnbindGroup() {
    			$data['success'] = false;
                $this->post -> rule('DisciplineID', 'not_empty')
                            -> rule('DisciplineID', 'digit')
    						-> rule('StudyGroupID', 'not_empty')
    						-> rule('StudyGroupID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->UnbindGroup($this->user['TeacherID'], $this->post->offsetGet('DisciplineID'), $this->post->offsetGet('StudyGroupID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    	
    		// Прикрепить студента
    		public function action_BindStudent() {
    			$data['success'] = false;
                $this->post -> rule('StudentID', 'not_empty')
                            -> rule('StudentID', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->BindStudent($this->user['TeacherID'], $this->post->offsetGet('DisciplineID'), $this->post->offsetGet('StudentID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    		
    		// Отсоединить студента 
    		public function action_UnbindStudent() {
    			$data['success'] = false;
                $this->post -> rule('StudentID', 'not_empty')
                            -> rule('StudentID', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->UnbindStudent($this->user['TeacherID'], $this->post->offsetGet('DisciplineID'), $this->post->offsetGet('StudentID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    		
    		// Получаем список групп
    		public function action_GetStudyGroups() {
    			$this->post -> rule('GradeID', 'digit')
    						-> rule('FacultyID', 'digit');
    			if($this->post->check()) {
    				$Groups = DataArray::factory('StudyGroups')->ordByGroups($this->post->offsetGet('GradeID'), $this->post->offsetGet('FacultyID'))->asJSON();
                }
    			$this->response->body($Groups);
    		}
    		
    		// Поиск студентов
     		public function action_SearchStudents() {
    			$this->post -> rule('GradeID', 'digit')
    						-> rule('GroupN', 'digit')
    						-> rule('FacultyID', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
    			if($this->post->check()) {	
    				$SearchResult = DataArray::factory('Students')
    				->NotAttendingDiscipline(
    					$this->post->offsetGet('GradeID'),
    					$this->post->offsetGet('GroupN'),
    					$this->post->offsetGet('FacultyID'),
    					$this->post->offsetGet('Last'),
    					$this->post->offsetGet('First'),
    					$this->post->offsetGet('Second'),
    					$this->post->offsetGet('DisciplineID')
    				)->asJSON();
    			}
    			$this->response->body($SearchResult);
    		}
    		
    		
    		// Прикрепить преподавателя 
    		public function action_BindTeacher() {
    			$data['success'] = false;
                $this->post -> rule('BindingTeacher', 'not_empty')
                            -> rule('BindingTeacher', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->BindTeacher($this->user['TeacherID'], $this->post->offsetGet('BindingTeacher'), $this->post->offsetGet('DisciplineID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    		
    		// Отсоединить преподавателя 
    		public function action_UnbindTeacher() {
    			$data['success'] = false;
                $this->post -> rule('BindingTeacher', 'not_empty')
                            -> rule('BindingTeacher', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
                if($this->post->check()) {
                    $result = $this->model->UnbindTeacher($this->user['TeacherID'], $this->post->offsetGet('BindingTeacher'), $this->post->offsetGet('DisciplineID'));
    				if ($result[0]['Num'] == 0)
    					$data['success'] = true;
                }
    			$this->response->body(json_encode($data));
    		}
    
    		// Получаем список кафедр 
    		public function action_GetDepartments() {
                $this->post -> rule('FacultyID', 'not_empty')
                            -> rule('FacultyID', 'digit');
                if($this->post->check()) {
    				$DepList = DataArray::factory('Departments')->byFaculty($this->post->offsetGet('FacultyID'))->asJSON();
                }
    			$this->response->body($DepList);
    		}
    		
    		// Поиск преподавателей
    		public function action_SearchTeachers() {
    			$this->post -> rule('DepartmentID', 'digit')
    						-> rule('DisciplineID', 'not_empty')
    						-> rule('DisciplineID', 'digit');
    			if($this->post->check()) {
    				$SeResult = $this->model->SearchTeacherNew(
    					$this->post->offsetGet('FacultyID'),
    					$this->post->offsetGet('DepartmentID'),
    					$this->post->offsetGet('Last'),
    					$this->post->offsetGet('First'),
    					$this->post->offsetGet('Second'),
    					$this->post->offsetGet('DisciplineID')
    				); 
    				$SearchResult = array();
    				$i = 0;
    				foreach($SeResult as $row){
    					$i++;
    					$SearchResult[$i]['TeacherID'] = $row['TeacherID'];
    					$SearchResult[$i]['TeacherLast'] = $row['TeacherLast'];
    					$SearchResult[$i]['TeacherFirst'] = $row['TeacherFirst'];
    					$SearchResult[$i]['TeacherSecond'] = $row['TeacherSecond'];
    					$SearchResult[$i]['JobPositionName'] = $row['JobPositionName'];
    					$SearchResult[$i]['DepID'] = $row['DepID'];
    				}
    				
    			}
    			$this->response->body(json_encode($SearchResult));
    		}
    }