From f1e8c533ef929c2bb23daa85f42e1104f442450a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A8=D0=B0=D0=BB=D0=B8?=
 =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= <solidovic@gmail.com>
Date: Sun, 5 Oct 2014 12:20:47 +0400
Subject: [PATCH] =?UTF-8?q?fix=20(=D0=B5=D1=89=D0=B5=20=D0=BC=D0=B0=D0=BB?=
 =?UTF-8?q?=D0=BE=20=D1=87=D1=82=D0=BE=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20?=
 =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=82=D1=8C)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../classes/Controller/Teacher/Discipline.php |  3 +-
 .../application/classes/DataArr/Students.php  | 45 +++++--------------
 .../classes/DataArr/StudyGroups.php           |  2 -
 .../application/classes/DataArr/Subjects.php  |  1 -
 .../application/classes/DataArr/Teachers.php  |  2 +
 .../teacher/discipline/EditStudents.twig      |  2 +-
 .../teacher/discipline/EditTeachers.twig      | 10 +----
 ~dev_rating/media/js/discipline/general.js    | 16 ++++++-
 8 files changed, 30 insertions(+), 51 deletions(-)

diff --git a/~dev_rating/application/classes/Controller/Teacher/Discipline.php b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
index c0c22e85d..c9f6ee4c1 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Discipline.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
@@ -21,7 +21,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi {
         $twig = Twig::factory('teacher/discipline/EditSettings');
 		
 		$twig->User = $this->UserInfo;
-		
+
 		$twig->FacultiesList = DataArray::factory('Faculties')->common()->asArray();
         $twig->Discipline = $this->GetDisciplineInfo($db, $id);
         $twig->SubjectsList = DataArray::factory('Subjects')->byFaculty($this->UserInfo['FacultyID'])->asArray();
@@ -84,7 +84,6 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi {
 		$twig->BindTeachersList = DataArray::factory('Teachers')->forDiscipline($id)->asArray();
 		$twig->FacultiesList = DataArray::factory('Faculties')->common()->asArray();
 		$twig->Departments = DataArray::factory('Departments')->byFaculty($this->UserInfo['FacultyID'])->asArray();
-		//$twig->TeachersList = $this->GetTeachersByDepartment($db, $twig->Discipline['DepID']);
 		
 		$this->response->body($twig);
 	}
diff --git a/~dev_rating/application/classes/DataArr/Students.php b/~dev_rating/application/classes/DataArr/Students.php
index 4ee82dd23..24cb97bc9 100644
--- a/~dev_rating/application/classes/DataArr/Students.php
+++ b/~dev_rating/application/classes/DataArr/Students.php
@@ -47,20 +47,23 @@ class DataArr_Students {
     
     protected function generateArray($students)
     {
+        // AddCount - не всегда требуется возвращать кол-во
         $studentsHandled = array(); $i = 0;
         foreach($students as $row)
         {
             $i++;
             $studentsHandled[$i]['ID'] = $row['StudentID'];
             $studentsHandled[$i]['AccountID'] = $row['StudentAccID'];
-            $studentsHandled[$i]['LastName'] = $row['StudentLast'];
-            $studentsHandled[$i]['FirstName'] = $row['StudentFirst'];
-            $studentsHandled[$i]['SecondName'] = $row['StudentSecond'];
+            $studentsHandled[$i]['LastName'] = $row['LastName'];
+            $studentsHandled[$i]['FirstName'] = $row['FirstName'];
+            $studentsHandled[$i]['SecondName'] = $row['SecondName'];
             $studentsHandled[$i]['GroupID'] = $row['GroupID'];
-            $studentsHandled[$i]['GradeID'] = $row['GradeID'];
+            $studentsHandled[$i]['GroupNum'] = $row['GroupNum'];
+            $studentsHandled[$i]['GradeID'] = $row['GradeID']; // ID РєСѓСЂСЃР°
+            $studentsHandled[$i]['Grade'] = $row['Grade']; // НОМЕР курса, а не ID... ID почти всегда <> НОМЕРУ курса
             $studentsHandled[$i]['GradeNum'] = $row['GroupGrade'];
             $studentsHandled[$i]['Degree'] = $this->getDegreeTitle($row['GroupDegree']);
-            $studentsHandled[$i]['GroupNum'] = $row['GroupNum'];
+            $studentsHandled[$i]['Type'] = $row['Type'];
         }
         return $studentsHandled;
     }
@@ -68,40 +71,12 @@ class DataArr_Students {
     public function forDiscipline($TeacherID, $DisciplineID)
     {
         $students = $this->model->getStudentsForDiscipline($TeacherID, $DisciplineID);
-        $studentsHandled = array();
-        $i = 0;
-        
-        foreach($students as $row) {
-            $i++;
-            $studentsHandled[$i]['StudentID'] = $row['StudentID'];
-            $studentsHandled[$i]['LastName'] = $row['LastName'];
-            $studentsHandled[$i]['FirstName'] = $row['FirstName'];
-            $studentsHandled[$i]['SecondName'] = $row['SecondName'];
-            $studentsHandled[$i]['Grade'] = $row['Grade'];
-            $studentsHandled[$i]['GroupNum'] = $row['GroupNum'];
-            $studentsHandled[$i]['Type'] = $row['Type'];
-            $studentsHandled[$i]['GroupID'] = $row['GroupID'];
-        }
-        return new DataArray_Result($studentsHandled);
+        return new DataArray_Result($this->generateArray($students));
     }
 
     public function NotAttendingDiscipline($GradeID, $GroupN, $FacultyID, $Last, $First, $Second, $DisciplineID)
     {
         $students = $this->model->getStudentsForDiscipline($GradeID, $GroupN, $FacultyID, $Last, $First, $Second, $DisciplineID);
-        $studentsHandled = array();
-        $i = 0;
-        
-        foreach($students as $row) {
-            $i++;
-            $studentsHandled[$i]['StudentID'] = $row['StudentID'];
-            $studentsHandled[$i]['StudentLast'] = $row['StudentLast'];
-            $studentsHandled[$i]['StudentFirst'] = $row['StudentFirst'];
-            $studentsHandled[$i]['StudentSecond'] = $row['StudentSecond'];
-            $studentsHandled[$i]['GroupGrade'] = $row['GroupGrade'];
-            $studentsHandled[$i]['GroupNum'] = $row['GroupNum'];
-            $studentsHandled[$i]['GroupID'] = $row['GroupID'];
-        }
-         $studentsHandled['count'] = $i;
-        return new DataArray_Result($studentsHandled);
+        return new DataArray_Result($this->generateArray($students));
     }
 }
diff --git a/~dev_rating/application/classes/DataArr/StudyGroups.php b/~dev_rating/application/classes/DataArr/StudyGroups.php
index f7b4831d2..72c4aaf2e 100644
--- a/~dev_rating/application/classes/DataArr/StudyGroups.php
+++ b/~dev_rating/application/classes/DataArr/StudyGroups.php
@@ -22,7 +22,6 @@ class DataArr_StudyGroups {
 			$GroupsHandled[$i]['SpecName'] = $row['SpecName'];
 			$GroupsHandled[$i]['SpecAbbr'] = $row['SpecAbbr'];
 		}
-		$GroupsHandled['count'] = $i;
 		
 		return new DataArray_Result($GroupsHandled);
 	}
@@ -40,7 +39,6 @@ class DataArr_StudyGroups {
 			$GroupsHandled[$i]['SpecName'] = $row['SpecName'];
 			$GroupsHandled[$i]['SpecAbbr'] = $row['SpecAbbr'];
 		}
-		$GroupsHandled['count'] = $i;
 		
 		return new DataArray_Result($GroupsHandled);
 	}
diff --git a/~dev_rating/application/classes/DataArr/Subjects.php b/~dev_rating/application/classes/DataArr/Subjects.php
index c497ff8e0..86f7d417e 100644
--- a/~dev_rating/application/classes/DataArr/Subjects.php
+++ b/~dev_rating/application/classes/DataArr/Subjects.php
@@ -19,7 +19,6 @@ class DataArr_Subjects {
 			$SubjectsList[$i]['Title'] = $row['SubjectName'];
 			$SubjectsList[$i]['Abbr'] = $row['SubjectAbbr'];
 		}
-		$SubjectsList['Count'] = $i;
 	
 		return new DataArray_Result($SubjectsList);
 	}
diff --git a/~dev_rating/application/classes/DataArr/Teachers.php b/~dev_rating/application/classes/DataArr/Teachers.php
index a1286fed0..37ad7bd82 100644
--- a/~dev_rating/application/classes/DataArr/Teachers.php
+++ b/~dev_rating/application/classes/DataArr/Teachers.php
@@ -55,6 +55,8 @@ class DataArr_Teachers {
         foreach ($teachers as $teacher)
         {
             $i++; $tchr = array();
+            $tchr['isAuthor'] = $teacher['isAuthor'];
+            $tchr['TeacherID'] = $teacher['TeacherID'];
             $tchr['LastName'] = $teacher['TeacherLast'];
             $tchr['FirstName'] = $asInitials ? 
                     UTF8::substr($teacher['TeacherFirst'], 0, 1).'. ' : $teacher['TeacherFirst'];
diff --git a/~dev_rating/application/views/teacher/discipline/EditStudents.twig b/~dev_rating/application/views/teacher/discipline/EditStudents.twig
index 1b9e26ec1..846169951 100644
--- a/~dev_rating/application/views/teacher/discipline/EditStudents.twig
+++ b/~dev_rating/application/views/teacher/discipline/EditStudents.twig
@@ -24,7 +24,7 @@
 				<div class="GroupContainer GroupID_{{ Student.GroupID }}">
 					{% set NowGroupNum = Student.GroupNum %}
 			{% endif %}
-				<div id="{{ Student.StudentID }}" class="Student {% if Student.Type == 'detach' %}StatusUnbind{% else %}StatusBind{% endif %}">
+				<div id="{{ Student.ID }}" class="Student {% if Student.Type == 'detach' %}StatusUnbind{% else %}StatusBind{% endif %}">
 					<span class="Name">{{ Student.LastName }} {{ Student.FirstName }} {{ Student.SecondName }}</span>
 					{% if Student.Type == 'detach' %}
 						<button class="action Action_BindStudent">Прикрепить студента</button>
diff --git a/~dev_rating/application/views/teacher/discipline/EditTeachers.twig b/~dev_rating/application/views/teacher/discipline/EditTeachers.twig
index 4576dc0fd..ba9cddb7a 100644
--- a/~dev_rating/application/views/teacher/discipline/EditTeachers.twig
+++ b/~dev_rating/application/views/teacher/discipline/EditTeachers.twig
@@ -12,7 +12,7 @@
 		<h2 class="BlueTitle">Прикрепленные преподаватели</h2>
 		{% for Teacher in BindTeachersList %}
 			<div class="Teacher" id="{{ Teacher.TeacherID }}">
-				<div class="Name">{{ Teacher.TeacherLast }} {{ Teacher.TeacherFirst }} {{ Teacher.TeacherSecond }}</div>
+				<div class="Name">{{ Teacher.LastName }} {{ Teacher.FirstName }} {{ Teacher.SecondName }}</div>
 				{% if Teacher.isAuthor == 0 %}
 					<button class="Action_UnbindTeacher Action">Отсоединить</button>
 					<button class="Action_ChangeOwner Action">Передать дисциплину</button>
@@ -34,18 +34,12 @@
 				<select class="SelectDepartment default_select">
 					<option value="0">Выберите кафедру (не обязательно)</option>
 					{% for Dep in Departments %}
-						<option value="{{ Dep.DepID }}">{{ Dep.DepName }}</option>
+						<option value="{{ Dep.ID }}">{{ Dep.Name }}</option>
 					{% endfor %}
 				</select>
 				<input tupe="text" class="InputTeacherName default_input_text" placeholder="Фамилия Имя Отчество" value="">
 			</div>
 			<div class="SearchResult">
-				{% for Teacher in TeachersList %}
-					<div class="Teacher" id="{{ Teacher.TeacherID }}">
-						<div class="Name">{{ Teacher.TeacherLast }} {{ Teacher.TeacherFirst }} {{ Teacher.TeacherSecond }}</div>
-						<button class="Action_BindTeacher Action">Присоединить</button>
-					</div>
-				{% endfor %}
 			</div>
 		</div>
 	</div>
diff --git a/~dev_rating/media/js/discipline/general.js b/~dev_rating/media/js/discipline/general.js
index 29a1c35fe..179c0b727 100644
--- a/~dev_rating/media/js/discipline/general.js
+++ b/~dev_rating/media/js/discipline/general.js
@@ -25,7 +25,7 @@ $(function() {
 			function(data)
 			{
 				SubjectsGlobal = $.parseJSON(data);
-				//console.log(SubjectsGlobal); // *
+				console.log(SubjectsGlobal); // *
 			}
 		);
 	}
@@ -37,7 +37,18 @@ $(function() {
 		var NameFilter = NameFilter.toLowerCase();
 		var SortSubjects = {};
 		var j = 0;
-		var SubjectCount = SubjectsGlobal.Count;
+		for (var i in SubjectsGlobal) { 
+			src = SubjectsGlobal[i];
+			if ((src.Title).toLowerCase().indexOf(NameFilter) == 0)
+			{
+				// 0 - успех, -1 - ничего не нашел 
+				var dest = SortSubjects[j] = {};
+				dest['ID'] = src.ID;
+				dest['Title'] = src.Title;
+				j++;
+			}
+		}
+		/*
 		for (var i = SubjectCount - 1; i >= 0; --i)
 		{
 			src = SubjectsGlobal[i];
@@ -50,6 +61,7 @@ $(function() {
 				j++;
 			}
 		}
+		*/
 		SortSubjects.Count = j;
 		//console.log(SortSubjects); // *
 		
-- 
GitLab