<?php defined('SYSPATH') or die('No direct script access.'); class Controller_Teacher_Index extends Controller_UserEnvi { public function action_index() { $twig = Twig::factory('teacher/index'); $model = new Model_Teacher_Index; $disciplines = $model->getDisciplinesForTeacher($this->UserInfo['TeacherID']); $subjectsHandled = array(); $subjID = $discID = $i = $j = $k = 0; foreach ($disciplines as $row) { if($subjID != $row['SubjectID']) { $i++; $j = $k = 0; $subjID = $row['SubjectID']; } $subjectsHandled['Subjects'][$i]['Title'] = $row['SubjectName']; if($discID != $row['DisciplineID']) { $j++; $k = 0; $discID = $row['DisciplineID']; } $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['ID'] = $row['DisciplineID']; $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['GradeNum'] = $row['StudyGroupGrade']; $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['ControlType'] = $this->getControlType($row['DisciplineType']); $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['Teachers'] = $this->getTeachersForDiscipline($discID); $k++; $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['Groups'][$k]['Count'] = 10; $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['Groups'][$k]['Num'] = $row['StudyGroupNum']; $subjectsHandled['Subjects'][$i]['Disciplines'][$j]['Groups'][$k]['ID'] = $row['StudyGroupID']; } $twig->content = $subjectsHandled; $twig->User = $this->UserInfo; $this->response->body($twig); } public function action_settings() { $twig = Twig::factory('settings'); $twig->User = $this->UserInfo; $this->response->body($twig); } protected function getControlType($type) { if($type == 'exam') { return 'Экзамен'; } elseif($type == 'credit') { return 'Зачет'; } } protected function getTeachersForDiscipline($id) { $model = new Model_Teacher_Index; $teachers = $model->getTeachersForDiscipline($id); $teachersHandled = array(); $i = 0; foreach ($teachers as $teacher) { $i++; $teachersHandled[$i] = $teacher['TeacherLast'].' '.UTF8::substr($teacher['TeacherFirst'], 0, 1).'. '; if(!empty($teacher['TeacherSecond'])) { $teachersHandled[$i] .= UTF8::substr($teacher['TeacherSecond'], 0, 1).'.'; } } return $teachersHandled; } }