From 847a708e8aab3ab36ac1664294f54fb56c597770 Mon Sep 17 00:00:00 2001
From: xamgore <xamgore@ya.ru>
Date: Wed, 18 Mar 2015 04:33:07 +0300
Subject: [PATCH] Improved semester model (static access)

---
 .../classes/Controller/Student/Subject.php            |  2 +-
 .../classes/Controller/Teacher/Discipline.php         |  2 +-
 .../application/classes/Controller/UserEnvi.php       |  3 +--
 ~dev_rating/application/classes/Model/Semesters.php   | 11 +++++------
 ~dev_rating/application/classes/Model/Student.php     |  6 ------
 5 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/~dev_rating/application/classes/Controller/Student/Subject.php b/~dev_rating/application/classes/Controller/Student/Subject.php
index 394c09e01..2f6b8510a 100644
--- a/~dev_rating/application/classes/Controller/Student/Subject.php
+++ b/~dev_rating/application/classes/Controller/Student/Subject.php
@@ -28,7 +28,7 @@ class Controller_Student_Subject extends Controller_UserEnvi {
 		$subject['LabCount'] = $info['LabCount'];
         $subject['DepName'] = $info['DepName'];
         $subject['Teachers'] = $this->getTeachersForDiscipline($id);
-        $semester = $db->getSemesterInfo($info['SemesterID']);
+        $semester = Model_Semesters::getInfo($info['SemesterID']);
         $semester['Num'] = $semester['Num'] == 1 ? 'Осенний' : 'Весенний';
         $subject['Num'] = $semester['Num'];
         $subject['Year'] = $semester['Year'];
diff --git a/~dev_rating/application/classes/Controller/Teacher/Discipline.php b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
index dc084a727..2e3b83551 100644
--- a/~dev_rating/application/classes/Controller/Teacher/Discipline.php
+++ b/~dev_rating/application/classes/Controller/Teacher/Discipline.php
@@ -219,7 +219,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi {
         $subject['IsBonus'] = $info['IsBonus'];
         
         $subject['SemesterID'] = $info['SemesterID'];
-        $semester = Model_Semesters::create()->bySemester($subject['SemesterID'])->asArray();
+        $semester = Model_Semesters::getInfo($subject['SemesterID']);
         $subject['SemesterNum'] = $semester['SemesterNum'] == 1 ? 'Осенний' : 'Весенний';
         $subject['SemesterYear'] = $semester['SemesterYear'];
         
diff --git a/~dev_rating/application/classes/Controller/UserEnvi.php b/~dev_rating/application/classes/Controller/UserEnvi.php
index d90bfd4a0..ce27dc640 100644
--- a/~dev_rating/application/classes/Controller/UserEnvi.php
+++ b/~dev_rating/application/classes/Controller/UserEnvi.php
@@ -13,8 +13,7 @@ class Controller_UserEnvi extends Controller {
         } 
         $this->UserInfo = $user->getInfoAsArray();
 
-        $db = new Model_Student;
-        $semester = $db->getSemesterInfo($this->UserInfo['SemesterID']);
+        $semester = Model_Semesters::getInfo($this->UserInfo['SemesterID']);
         // $semester['Num'] = $semester['Num'] == 1 ? 'Осень' : 'Весна';
         if($semester['Num'] == 1)
         {
diff --git a/~dev_rating/application/classes/Model/Semesters.php b/~dev_rating/application/classes/Model/Semesters.php
index ffd8ac102..3180f1afb 100644
--- a/~dev_rating/application/classes/Model/Semesters.php
+++ b/~dev_rating/application/classes/Model/Semesters.php
@@ -6,7 +6,11 @@ class Model_Semesters extends Model
         return new self();
     }
 
-    public function getSemesterInfo($id) {
+    /**
+     * @param $id int semester id
+     * @return array data from <tt>semesters</tt> table
+     */
+    public static function getInfo($id) {
         $sql = "CALL `GetSemesterInfo`('$id'); ";
         return DB::query(Database::SELECT, $sql)->execute()->offsetGet(0);
     }
@@ -16,11 +20,6 @@ class Model_Semesters extends Model
         return DB::query(Database::SELECT, $sql)->execute();
     }
 
-    public function bySemester($SemesterID) {
-        $departments = $this->getSemesterInfo($SemesterID);
-        return new DataArray_Result($departments);
-    }
-
     public function getList() {
         $semesters = $this->getSemesters();
         $list = array();
diff --git a/~dev_rating/application/classes/Model/Student.php b/~dev_rating/application/classes/Model/Student.php
index 5298123b7..e269a417b 100644
--- a/~dev_rating/application/classes/Model/Student.php
+++ b/~dev_rating/application/classes/Model/Student.php
@@ -7,10 +7,4 @@ class Model_Student extends Model
         $sql = "CALL `GetRates`('$student_id', '$subject_id'); ";
         return DB::query(Database::SELECT, $sql)->execute();
     }
-    
-    public function getSemesterInfo($id) // TODO: перенести в common.php
-    {
-        $sql = "CALL `GetSemesterInfo`('$id'); ";
-        return DB::query(Database::SELECT, $sql)->execute()->offsetGet(0);
-    }   
 }
-- 
GitLab