public function getFullFieldSubHeading(SurveyObj $survey, FormattingOptions $oOptions, $fieldName) { $field = $survey->fieldMap[$fieldName]; $answerCode = $field['aid']; $questionId = $field['qid']; $fieldType = $field['type']; $subHeading = ''; switch ($fieldType) { case 'R': $subHeading .= ' [' . $this->translate('Ranking', $this->languageCode) . ' ' . $answerCode . ']'; break; case 'L': case '!': if ($answerCode == 'other') { $subHeading .= ' ' . $this->getOtherSubHeading(); } break; case 'O': if ($answerCode == 'comment') { $subHeading .= ' ' . $this->getCommentSubHeading(); } break; case 'M': case 'P': //This section creates differing output from the old code base, but I do think //that it is more correct than the old code. $isOther = $answerCode == 'other'; $isComment = mb_substr($answerCode, -7, 7) == 'comment'; if ($isComment) { $isOther = mb_substr($answerCode, 0, -7) == 'other'; } if ($isOther) { $subHeading .= ' ' . $this->getOtherSubHeading(); } else { $sqs = $survey->getSubQuestionArrays($questionId); foreach ($sqs as $sq) { if (!$isComment && $sq['title'] == $answerCode) { $value = $sq['question']; } } if (!empty($value)) { $subHeading .= ' [' . $this->stripTagsFull($value) . ']'; } } if (isset($isComment) && $isComment == true) { $subHeading .= ' ' . $this->getCommentSubHeading(); $comment = false; } break; case ':': case ';': //The headers created by this section of code are significantly different from //the old code. I believe that they are more accurate. - elameno list($scaleZeroTitle, $scaleOneTitle) = explode('_', $answerCode); $sqs = $survey->getSubQuestionArrays($questionId); $scaleZeroText = ''; $scaleOneText = ''; foreach ($sqs as $sq) { if ($sq['title'] == $scaleZeroTitle && $sq['scale_id'] == 0) { $scaleZeroText = $sq['question']; } elseif ($sq['title'] == $scaleOneTitle && $sq['scale_id'] == 1) { $scaleOneText = $sq['question']; } } $subHeading .= ' [' . $this->stripTagsFull($scaleZeroText) . '][' . $this->stripTagsFull($scaleOneText) . ']'; break; case '1': $answerScale = substr($fieldName, -1) + 1; $subQuestions = $survey->getSubQuestionArrays($questionId); foreach ($subQuestions as $question) { if ($question['title'] == $answerCode && $question['scale_id'] == 0) { $subHeading = ' [' . flattenText($question['question'], true, true) . '][Scale ' . $answerScale . ']'; } } break; default: $subQuestion = null; $subQuestions = $survey->getSubQuestionArrays($questionId); foreach ($subQuestions as $question) { if ($question['title'] == $answerCode) { $subQuestion = $question; } } if (!empty($subQuestion) && !empty($subQuestion['question'])) { $subHeading .= ' [' . $this->stripTagsFull($subQuestion['question']) . ']'; } } //rtrim the result since it could be an empty string ' ' which //should be removed. return rtrim($subHeading); }
/** * Return the answer text according to options * * @param Survey $oSurvey * @param FormattingOptions $oOptions * @param string $fieldName * @param string $sValue * @return string */ public function getLongAnswer(SurveyObj $oSurvey, FormattingOptions $oOptions, $fieldName, $sValue) { return $this->transformResponseValue($oSurvey->getFullAnswer($fieldName, $sValue, $this->translator, $this->languageCode), $oSurvey->fieldMap[$fieldName]['type'], $oOptions, $fieldName); }
/** * Return the answer text according to options * * @param Survey $oSurvey * @param FormattingOptions $oOptions * @param string $fieldName * @param string $sValue * @return string */ public function getShortAnswer(SurveyObj $oSurvey, FormattingOptions $oOptions, $fieldName, $sValue) { return $this->transformResponseValue($oSurvey->getShortAnswer($fieldName, $sValue), $oSurvey->fieldMap[$fieldName]['type'], $oOptions, $fieldName); }