From a83ebf8eb053c942b1bcc27c3a5e3db45c7e69d0 Mon Sep 17 00:00:00 2001 From: Olle Harstedt Date: Thu, 6 Oct 2016 21:18:26 +0200 Subject: [PATCH] Dev: Factored out getAnswer() and getQuestionCodes() to helper --- application/helpers/QuestionObjectHelper.php | 32 ++++++++++++++++++++ application/helpers/qanda_helper.php | 18 +++++------ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/application/helpers/QuestionObjectHelper.php b/application/helpers/QuestionObjectHelper.php index e1ebb1452ae..923bb5f203c 100644 --- a/application/helpers/QuestionObjectHelper.php +++ b/application/helpers/QuestionObjectHelper.php @@ -49,6 +49,38 @@ public static function getDatabaseFieldTypes($row) return $question->getDatabaseFieldTypes($row); } + /** + * @param string $extendedType + */ + public static function getQuestionText($extendedType) + { + $question = self::getInstance($extendedType); + return $question->getQuestionText(); + } + + /** + * @param string $extendedType + * @return string html + */ + public static function getAnswer($extendedType, $ia, $aQuestionAttributes, $oQuestion) + { + $question = self::getInstance($extendedType); + $question->setIa($ia); + $question->setQuestionAttributes($aQuestionAttributes); + $question->setQuestionModel($oQuestion); + return $question->getAnswer(); + } + + /** + * @param string $extendedType + * @return array + */ + public static function getQuestionCodes($extendedType) + { + $question = self::getInstance($extendedType); + return $question->getQuestionCodes(); + } + /** * @todo Validate $extendedType * @todo Check if extended type is core type diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 3274778b8c2..df0d07e77a5 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -341,9 +341,7 @@ function composeQuestionText(array $ia, array $aQuestionAttributes, Question $oQ // Check for question objects if ($ia[4] == '?') { - // TODO: Check extended_type here - $question = TestQuestionObject::getInstance(); - return $question->getQuestionText(); + return \ls\helpers\QuestionObjectHelper::getQuestionText($oQuestion->extended_type); } $number = isset($ia[9]) ? $ia[9] : ''; // Previously in limesurvey, it was virtually impossible to control how the start of questions were formatted. // this is an attempt to allow users (or rather system admins) some control over how the starting text is formatted. @@ -839,13 +837,13 @@ function do_equation($ia) */ function do_question_object(array $ia, array $aQuestionAttributes, Question $oQuestion) { - $question = TestQuestionObject::getInstance(); - $question->setIa($ia); - $question->setQuestionAttributes($aQuestionAttributes); - $question->setQuestionModel($oQuestion); - - $answer = $question->getAnswer(); - $inputnames = $question->getQuestionCodes(); + $answer = \ls\helpers\QuestionObjectHelper::getAnswer( + $oQuestion->extended_type, + $ia, + $aQuestionAttributes, + $oQuestion + ); + $inputnames = \ls\helpers\QuestionObjectHelper::getQuestionCodes($oQuestion->extended_type); return array($answer, $inputnames); }