Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 56.06 KB | None | 0 0
  1. public function getTestMapWithTemplateAndScore() {
  2.         if (null === $this->_testMapWithTemplateAndScore) {
  3.             $testTemplate                                   = $this->getTestTemplate();
  4.             $testMapWithClientAnswer                        = $this->getTestMapWithClientAnswer();
  5.             $testTemplateMap                                = $testTemplate->getTestTemplateMap();
  6.             $testMapWithTemplateAndScore                    = $testMapWithClientAnswer;
  7.             $testMapWithTemplateAndScore['test_section']    = array_combine(array_keys($testMapWithClientAnswer['test_section']), array_values($testTemplateMap['test_form_templatesection']));
  8.             $testMapWithTemplateAndScore['test_score']      = 0;
  9.             $testMapWithTemplateAndScore['test_min_score']  = 0;
  10.             $testMapWithTemplateAndScore['test_max_score']  = 0;
  11.             $stringHelper                                   = Teemo::helper('teemo/string');
  12.             $testScoreSheetMapper                           = new Test_Model_Mapper_ScoreSheet();
  13.             $testScoreMapper                                = new Test_Model_Mapper_Score();
  14.             $sectionRelatedCategoryIds                      = array();
  15.             $testSubscoreArray                              = array();
  16.             $testSiblingChildCategoryBelongsToSubscoreArray = array();
  17.             $relatedScoreRate                               = (int)Core_Model_Setting::getValue('TEST-RELATED-SCORE-RATE');
  18.  
  19.             $testScoreSheetsWithTestScoreCode  = $testScoreSheetMapper->fetchByFields(array('active' => true, 'test_type_id' => $testTemplate->getTestTypeId(), 'test_score_sheet_type_id' => Test_Model_ScoreSheetType::getScoreSheetTypeByCode(Test_Model_ScoreSheetType::TEST_SCORE_CODE)->getId()));
  20.             $testScoreSheetIdWithTestScoreCode = $testScoreSheetsWithTestScoreCode->count() > 0 ? $testScoreSheetsWithTestScoreCode->first()->getId() : null;
  21.             $testScoresWithTestScoreCode       = $testScoreMapper->fetchByFields(array('test_score_sheet_id' => $testScoreSheetIdWithTestScoreCode))->sort('raw_score desc');
  22.             $maxRawScoreWithTestScoreCode      = $testScoresWithTestScoreCode->count() > 0 ? (int)$testScoresWithTestScoreCode->first()->getRawScore() : 0;
  23.             $minRawScoreWithTestScoreCode      = $testScoresWithTestScoreCode->count() > 0 ? (int)$testScoresWithTestScoreCode->last()->getRawScore() : 0;
  24.  
  25.             $testScoreSheetsWithCrossTestScoreCode  = $testScoreSheetMapper->fetchByFields(array('active' => true, 'test_type_id' => $testTemplate->getTestTypeId(), 'test_score_sheet_type_id' => Test_Model_ScoreSheetType::getScoreSheetTypeByCode(Test_Model_ScoreSheetType::CROSS_TEST_SCORE_CODE)->getId()));
  26.             $testScoreSheetIdWithCrossTestScoreCode = $testScoreSheetsWithCrossTestScoreCode->count() > 0 ? $testScoreSheetsWithCrossTestScoreCode->first()->getId() : null;
  27.             $testScoresWithCrossTestScoreCode       = $testScoreMapper->fetchByFields(array('test_score_sheet_id' => $testScoreSheetIdWithCrossTestScoreCode))->sort('raw_score desc');
  28.             $maxRawScoreWithCrossTestScoreCode      = $testScoresWithCrossTestScoreCode->count() > 0 ? (int)$testScoresWithCrossTestScoreCode->first()->getRawScore() : 0;
  29.             $minRawScoreWithCrossTestScoreCode      = $testScoresWithCrossTestScoreCode->count() > 0 ? (int)$testScoresWithCrossTestScoreCode->last()->getRawScore() : 0;
  30.  
  31.             $testScoreSheetsWithSubscoreCode  = $testScoreSheetMapper->fetchByFields(array('active' => true, 'test_type_id' => $testTemplate->getTestTypeId(), 'test_score_sheet_type_id' => Test_Model_ScoreSheetType::getScoreSheetTypeByCode(Test_Model_ScoreSheetType::SUBSCORE_CODE)->getId()));
  32.             $testScoreSheetIdWithSubscoreCode = $testScoreSheetsWithSubscoreCode->count() > 0 ? $testScoreSheetsWithSubscoreCode->first()->getId() : null;
  33.             $testScoresWithSubscoreCode       = $testScoreMapper->fetchByFields(array('test_score_sheet_id' => $testScoreSheetIdWithSubscoreCode))->sort('raw_score desc');
  34.             $maxRawScoreWithSubscoreCode      = $testScoresWithSubscoreCode->count() > 0 ? (int)$testScoresWithSubscoreCode->first()->getRawScore() : 0;
  35.             $minRawScoreWithSubscoreCode      = $testScoresWithSubscoreCode->count() > 0 ? (int)$testScoresWithSubscoreCode->last()->getRawScore() : 0;
  36.  
  37.             $colourMap           = Test_Model_AnswerType::getTestReportAnswerTypeColorMap();
  38.             $correctAnswerName   = Test_Model_AnswerType::getAnswerTypeByCode(Test_Model_AnswerType::CORRECT_CODE)->getName();
  39.             $incorrectAnswerName = Test_Model_AnswerType::getAnswerTypeByCode(Test_Model_AnswerType::INCORRECT_CODE)->getName();
  40.  
  41.             foreach ($testMapWithClientAnswer['test_section'] as $testSectionId => $testSectionMap) {
  42.                 $testSection = new Test_Model_Section();
  43.                 $testSection->find($testSectionId);
  44.  
  45.                 $testQuestionIds                                                                       = $testSection->getTestQuestions()->getIds();
  46.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_question_count'] = count($testQuestionIds);
  47.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_raw_score']      = 0;
  48.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_incorrect']      = 0;
  49.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_omitted']        = 0;
  50.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_notes']          = $testSectionMap['notes'];
  51.  
  52.                 foreach ($testSectionMap['client_answer'] as $index => $clientAnswer) {
  53.                     $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['client_answer'] = $clientAnswer;
  54.  
  55.                     if (isset($clientAnswer) && $clientAnswer !== null) {
  56.                         if ($this->isCorrectAnswer($clientAnswer, $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['test_choice_format_option_id'], $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['grid_in_answer'])) {
  57.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_raw_score'] = 1;
  58.  
  59.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_raw_score']++;
  60.  
  61.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['colour']   = $colourMap[$correctAnswerName];
  62.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['response'] = '+';
  63.                         } else {
  64.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_incorrect'] = 1;
  65.  
  66.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_incorrect']++;
  67.  
  68.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['colour'] = $colourMap[$incorrectAnswerName];
  69.  
  70.                             $response = new Test_Model_ChoiceFormatOption();
  71.                             $response->find($clientAnswer);
  72.  
  73.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['response'] = $response->getId() ? $response->getName() : $clientAnswer;
  74.                         }
  75.                     } else {
  76.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_omitted'] = 1;
  77.  
  78.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_omitted']++;
  79.  
  80.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['colour'] = '#000';
  81.  
  82.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['response'] = '';
  83.                     }
  84.  
  85.                     $correctAnswer = new Test_Model_ChoiceFormatOption();
  86.  
  87.                     $correctAnswer = $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['grid_in_answer'] !== null ? $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['grid_in_answer'] : $correctAnswer->find($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['test_choice_format_option_id']);
  88.  
  89.                     $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['question_num']   = $index + 1;
  90.                     $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['correct_answer'] = $correctAnswer instanceof Test_Model_ChoiceFormatOption ? $correctAnswer->getName() : $correctAnswer;
  91.  
  92.                     $templateQuestion = new Test_Model_TemplateQuestion();
  93.                     $templateQuestion->find($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['test_template_question_id']);
  94.  
  95.                     $testTemplateQuestionCategoryNames = array();
  96.  
  97.                     foreach ($templateQuestion->getTestTemplateQuestionCategories() as $testTemplateQuestionCategory) {
  98.                         $testTemplateQuestionCategoryName = $testTemplateQuestionCategory->getTestCategory()->getName();
  99.  
  100.                         if (!in_array($testTemplateQuestionCategoryName, $testTemplateQuestionCategoryNames)) {
  101.                             $testTemplateQuestionCategoryNames[] = $testTemplateQuestionCategoryName;
  102.                         }
  103.                     }
  104.  
  105.                     sort($testTemplateQuestionCategoryNames);
  106.  
  107.                     $testMapWithTemplateAndScore['test_section'][$testSectionId]['responses'][$testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name']][$index]['categories'] = implode(', ', $testTemplateQuestionCategoryNames);
  108.  
  109.                     $testCrossTestScoreId = $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['test_cross_test_score_id'];
  110.  
  111.                     if ($testCrossTestScoreId) {
  112.                         $testCrossTestScore = new Test_Model_CrossTestScore();
  113.                         $testCrossTestScore->find($testCrossTestScoreId);
  114.  
  115.                         $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId]['test_cross_test_score_name'] = $testCrossTestScore->getName();
  116.  
  117.                         $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId]['test_cross_test_score_count']++;
  118.  
  119.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_raw_score']) {
  120.                             $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId]['test_cross_test_score_raw_score']++;
  121.                         }
  122.  
  123.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_incorrect']) {
  124.                             $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId]['test_cross_test_score_incorrect']++;
  125.                         }
  126.  
  127.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_omitted']) {
  128.                             $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId]['test_cross_test_score_omitted']++;
  129.                         }
  130.                     }
  131.  
  132.                     $testSubscoreId = $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['test_subscore_id'];
  133.  
  134.                     if ($testSubscoreId) {
  135.                         $testSubscore = new Test_Model_Subscore();
  136.                         $testSubscore->find($testSubscoreId);
  137.  
  138.                         $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId]['test_subscore_name'] = $testSubscore->getName();
  139.  
  140.                         $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId]['test_subscore_count']++;
  141.  
  142.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_raw_score']) {
  143.                             $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId]['test_subscore_raw_score']++;
  144.                         }
  145.  
  146.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_incorrect']) {
  147.                             $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId]['test_subscore_incorrect']++;
  148.                         }
  149.  
  150.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_omitted']) {
  151.                             $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId]['test_subscore_omitted']++;
  152.                         }
  153.                     }
  154.  
  155.                     foreach ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_category'] as $testQuestionCategoryIndex => $testQuestionCategory) {
  156.                         $questionCategoryId = $testQuestionCategory['question_category_id'];
  157.  
  158.                         $questionCategory = new Test_Model_Category();
  159.                         $questionCategory->find($questionCategoryId);
  160.  
  161.                         $questionCategoryName                                                                                                                                                        = $questionCategory->getName();
  162.                         $questionCategoryBelongToSubscore                                                                                                                                            = $questionCategory->getBelongToSubscore();
  163.                         $questionCategoryTestCategoryTypeId                                                                                                                                          = $questionCategory->getTestCategoryTypeId();
  164.                         $isGrandchildCategory                                                                                                                                                        = $questionCategory->isGrandchildCategory();
  165.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['test_category_type_id']                = $questionCategoryTestCategoryTypeId ? : '';
  166.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['test_category_type_name']              = $questionCategoryTestCategoryTypeId ? $questionCategory->getTestCategoryType()->getName() : '';
  167.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_name']               = $questionCategoryName;
  168.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_belong_to_subscore'] = $questionCategoryBelongToSubscore;
  169.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['is_grandchild_category']               = $isGrandchildCategory;
  170.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['parent_id_of_grandchild_category']     = $isGrandchildCategory ? $questionCategory->getParentId() : '';
  171.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['parent_name_of_grandchild_category']   = $isGrandchildCategory ? $questionCategory->getParentTestCategory()->getName() : '';
  172.  
  173.                         $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_count']++;
  174.  
  175.                         if ($questionCategoryBelongToSubscore) {
  176.                             $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$questionCategoryId]['question_category_name'] = $questionCategoryName;
  177.  
  178.                             $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$questionCategoryId]['question_category_count']++;
  179.                         }
  180.  
  181.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_raw_score']) {
  182.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_raw_score']++;
  183.  
  184.                             if ($questionCategoryBelongToSubscore) {
  185.                                 $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$questionCategoryId]['question_category_raw_score']++;
  186.                             }
  187.                         }
  188.  
  189.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_incorrect']) {
  190.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_incorrect']++;
  191.  
  192.                             if ($questionCategoryBelongToSubscore) {
  193.                                 $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$questionCategoryId]['question_category_incorrect']++;
  194.                             }
  195.                         }
  196.  
  197.                         if ($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'][$index]['question_omitted']) {
  198.                             $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_omitted']++;
  199.  
  200.                             if ($questionCategoryBelongToSubscore) {
  201.                                 $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$questionCategoryId]['question_category_omitted']++;
  202.                             }
  203.                         }
  204.                     }
  205.                 }
  206.  
  207.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion'] = array_combine(array_values($testQuestionIds), array_values($testMapWithTemplateAndScore['test_section'][$testSectionId]['test_form_templatequestion']));
  208.                 $sectionTestCategoryId                                                                     = $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_id'];
  209.                 $sectionParentCategoryId                                                                   = $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_parent_category_id'];
  210.  
  211.                 $testCategory = new Test_Model_Category();
  212.                 $testCategory->find($sectionTestCategoryId);
  213.  
  214.                 if ($testCategory->getIsSubcategory()) {
  215.                     $sectionTestCategoryId = $testCategory->getParentId();
  216.                 }
  217.  
  218.                 $scoreArray                                                                           = $this->getScores(Test_Model_ScoreSheetType::TEST_SCORE_CODE, $testScoreSheetIdWithTestScoreCode, $sectionTestCategoryId, $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_raw_score'], $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_question_count'], $maxRawScoreWithTestScoreCode, $minRawScoreWithTestScoreCode);
  219.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_score']         = $scoreArray['section_score'];
  220.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_min_score']     = $scoreArray['section_min_score'];
  221.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_min_raw_score'] = $scoreArray['section_min_raw_score'];
  222.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_max_score']     = $scoreArray['section_max_score'];
  223.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_max_raw_score'] = $scoreArray['section_max_raw_score'];
  224.                 $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_category_name'] = $testCategory->getName();
  225.  
  226.                 if (!$sectionParentCategoryId) {
  227.                     $sectionRelatedCategoryId                      = $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_related_category_id'];
  228.                     $testMapWithTemplateAndScore['test_score']     = is_numeric($testMapWithTemplateAndScore['test_section'][$testSectionId]['section_score']) ? ($sectionRelatedCategoryId ? $relatedScoreRate * $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_score'] + $testMapWithTemplateAndScore['test_score'] : $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_score'] + $testMapWithTemplateAndScore['test_score']) : $stringHelper->get('N/A');
  229.                     $testMapWithTemplateAndScore['test_min_score'] = is_numeric($testMapWithTemplateAndScore['test_section'][$testSectionId]['section_min_score']) ? ($sectionRelatedCategoryId ? $relatedScoreRate * $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_min_score'] + $testMapWithTemplateAndScore['test_min_score'] : $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_min_score'] + $testMapWithTemplateAndScore['test_min_score']) : $stringHelper->get('N/A');
  230.                     $testMapWithTemplateAndScore['test_max_score'] = is_numeric($testMapWithTemplateAndScore['test_section'][$testSectionId]['section_max_score']) ? ($sectionRelatedCategoryId ? $relatedScoreRate * $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_max_score'] + $testMapWithTemplateAndScore['test_max_score'] : $testMapWithTemplateAndScore['test_section'][$testSectionId]['section_max_score'] + $testMapWithTemplateAndScore['test_max_score']) : $stringHelper->get('N/A');
  231.                 }
  232.             }
  233.  
  234.             if ($testMapWithTemplateAndScore['test_cross_test_score']) {
  235.                 foreach ($testMapWithTemplateAndScore['test_cross_test_score'] as $testCrossTestScoreId => $testCrossTestScore) {
  236.                     $testCrossTestScoreArray = array(
  237.                         'test_cross_test_score_name'      => $testCrossTestScore['test_cross_test_score_name'],
  238.                         'test_cross_test_score_count'     => $testCrossTestScore['test_cross_test_score_count'],
  239.                         'test_cross_test_score_raw_score' => $testCrossTestScore['test_cross_test_score_raw_score'] ? : 0,
  240.                         'test_cross_test_score_incorrect' => $testCrossTestScore['test_cross_test_score_incorrect'] ? : 0,
  241.                         'test_cross_test_score_omitted'   => $testCrossTestScore['test_cross_test_score_omitted'] ? : 0,
  242.                     );
  243.  
  244.                     $scoreArray                                                                  = $this->getScores(Test_Model_ScoreSheetType::CROSS_TEST_SCORE_CODE, $testScoreSheetIdWithCrossTestScoreCode, $testCrossTestScoreId, $testCrossTestScoreArray['test_cross_test_score_raw_score'], $testCrossTestScoreArray['test_cross_test_score_count'], $maxRawScoreWithCrossTestScoreCode, $minRawScoreWithCrossTestScoreCode);
  245.                     $testCrossTestScoreArray['test_cross_test_score_score']                      = $scoreArray['section_score'];
  246.                     $testCrossTestScoreArray['test_cross_test_score_min_score']                  = $scoreArray['section_min_score'];
  247.                     $testCrossTestScoreArray['test_cross_test_score_min_raw_score']              = $scoreArray['section_min_raw_score'];
  248.                     $testCrossTestScoreArray['test_cross_test_score_max_score']                  = $scoreArray['section_max_score'];
  249.                     $testCrossTestScoreArray['test_cross_test_score_max_raw_score']              = $scoreArray['section_max_raw_score'];
  250.                     $testMapWithTemplateAndScore['test_cross_test_score'][$testCrossTestScoreId] = $testCrossTestScoreArray;
  251.                 }
  252.             }
  253.  
  254.             if ($testMapWithTemplateAndScore['test_subscore']) {
  255.                 foreach ($testMapWithTemplateAndScore['test_subscore'] as $testSubscoreId => $testSubscore) {
  256.                     $testSubscoreArray = array(
  257.                         'test_subscore_name'      => $testSubscore['test_subscore_name'],
  258.                         'test_subscore_count'     => $testSubscore['test_subscore_count'],
  259.                         'test_subscore_raw_score' => $testSubscore['test_subscore_raw_score'] ? : 0,
  260.                         'test_subscore_incorrect' => $testSubscore['test_subscore_incorrect'] ? : 0,
  261.                         'test_subscore_omitted'   => $testSubscore['test_subscore_omitted'] ? : 0,
  262.                     );
  263.  
  264.                     $scoreArray                                                    = $this->getScores(Test_Model_ScoreSheetType::SUBSCORE_CODE, $testScoreSheetIdWithSubscoreCode, $testSubscoreId, $testSubscoreArray['test_subscore_raw_score'], $testSubscoreArray['test_subscore_count'], $maxRawScoreWithSubscoreCode, $minRawScoreWithSubscoreCode);
  265.                     $testSubscoreArray['test_subscore_score']                      = $scoreArray['section_score'];
  266.                     $testSubscoreArray['test_subscore_min_score']                  = $scoreArray['section_min_score'];
  267.                     $testSubscoreArray['test_subscore_min_raw_score']              = $scoreArray['section_min_raw_score'];
  268.                     $testSubscoreArray['test_subscore_max_score']                  = $scoreArray['section_max_score'];
  269.                     $testSubscoreArray['test_subscore_max_raw_score']              = $scoreArray['section_max_raw_score'];
  270.                     $testMapWithTemplateAndScore['test_subscore'][$testSubscoreId] = $testSubscoreArray;
  271.                 }
  272.             }
  273.  
  274.             if ($testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore']) {
  275.                 foreach ($testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'] as $testCategoryId => $testCategory) {
  276.                     $testCategoryArray = array(
  277.                         'test_subscore_name'      => $testCategory['question_category_name'],
  278.                         'test_subscore_count'     => $testCategory['question_category_count'],
  279.                         'test_subscore_raw_score' => $testCategory['question_category_raw_score'] ? : 0,
  280.                         'test_subscore_incorrect' => $testCategory['question_category_incorrect'] ? : 0,
  281.                         'test_subscore_omitted'   => $testCategory['question_category_omitted'] ? : 0,
  282.                     );
  283.  
  284.                     $scoreArray                                                                                      = $this->getScores(Test_Model_ScoreSheetType::SUBSCORE_CODE, $testScoreSheetIdWithSubscoreCode, $testCategoryId, $testCategoryArray['test_subscore_raw_score'], $testCategoryArray['test_subscore_count'], $maxRawScoreWithSubscoreCode, $minRawScoreWithSubscoreCode, true);
  285.                     $testCategoryArray['test_subscore_score']                                                        = $scoreArray['section_score'];
  286.                     $testCategoryArray['test_subscore_min_score']                                                    = $scoreArray['section_min_score'];
  287.                     $testCategoryArray['test_subscore_min_raw_score']                                                = $scoreArray['section_min_raw_score'];
  288.                     $testCategoryArray['test_subscore_max_score']                                                    = $scoreArray['section_max_score'];
  289.                     $testCategoryArray['test_subscore_max_raw_score']                                                = $scoreArray['section_max_raw_score'];
  290.                     $testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore'][$testCategoryId] = $testCategoryArray;
  291.                 }
  292.             }
  293.  
  294.             if ($testMapWithTemplateAndScore['test_subscore']) {
  295.                 $testSubscoreArray = array_values($testMapWithTemplateAndScore['test_subscore']);
  296.             }
  297.  
  298.             if ($testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore']) {
  299.                 ksort($testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore']);
  300.  
  301.                 $testSiblingChildCategoryBelongsToSubscoreArray = array_values($testMapWithTemplateAndScore['test_sibling_child_category_belongs_to_subscore']);
  302.             }
  303.  
  304.             $testMapWithTemplateAndScore['test_subscore_merged'] = array_merge($testSubscoreArray, $testSiblingChildCategoryBelongsToSubscoreArray);
  305.  
  306.             foreach ($testMapWithTemplateAndScore['test_section'] as $sectionId => $testSection) {
  307.                 if ($testSection['section_performance_by_question_category_report']) {
  308.                     foreach ($testSection['section_performance_by_question_category_report'] as $questionCategoryId => $questionCategory) {
  309.                         $questionCategoryArray = array(
  310.                             'question_category_name'               => $questionCategory['question_category_name'],
  311.                             'question_category_count'              => $questionCategory['question_category_count'],
  312.                             'question_category_raw_score'          => $questionCategory['question_category_raw_score'] ? : 0,
  313.                             'question_category_incorrect'          => $questionCategory['question_category_incorrect'] ? : 0,
  314.                             'question_category_omitted'            => $questionCategory['question_category_omitted'] ? : 0,
  315.                             'test_category_type_id'                => $questionCategory['test_category_type_id'],
  316.                             'test_category_type_name'              => $questionCategory['test_category_type_name'],
  317.                             'question_category_belong_to_subscore' => $questionCategory['question_category_belong_to_subscore'],
  318.                             'is_grandchild_category'               => $questionCategory['is_grandchild_category'],
  319.                             'parent_id_of_grandchild_category'     => $questionCategory['parent_id_of_grandchild_category'],
  320.                             'parent_name_of_grandchild_category'   => $questionCategory['parent_name_of_grandchild_category']
  321.                         );
  322.  
  323.                         $testMapWithTemplateAndScore['test_section'][$sectionId]['section_performance_by_question_category_report'][$questionCategoryId] = $questionCategoryArray;
  324.  
  325.                         if ($questionCategory['test_category_type_id']) {
  326.                             if ($questionCategory['is_grandchild_category']) {
  327.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['parent_name_of_grandchild_category']                                                                                                 = $questionCategory['parent_name_of_grandchild_category'];
  328.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_name'] = $questionCategory['test_category_type_name'];
  329.  
  330.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId] = array(
  331.                                     'question_category_name'             => $questionCategory['question_category_name'],
  332.                                     'question_category_count'            => $questionCategory['question_category_count'],
  333.                                     'question_category_raw_score'        => $questionCategory['question_category_raw_score'] ? : 0,
  334.                                     'question_category_incorrect'        => $questionCategory['question_category_incorrect'] ? : 0,
  335.                                     'question_category_omitted'          => $questionCategory['question_category_omitted'] ? : 0,
  336.                                     'is_grandchild_category'             => $questionCategory['is_grandchild_category'],
  337.                                     'parent_id_of_grandchild_category'   => $questionCategory['parent_id_of_grandchild_category'],
  338.                                     'parent_name_of_grandchild_category' => $questionCategory['parent_name_of_grandchild_category']
  339.                                 );
  340.  
  341.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_name']      = $questionCategory['parent_name_of_grandchild_category'];
  342.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_count']     += $questionCategory['question_category_count'];
  343.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_raw_score'] += $questionCategory['question_category_raw_score'];
  344.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_incorrect'] += $questionCategory['question_category_incorrect'];
  345.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_omitted']   += $questionCategory['question_category_omitted'];
  346.                             } else {
  347.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_name'] = $questionCategory['test_category_type_name'];
  348.  
  349.                                 $testMapWithTemplateAndScore['test_section'][$sectionId]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId] = array(
  350.                                     'question_category_name'             => $questionCategory['question_category_name'],
  351.                                     'question_category_count'            => $questionCategory['question_category_count'],
  352.                                     'question_category_raw_score'        => $questionCategory['question_category_raw_score'] ? : 0,
  353.                                     'question_category_incorrect'        => $questionCategory['question_category_incorrect'] ? : 0,
  354.                                     'question_category_omitted'          => $questionCategory['question_category_omitted'] ? : 0,
  355.                                     'is_grandchild_category'             => $questionCategory['is_grandchild_category'],
  356.                                     'parent_id_of_grandchild_category'   => $questionCategory['parent_id_of_grandchild_category'],
  357.                                     'parent_name_of_grandchild_category' => $questionCategory['parent_name_of_grandchild_category']
  358.                                 );
  359.                             }
  360.                         }
  361.                     }
  362.                 }
  363.  
  364.                 if ($testSection['section_parent_category_id']) {
  365.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_category_id']         = $testSection['section_parent_category_id'];
  366.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_category_name']       = $testSection['section_parent_category_name'];
  367.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_notes']               = sprintf('<strong>%s:</strong> %s<br>%s', $testSection['section_category_name'], $testSection['section_notes'], $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_notes']);
  368.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_question_count']      += $testSection['section_question_count'];
  369.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_raw_score']           += $testSection['section_raw_score'];
  370.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_incorrect']           += $testSection['section_incorrect'];
  371.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_omitted']             += $testSection['section_omitted'];
  372.                     $scoreArray                                                                                                                = $this->getScores(Test_Model_ScoreSheetType::TEST_SCORE_CODE, $testScoreSheetIdWithTestScoreCode, $testSection['section_parent_category_id'], $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_raw_score'], $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_question_count'], $maxRawScoreWithTestScoreCode, $minRawScoreWithTestScoreCode);
  373.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_score']               = $scoreArray['section_score'] / ($relatedScoreRate * 2);
  374.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_min_score']           = $scoreArray['section_min_score'] / ($relatedScoreRate * 2);
  375.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_min_raw_score']       = $scoreArray['section_min_raw_score'];
  376.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_max_score']           = $scoreArray['section_max_score'] / ($relatedScoreRate * 2);
  377.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_max_raw_score']       = $scoreArray['section_max_raw_score'];
  378.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_score_converted']     = $scoreArray['section_score'];
  379.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_min_score_converted'] = $scoreArray['section_min_score'];
  380.                     $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_max_score_converted'] = $scoreArray['section_max_score'];
  381.  
  382.                     foreach ($testSection['responses'] as $response) {
  383.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['responses'][$testMapWithTemplateAndScore['test_section'][$sectionId]['section_category_name']] = $response;
  384.                     }
  385.  
  386.                     $testCategory = new Test_Model_Category();
  387.                     $testCategory->find($testSection['section_parent_category_id']);
  388.  
  389.                     if ($testCategory->getId()) {
  390.                         $relatedTestCategory                                                                                                         = $testCategory->getRelatedTestCategory();
  391.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_related_category_id']   = $relatedTestCategory->getId();
  392.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_related_category_name'] = $relatedTestCategory->getName();
  393.                     }
  394.  
  395.                     foreach ($testSection['section_performance_by_question_category_report'] as $questionCategoryId => $questionCategory) {
  396.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_name']               = $questionCategory['question_category_name'];
  397.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_count']              += $questionCategory['question_category_count'];
  398.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_raw_score']          += $questionCategory['question_category_raw_score'];
  399.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_incorrect']          += $questionCategory['question_category_incorrect'];
  400.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_omitted']            += $questionCategory['question_category_omitted'];
  401.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['test_category_type_id']                = $questionCategory['test_category_type_id'];
  402.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['test_category_type_name']              = $questionCategory['test_category_type_name'];
  403.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['question_category_belong_to_subscore'] = $questionCategory['question_category_belong_to_subscore'];
  404.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['is_grandchild_category']               = $questionCategory['is_grandchild_category'];
  405.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['parent_id_of_grandchild_category']     = $questionCategory['parent_id_of_grandchild_category'];
  406.                         $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_question_category_report'][$questionCategoryId]['parent_name_of_grandchild_category']   = $questionCategory['parent_name_of_grandchild_category'];
  407.  
  408.                         if ($questionCategory['test_category_type_id']) {
  409.                             if ($questionCategory['is_grandchild_category']) {
  410.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['parent_name_of_grandchild_category']                                                                                                                                                       = $questionCategory['parent_name_of_grandchild_category'];
  411.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_name']                                                       = $questionCategory['test_category_type_name'];
  412.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_name']      = $questionCategory['question_category_name'];
  413.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_count']     += $questionCategory['question_category_count'];
  414.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_raw_score'] += $questionCategory['question_category_raw_score'];
  415.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_incorrect'] += $questionCategory['question_category_incorrect'];
  416.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['section_performance_by_category_type_report_for_parent_of_grandchild_category'][$questionCategory['parent_id_of_grandchild_category']]['test_category_type_report_for_parent_of_grandchild_category'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_omitted']   += $questionCategory['question_category_omitted'];
  417.  
  418.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_name']      = $questionCategory['parent_name_of_grandchild_category'];
  419.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_count']     += $questionCategory['question_category_count'];
  420.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_raw_score'] += $questionCategory['question_category_raw_score'];
  421.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_incorrect'] += $questionCategory['question_category_incorrect'];
  422.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategory['parent_id_of_grandchild_category']]['question_category_omitted']   += $questionCategory['question_category_omitted'];
  423.                             } else {
  424.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_name']                                                       = $questionCategory['test_category_type_name'];
  425.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_name']      = $questionCategory['question_category_name'];
  426.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_count']     += $questionCategory['question_category_count'];
  427.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_raw_score'] += $questionCategory['question_category_raw_score'];
  428.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_incorrect'] += $questionCategory['question_category_incorrect'];
  429.                                 $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['test_category_type_report'][$questionCategoryId]['question_category_omitted']   += $questionCategory['question_category_omitted'];
  430.                             }
  431.  
  432.                             $testMapWithTemplateAndScore['parent_category'][$testSection['section_parent_category_id']]['child_section_category_type_reports'][$sectionId]['section_performance_by_category_type_report'][$questionCategory['test_category_type_id']]['section_name'] = str_replace(sprintf('%s - ', $testCategory->getName()), '', $testMapWithTemplateAndScore['test_section'][$sectionId]['section_category_name']);
  433.                         }
  434.                     }
  435.                 }
  436.  
  437.                 $sectionRelatedCategoryIds[] = $testSection['section_related_category_id'];
  438.  
  439.                 if ($testSection['section_related_category_id'] && !in_array($testSection['section_category_id'], $sectionRelatedCategoryIds)) {
  440.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_category_id']         = $testSection['section_category_id'];
  441.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_related_category_id'] = $testSection['section_related_category_id'];
  442.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_category_name']       = $stringHelper->get('Evidence Based %s, %s', $testSection['section_category_name'], $testSection['section_related_category_name']);
  443.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_score']               = is_numeric($testSection['section_score']) ? $testSection['section_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  444.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_min_score']           = is_numeric($testSection['section_min_score']) ? $testSection['section_min_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  445.                     $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_max_score']           = is_numeric($testSection['section_max_score']) ? $testSection['section_max_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  446.  
  447.                     foreach ($testMapWithTemplateAndScore['test_section'] as $sectionIdRelated => $testSectionRelated) {
  448.                         if ($testSectionRelated['section_category_id'] === $testSection['section_related_category_id']) {
  449.                             $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_score']     = is_numeric($testSection['section_score']) && is_numeric($testSectionRelated['section_score']) ? ($testSection['section_score'] + $testSectionRelated['section_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  450.                             $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_min_score'] = is_numeric($testSection['section_min_score']) && is_numeric($testSectionRelated['section_min_score']) ? ($testSection['section_min_score'] + $testSectionRelated['section_min_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  451.                             $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_max_score'] = is_numeric($testSection['section_max_score']) && is_numeric($testSectionRelated['section_max_score']) ? ($testSection['section_max_score'] + $testSectionRelated['section_max_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  452.                         }
  453.                     }
  454.                 }
  455.             }
  456.  
  457.             foreach ($testMapWithTemplateAndScore['related_category'] as $testCategoryId => $testSection) {
  458.                 foreach ($testMapWithTemplateAndScore['parent_category'] as $testCategoryIdRelated => $testSectionRelated) {
  459.                     if ((int)$testSection['section_related_category_id'] === $testCategoryIdRelated) {
  460.                         $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_score']     = is_numeric($testSection['section_score']) && is_numeric($testSectionRelated['section_score']) ? $testSection['section_score'] + $testSectionRelated['section_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  461.                         $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_min_score'] = is_numeric($testSection['section_min_score']) && is_numeric($testSectionRelated['section_min_score']) ? $testSection['section_min_score'] + $testSectionRelated['section_min_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  462.                         $testMapWithTemplateAndScore['related_category'][$testSection['section_category_id']]['section_max_score'] = is_numeric($testSection['section_max_score']) && is_numeric($testSectionRelated['section_max_score']) ? $testSection['section_max_score'] + $testSectionRelated['section_max_score'] * $relatedScoreRate : $stringHelper->get('N/A');
  463.                     }
  464.                 }
  465.             }
  466.  
  467.             $sectionRelatedCategoryIds[] = array();
  468.  
  469.             foreach ($testMapWithTemplateAndScore['parent_category'] as $testCategoryId => $testSection) {
  470.                 $sectionRelatedCategoryIds[] = $testSection['section_related_category_id'];
  471.  
  472.                 if (!in_array($testCategoryId, $sectionRelatedCategoryIds)) {
  473.                     foreach ($testMapWithTemplateAndScore['parent_category'] as $testCategoryIdRelated => $testSectionRelated) {
  474.                         if ((int)$testSection['section_related_category_id'] === $testCategoryIdRelated) {
  475.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_category_id']         = $testCategoryId;
  476.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_related_category_id'] = $testSection['section_related_category_id'];
  477.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_category_name']       = $stringHelper->get('%s and %s', $testSection['section_category_name'], $testSection['section_related_category_name']);
  478.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_score']               = is_numeric($testSection['section_score']) && is_numeric($testSectionRelated['section_score']) ? ($testSection['section_score'] + $testSectionRelated['section_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  479.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_min_score']           = is_numeric($testSection['section_min_score']) && is_numeric($testSectionRelated['section_min_score']) ? ($testSection['section_min_score'] + $testSectionRelated['section_min_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  480.                             $testMapWithTemplateAndScore['related_category'][$testCategoryId]['section_max_score']           = is_numeric($testSection['section_max_score']) && is_numeric($testSectionRelated['section_max_score']) ? ($testSection['section_max_score'] + $testSectionRelated['section_max_score']) * $relatedScoreRate : $stringHelper->get('N/A');
  481.                         }
  482.                     }
  483.                 }
  484.  
  485.                 $testMapWithTemplateAndScore['test_score']     = is_numeric($testSection['section_score']) ? ($testSection['section_related_category_id'] ? $relatedScoreRate * $testSection['section_score'] + $testMapWithTemplateAndScore['test_score'] : $testSection['section_score_converted'] + $testMapWithTemplateAndScore['test_score']) : $stringHelper->get('N/A');
  486.                 $testMapWithTemplateAndScore['test_min_score'] = is_numeric($testSection['section_min_score']) ? ($testSection['section_related_category_id'] ? $relatedScoreRate * $testSection['section_min_score'] + $testMapWithTemplateAndScore['test_min_score'] : $testSection['section_min_score_converted'] + $testMapWithTemplateAndScore['test_min_score']) : $stringHelper->get('N/A');
  487.                 $testMapWithTemplateAndScore['test_max_score'] = is_numeric($testSection['section_max_score']) ? ($testSection['section_related_category_id'] ? $relatedScoreRate * $testSection['section_max_score'] + $testMapWithTemplateAndScore['test_max_score'] : $testSection['section_max_score_converted'] + $testMapWithTemplateAndScore['test_max_score']) : $stringHelper->get('N/A');
  488.             }
  489.  
  490.             $this->_testMapWithTemplateAndScore = $testMapWithTemplateAndScore;
  491.         }
  492.  
  493.         return $this->_testMapWithTemplateAndScore;
  494.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement