diff --git a/~dev_rating/application/classes/DataHelper.php b/~dev_rating/application/classes/DataHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..8f4f83ea43c9e33f33e77ea2e244d97cf345a4ea --- /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