From 20770fa0e09aed044c68626b38ae8c69bb28251b Mon Sep 17 00:00:00 2001
From: xamgore <xamgore@ya.ru>
Date: Mon, 9 Mar 2015 22:14:31 +0300
Subject: [PATCH] Unified Model_Departments class added

---
 .../Controller/Handler/AdmTeachers.php        |  2 +-
 .../classes/Controller/Handler/Map.php        |  2 +-
 .../classes/Controller/Handler/Settings.php   |  2 +-
 .../classes/Controller/Teacher/Discipline.php |  2 +-
 .../classes/Controller/Teacher/Profile.php    |  2 +-
 .../classes/DataArr/Departments.php           |  4 ++-
 .../classes/Model/DataArr/Departments.php     |  4 ++-
 .../application/classes/Model/Departments.php | 26 +++++++++++++++++++
 8 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 ~dev_rating/application/classes/Model/Departments.php

diff --git a/~dev_rating/application/classes/Controller/Handler/AdmTeachers.php b/~dev_rating/application/classes/Controller/Handler/AdmTeachers.php
index 6f210c34b..f667341bc 100644
--- a/~dev_rating/application/classes/Controller/Handler/AdmTeachers.php
+++ b/~dev_rating/application/classes/Controller/Handler/AdmTeachers.php
@@ -80,6 +80,6 @@ class Controller_Handler_AdmTeachers extends Controller_Handler {
         public function action_getDepartmentsList()
         {
             $facultyID = $this->post->offsetGet('facultyID');
-            $this->response->body(DataArray::factory('Departments')->byFaculty($facultyID)->asJSON());
+            $this->response->body(Model_Departments::factory()->byFaculty($facultyID)->asJSON());
         }
 }
\ No newline at end of file
diff --git a/~dev_rating/application/classes/Controller/Handler/Map.php b/~dev_rating/application/classes/Controller/Handler/Map.php
index da4e3b66f..c64336996 100644
--- a/~dev_rating/application/classes/Controller/Handler/Map.php
+++ b/~dev_rating/application/classes/Controller/Handler/Map.php
@@ -516,7 +516,7 @@ class Controller_Handler_Map extends Controller_Handler {
             $this->post -> rule('FacultyID', 'not_empty')
                         -> rule('FacultyID', 'digit');
             if($this->post->check()) {
-				$DepList = DataArray::factory('Departments')->byFaculty($this->post->offsetGet('FacultyID'))->asJSON();
+				$DepList = Model_Departments::factory()->byFaculty($this->post->offsetGet('FacultyID'))->asJSON();
             }
 			$this->response->body($DepList);
 		}
diff --git a/~dev_rating/application/classes/Controller/Handler/Settings.php b/~dev_rating/application/classes/Controller/Handler/Settings.php
index aa184f91c..60e4a9444 100644
--- a/~dev_rating/application/classes/Controller/Handler/Settings.php
+++ b/~dev_rating/application/classes/Controller/Handler/Settings.php
@@ -80,7 +80,7 @@ class Controller_Handler_Settings extends Controller_Handler {
         public function action_getDepartmentsList()
         {
             $facultyID = $this->post->offsetGet('facultyID');
-            $deps = DataArray::factory('Departments')->byFaculty($facultyID)->asArray();
+            $deps = Model_Departments::factory()->byFaculty($facultyID)->asArray();
             $this->response->body(json_encode($deps));  
         }
         
diff --git a/~dev_rating/application/classes/Controller/Teacher/Discipline.php b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
index a30cc2c9f..cd99179d0 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Discipline.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
@@ -146,7 +146,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi {
         $twig->Discipline = $this->getDisciplineInfo($db, $id);
         $twig->BindTeachersList = Model_Teachers::factory()->forDiscipline($id)->asArray();
         $twig->FacultiesList = Model_Faculties::factory()->common()->asArray();
-        $twig->Departments = DataArray::factory('Departments')->byFaculty($this->UserInfo['FacultyID'])->asArray();
+        $twig->Departments = Model_Departments::factory()->byFaculty($this->UserInfo['FacultyID'])->asArray();
         
         $this->response->body($twig);
     }
diff --git a/~dev_rating/application/classes/Controller/Teacher/Profile.php b/~dev_rating/application/classes/Controller/Teacher/Profile.php
index 587a234a5..fc2cb84ae 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Profile.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Profile.php
@@ -6,7 +6,7 @@ class Controller_Teacher_Profile extends Controller_UserEnvi {
         $twig = Twig::factory('profile/settings');
         $twig->JobPositions = $this->getJobPositions();
         $twig->Faculties = $this->getFaculties();
-        $twig->Departments = DataArray::factory('Departments')->byFaculty($this->UserInfo['FacultyID'])->asArray();
+        $twig->Departments = Model_Departments::factory()->byFaculty($this->UserInfo['FacultyID'])->asArray();
         $twig->User = $this->UserInfo;
         $this->response->body($twig);
     }
diff --git a/~dev_rating/application/classes/DataArr/Departments.php b/~dev_rating/application/classes/DataArr/Departments.php
index ca529798b..b4447bf45 100644
--- a/~dev_rating/application/classes/DataArr/Departments.php
+++ b/~dev_rating/application/classes/DataArr/Departments.php
@@ -1,12 +1,14 @@
 <?php
 
+/** @deprecated use Model_Departments instead. */
 class DataArr_Departments {
     protected $model;
     
     public function __construct() {
         $this->model = new Model_DataArr_Departments;
     }
-    
+
+    /** @deprecated */
     public function byFaculty($facultyID)
     {
         if($facultyID != 0)
diff --git a/~dev_rating/application/classes/Model/DataArr/Departments.php b/~dev_rating/application/classes/Model/DataArr/Departments.php
index 6d0007605..8f372f19a 100644
--- a/~dev_rating/application/classes/Model/DataArr/Departments.php
+++ b/~dev_rating/application/classes/Model/DataArr/Departments.php
@@ -1,7 +1,9 @@
 <?php defined('SYSPATH') or die('No direct script access.');
-  
+
+/** @deprecated use Model_Departments instead. */
 class Model_DataArr_Departments extends Model
 {
+    /** @deprecated */
     public function getDepartmentsByFaculty($facultyID)
     {
         $sql = "CALL `GetDepartments`('$facultyID'); ";
diff --git a/~dev_rating/application/classes/Model/Departments.php b/~dev_rating/application/classes/Model/Departments.php
new file mode 100644
index 000000000..de4f86b6d
--- /dev/null
+++ b/~dev_rating/application/classes/Model/Departments.php
@@ -0,0 +1,26 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Model_Departments extends Model
+{
+    public static function factory() {
+        return new self();
+    }
+
+    public function getDepartmentsByFaculty($facultyID) {
+        $sql = "CALL `GetDepartments`('$facultyID'); ";
+        return DB::query(Database::SELECT, $sql)->execute();
+    }
+
+    public function byFaculty($facultyID) {
+        if ($facultyID != 0) {
+            $departments = $this->getDepartmentsByFaculty($facultyID);
+            $list = array();
+            foreach ($departments as $row) {
+                if ($row['Name'] == null)
+                    $row['Name'] = '<служебная кафедра>';
+                $list = $row;
+            }
+            return new DataArray_Result($list);
+        }
+    }
+}
-- 
GitLab