Skip to content

Commit

Permalink
Dev: Factored out getAnswer() and getQuestionCodes() to helper
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 6, 2016
1 parent 7bf7237 commit a83ebf8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
32 changes: 32 additions & 0 deletions application/helpers/QuestionObjectHelper.php
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions application/helpers/qanda_helper.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a83ebf8

Please sign in to comment.