Skip to content

Commit

Permalink
New feature #09554: add the possibility to change an answer value wit…
Browse files Browse the repository at this point in the history
…h plugin event beforeQuestionRender()

Dev: quickly done, replaced by complete function in 2.06
Dev: see http://bugs.limesurvey.org/view.php?id=9500
  • Loading branch information
Shnoulle committed Mar 6, 2015
1 parent 72eee7e commit 9618b2f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions application/helpers/replacements_helper.php
Expand Up @@ -242,11 +242,17 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$event->set('type', $question['type']);
$event->set('code', $question['code']);
$event->set('qid', $question['qid']);
$event->set('answers',isset($answer) ? $answer : null);
$event->set('questionhelp',isset($help) ? $help : null);

App()->getPluginManager()->dispatchEvent($event);
$question['text'] = $event->get('text');
$question['class'] = $event->get('class');
$question['help'] = $event->get('help');
$question['mandatory'] = $event->get('mandatory',$question['mandatory']);
$question['answers'] = $event->get('answers');
$question['questionhelp'] = $event->get('questionhelp');

// answer part ?
// $answer is set with answer part
$_question = $question['all'];
Expand Down Expand Up @@ -415,8 +421,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
{
$_saveall = "";
}

if(!isset($help)) $help = "";
$help= isset($question['questionhelp']) ? $question['questionhelp'] : isset($help) ? $help : "";
if (flattenText($help, true,true) != '')
{
if (!isset($helpicon))
Expand Down Expand Up @@ -725,7 +730,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$coreReplacements = array();
$coreReplacements['ACTIVE'] = (isset($thissurvey['active']) && !($thissurvey['active'] != "Y"));
$coreReplacements['AID'] = $question['aid'];
$coreReplacements['ANSWER'] = isset($answer) ? $answer : ''; // global
$coreReplacements['ANSWER'] = isset($question['answers']) ? $question['answers'] : isset($answer) ? $answer : ''; // global
$coreReplacements['ANSWERSCLEARED'] = $clang->gT("Answers cleared");
$coreReplacements['ASSESSMENTS'] = $assessmenthtml;
$coreReplacements['ASSESSMENT_CURRENT_TOTAL'] = $_assessment_current_total;
Expand Down

5 comments on commit 9618b2f

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great - thank you!

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GID is still missing.

@KRav007
Copy link
Contributor

@KRav007 KRav007 commented on 9618b2f Mar 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey denis, thank you very much for that fast commit!

@KRav007
Copy link
Contributor

@KRav007 KRav007 commented on 9618b2f Mar 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I test it, and it seems that the this:
$question['answers'] = $event->get('answers');

is not working. This works:

$answer = $event->get('answers');

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed : 5500ed6

I prefer to not rework completely, at start : i'm not sure $answer is returned at the same time than $question (maybe "print survey page for example).

Please sign in to comment.