From 2b9667d4065b8ab42b9264c5eacfbf21fef4e299 Mon Sep 17 00:00:00 2001
From: PavelBegunkov <asml.Silence@gmail.com>
Date: Wed, 11 Feb 2015 20:11:20 +0300
Subject: [PATCH] ADD: helpers

---
 .../application/classes/DataHelper.php        | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 ~dev_rating/application/classes/DataHelper.php

diff --git a/~dev_rating/application/classes/DataHelper.php b/~dev_rating/application/classes/DataHelper.php
new file mode 100644
index 000000000..8f4f83ea4
--- /dev/null
+++ b/~dev_rating/application/classes/DataHelper.php
@@ -0,0 +1,89 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class DataHelper
+{
+    protected static $dgr_lookup = array(   'bachelor' => 'Бакалавриат',
+                                            'specialist' => 'Специалитет',
+                                            'master' => 'Магистратура');
+
+    // take array with (at least) LastName & FirstName keys
+    static public function AbbreviateName(&$personInfo) {
+        $fullName = $personInfo['LastName'].' '.UTF8::substr($personInfo['FirstName'], 0, 1).'. ';
+        if(!empty($personInfo['SecondName'])) {
+            $fullName .= UTF8::substr($personInfo['SecondName'], 0, 1).'.';
+        }
+        return $fullName;
+    }
+
+    static public function GetAbbrNameArray($persons)
+    {
+        $result = array();
+        $i = 0;
+        foreach ($persons as $person){
+            $result[$i] = self::AbbreviateName($person);
+            ++$i;
+        }
+        return $result;
+    }
+
+    static public function LocalizeExamType($examType) {
+        return ($examType === "exam")?"Экзамен":"Зачет";
+    }
+
+    static public function LocalizeDegree($degree) {
+        return self::$dgr_lookup[$degree];
+    }
+
+    static public function DeserializeDisciplines($rawDiscs)
+    {
+        $subjID = $discID = $gradeID = $i = $j = 0; // Combo!!!
+        $result = array();
+
+        foreach ($rawDiscs as $row)
+        {
+            $curSubjectID = $row['SubjectID'];
+            $curGradeID = $row['GradeID'];
+            $curDiscID =  $row['ID'];
+
+            if($subjID != $curSubjectID || $gradeID != $curGradeID)
+            {
+                $j = 0;
+                ++$i;
+                $subjID = $curSubjectID;
+                $gradeID = $curGradeID;
+
+                // new grade/subject
+                $data = array();
+                $data['Degree'] = $row['Degree'];
+                $data['GradeNum'] = $row['GradeNum'];
+                $data['SubjectName'] = $row['SubjectName'];
+                $result[$i] = $data;
+                $result[$i]['Disciplines'] = array();
+                $discs = &$result[$i]['Disciplines'];
+            }
+
+            if($discID != $curDiscID)
+            {
+                $discID = $curDiscID;
+                $discs[$j] = $row; // IsAuthor, IsLocked, IsMapCreated, ID, ExamType
+                ++$j;
+            }
+        } //!for_each
+
+        return $result;
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
\ No newline at end of file
-- 
GitLab