From 21a69d363e2f289d861232286bae4acfaa5e8931 Mon Sep 17 00:00:00 2001 From: xamgore <xamgore@ya.ru> Date: Wed, 18 Mar 2015 14:33:20 +0300 Subject: [PATCH] Removed `create` method from Grades model --- .../classes/Controller/Admin/Accounts.php | 2 +- .../classes/Controller/Admin/Students.php | 4 ++-- .../classes/Controller/DeanOffice/Index.php | 2 +- .../classes/Controller/Teacher/Discipline.php | 6 +++--- .../application/classes/Model/Grades.php | 19 ++++++++----------- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/~dev_rating/application/classes/Controller/Admin/Accounts.php b/~dev_rating/application/classes/Controller/Admin/Accounts.php index 2f6985dc5..93cfbbcc0 100644 --- a/~dev_rating/application/classes/Controller/Admin/Accounts.php +++ b/~dev_rating/application/classes/Controller/Admin/Accounts.php @@ -16,7 +16,7 @@ class Controller_Admin_Accounts extends Controller_UserEnvi { Cookie::set('fD', 'true'); $twig = Twig::factory('admin/accounts/codes'); $twig->Faculties = Model_Faculties::toArray(); - $twig->Grades = Model_Grades::create()->structured()->asArray(); + $twig->Grades = Model_Grades::toStructuredArray(); $twig->User = $this->UserInfo; $this->response->body($twig); } diff --git a/~dev_rating/application/classes/Controller/Admin/Students.php b/~dev_rating/application/classes/Controller/Admin/Students.php index b6d79ea87..44dd6b0a4 100644 --- a/~dev_rating/application/classes/Controller/Admin/Students.php +++ b/~dev_rating/application/classes/Controller/Admin/Students.php @@ -7,7 +7,7 @@ class Controller_Admin_Students extends Controller_UserEnvi { // VIEW $twig = Twig::factory('admin/students/index'); $twig->Faculties = Model_Faculties::toArray(); - $twig->Grades = Model_Grades::create()->structured()->asArray(); + $twig->Grades = Model_Grades::toStructuredArray(); $twig->User = $this->UserInfo; $this->response->body($twig); } @@ -16,7 +16,7 @@ class Controller_Admin_Students extends Controller_UserEnvi { { $twig = Twig::factory('admin/students/add'); $twig->Faculties = Model_Faculties::toArray(); - $twig->Grades = Model_Grades::create()->structured()->asArray(); + $twig->Grades = Model_Grades::toStructuredArray(); $twig->User = $this->UserInfo; $this->response->body($twig); } diff --git a/~dev_rating/application/classes/Controller/DeanOffice/Index.php b/~dev_rating/application/classes/Controller/DeanOffice/Index.php index efeee6903..10ce82756 100644 --- a/~dev_rating/application/classes/Controller/DeanOffice/Index.php +++ b/~dev_rating/application/classes/Controller/DeanOffice/Index.php @@ -13,7 +13,7 @@ class Controller_DeanOffice_Index extends Controller_UserEnvi { $twig = Twig::factory('dean_office/index'); $model = new Model_Teacher_Map; - $twig->GradesList = Model_Grades::create()->common()->asArray(); + $twig->GradesList = Model_Grades::toArray(); $twig->User = $this->UserInfo; $this->response->body($twig); diff --git a/~dev_rating/application/classes/Controller/Teacher/Discipline.php b/~dev_rating/application/classes/Controller/Teacher/Discipline.php index bb7b97a72..951564bef 100644 --- a/~dev_rating/application/classes/Controller/Teacher/Discipline.php +++ b/~dev_rating/application/classes/Controller/Teacher/Discipline.php @@ -9,7 +9,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi { $twig->User = $this->UserInfo; $twig->FacultiesList = Model_Faculties::toArray(); $twig->SubjectsList = Model_Subjects::create()->byFaculty($this->UserInfo['FacultyID'])->asArray(); - $twig->GradesList = Model_Grades::create()->common()->asArray(); + $twig->GradesList = Model_Grades::toArray(); $this->response->body($twig); } @@ -25,7 +25,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi { //$twig->FacultiesList = Model_Faculties::create()->common()->asArray(); $twig->Discipline = $this->GetDisciplineInfo($db, $id); $twig->SubjectsList = Model_Subjects::create()->byFaculty($this->UserInfo['FacultyID'])->asArray(); - $twig->GradesList = Model_Grades::create()->common()->asArray(); + $twig->GradesList = Model_Grades::toArray(); $this->response->body($twig); } @@ -66,7 +66,7 @@ class Controller_Teacher_Discipline extends Controller_UserEnvi { $twig->User = $this->UserInfo; $twig->Discipline = $this->GetDisciplineInfo($db, $id); - $twig->GradesList = Model_Grades::create()->common()->asArray(); + $twig->GradesList = Model_Grades::toArray(); $twig->Groups = Model_Groups::create()->ordByGroups($twig->Discipline['GradeID'], $twig->Discipline['FacultyID'])->asArray(); $students = $db->getStudentsForDiscipline($id); diff --git a/~dev_rating/application/classes/Model/Grades.php b/~dev_rating/application/classes/Model/Grades.php index ba0f1adcc..d1a6adc2d 100644 --- a/~dev_rating/application/classes/Model/Grades.php +++ b/~dev_rating/application/classes/Model/Grades.php @@ -2,17 +2,13 @@ class Model_Grades extends Model { - public static function create() { - return new self(); - } - - public function getGrades() { + public static function getGrades() { $sql = "CALL `GetGrades`();"; return DB::query(Database::SELECT, $sql)->execute(); } - public function common() { - $grades = $this->GetGrades(); + public static function toArray() { + $grades = self::GetGrades(); $list = array(); foreach ($grades as $row) { @@ -23,7 +19,7 @@ class Model_Grades extends Model $list[] = $row; } - return new DataArray_Result($list); + return $list; } public static function getDegreeTitle($degree) { @@ -39,8 +35,9 @@ class Model_Grades extends Model } } - public function structured() { - $grades = $this->common()->asArray(); + /** @return array an array with elements, grouped by grades. */ + public static function toStructuredArray() { + $grades = self::toArray(); $list = array(); $degree = 'null'; $i = 0; @@ -55,6 +52,6 @@ class Model_Grades extends Model $list[$i]['Grades'][] = $row; } - return new DataArray_Result($list); + return $list; } } -- GitLab