Skip to content

Commit

Permalink
Fixed text output for multiple choice questions
Browse files Browse the repository at this point in the history
Added additional fields to support a conditional alternate confirmation email
  • Loading branch information
hschottm committed Mar 1, 2019
1 parent 8964d5a commit e4efb46
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 69 deletions.
10 changes: 0 additions & 10 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ services:
Symfony\Component\DependencyInjection\ContainerAwareInterface:
calls:
- ["setContainer", ["@service_container"]]

contao_news.picker.news_provider:
class: Hschottm\SurveyBundle\Picker\SurveyPickerProvider
arguments:
- "@knp_menu.factory"
- "@router"
calls:
- [setTokenStorage, ["@security.token_storage"]]
tags:
- { name: contao.picker_provider, priority: 128 }
4 changes: 1 addition & 3 deletions src/Resources/contao/classes/SurveyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function replaceTags($source, $uidOrPin, $replacements = array(), $blnIsH
break;
}
}

$source = preg_replace(array('/__BRCL__/', '/__BRCR__/'), array('{{', '}}'), $source);
$source = $this->replaceInsertTags($source, false);
if ($blnEvalSource)
Expand Down Expand Up @@ -154,8 +153,7 @@ public function evalConditionTags($strBuffer)
}

$strReturn = str_replace('?><br />', '?>', $strBuffer);

// Eval the code
// Eval the code
ob_start();
$blnEval = eval("?>" . $strReturn);
$strReturn = ob_get_contents();
Expand Down
54 changes: 36 additions & 18 deletions src/Resources/contao/classes/SurveyQuestionMultiplechoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,25 +455,43 @@ protected function exportDetailResults(&$exporter, $sheet, &$row, &$col, $partic
return $cells;
}

public function resultAsString($res)
{
$arrAnswer = deserialize($res, true);
$arrChoices = (strcmp($this->arrData['multiplechoice_subtype'], 'mc_dichotomous') != 0) ? deserialize($this->arrData['choices'], true) : array(0 => $GLOBALS['TL_LANG']['tl_survey_question']['yes'], 1 => $GLOBALS['TL_LANG']['tl_survey_question']['no']);
if (is_array($arrAnswer['value']))
{
foreach ($arrAnswer['value'] as $key => $val)
public function resultAsString($res)
{
$selections[] = $arrChoices[$val-1];
}
return implode (", ", $selections);
}
else
{
return $arrChoices[is_numeric($arrAnswer['value']) ? $arrAnswer['value']-1 : -1];
}
if (strlen($arrAnswer['other']))
$arrAnswer = deserialize($res, true);
$arrChoices = (strcmp($this->arrData['multiplechoice_subtype'], 'mc_dichotomous') != 0) ? deserialize($this->arrData['choices'], true) : array(0 => $GLOBALS['TL_LANG']['tl_survey_question']['yes'], 1 => $GLOBALS['TL_LANG']['tl_survey_question']['no']);
if (is_array($arrAnswer['value']))
{
foreach ($arrAnswer['value'] as $key => $val)
{
return $arrAnswer['other'];
$selections[] = $arrChoices[$val-1];
}
}
return implode (", ", $selections);
}
else
{
return $arrChoices[is_numeric($arrAnswer['value']) ? $arrAnswer['value']-1 : -1];
}
if (strlen($arrAnswer['other']))
{
return $arrAnswer['other'];
}
}

/*public function resultAsString($res)
{
$arrAnswer = deserialize($res, true);
if (is_array($arrAnswer['value']))
{
return implode (", ", $arrAnswer['value']);
}
else
{
$arrChoices = (strcmp($this->arrData['multiplechoice_subtype'], 'mc_dichotomous') != 0) ? deserialize($this->arrData['choices'], true) : array(0 => $GLOBALS['TL_LANG']['tl_survey_question']['yes'], 1 => $GLOBALS['TL_LANG']['tl_survey_question']['no']);
return $arrChoices[$arrAnswer['value']-1];
}
if (strlen($arrAnswer['other']))
{
return $arrAnswer['other'];
}
}*/
}
108 changes: 99 additions & 9 deletions src/Resources/contao/dca/tl_survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@
'palettes' => [
'__selector__' => ['access', 'limit_groups'],
'default' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end',
'anon' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail;{misc_legend},allowback,immediate_start,jumpto',
'anoncode' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail;{misc_legend},allowback,immediate_start,jumpto',
'nonanoncode' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie,limit_groups;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail;{misc_legend},allowback,immediate_start,jumpto',
'anon' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail,sendConfirmationMailAlternate;{misc_legend},allowback,immediate_start,jumpto',
'anoncode' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail,sendConfirmationMailAlternate;{misc_legend},allowback,immediate_start,jumpto',
'nonanoncode' => '{title_legend},title,author,description,language;{activation_legend},online_start,online_end;{access_legend},access,usecookie,limit_groups;{texts_legend},introduction,finalsubmission;{head_legend},show_title,show_cancel;{sendconfirmationmail_legend:hide},sendConfirmationMail,sendConfirmationMailAlternate;{misc_legend},allowback,immediate_start,jumpto',
],

// Palettes
Expand Down Expand Up @@ -257,14 +257,14 @@
];

$GLOBALS['TL_DCA']['tl_survey']['palettes']['__selector__'][] = 'sendConfirmationMail';
$GLOBALS['TL_DCA']['tl_survey']['palettes']['__selector__'][] = 'sendConfirmationMailAlternate';
$GLOBALS['TL_DCA']['tl_survey']['palettes']['__selector__'][] = 'addConfirmationMailAttachments';
$GLOBALS['TL_DCA']['tl_survey']['palettes']['__selector__'][] = 'addConfirmationMailAlternateAttachments';

array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']),
array('sendConfirmationMail' => 'confirmationMailRecipientField,confirmationMailRecipient,confirmationMailSender,confirmationMailReplyto,confirmationMailSubject,confirmationMailText,confirmationMailTemplate,addConfirmationMailAttachments')
);
array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']),
array('addConfirmationMailAttachments' => 'confirmationMailAttachments')
);
array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']), array('sendConfirmationMail' => 'confirmationMailRecipientField,confirmationMailRecipient,confirmationMailSender,confirmationMailReplyto,confirmationMailSubject,confirmationMailText,confirmationMailTemplate,addConfirmationMailAttachments'));
array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']), array('sendConfirmationMailAlternate' => 'confirmationMailAlternateCondition,confirmationMailAlternateRecipient,confirmationMailAlternateSender,confirmationMailAlternateReplyto,confirmationMailAlternateSubject,confirmationMailAlternateText,confirmationMailAlternateTemplate,addConfirmationMailAlternateAttachments'));
array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']), array('addConfirmationMailAttachments' => 'confirmationMailAttachments'));
array_insert($GLOBALS['TL_DCA']['tl_survey']['subpalettes'], count($GLOBALS['TL_DCA']['tl_survey']['subpalettes']), array('addConfirmationMailAlternateAttachments' => 'confirmationMailAlternateAttachments'));

$GLOBALS['TL_DCA']['tl_survey']['fields']['sendConfirmationMail'] = array
(
Expand All @@ -275,6 +275,24 @@
'eval' => array('helpwizard'=>true,'submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['sendConfirmationMailAlternate'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['sendConfirmationMailAlternate'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('helpwizard'=>true,'submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateCondition'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateCondition'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailRecipientField'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailRecipientField'],
Expand All @@ -294,6 +312,15 @@
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateRecipient'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateRecipient'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailSender'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailSender'],
Expand All @@ -303,6 +330,15 @@
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateSender'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateSender'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailReplyto'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailReplyto'],
Expand All @@ -312,6 +348,15 @@
'eval' => array('mandatory'=>false, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateReplyto'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateReplyto'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('mandatory'=>false, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailSubject'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailSubject'],
Expand All @@ -321,6 +366,15 @@
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateSubject'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateSubject'],
'exclude' => true,
'filter' => false,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailText'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailText'],
Expand All @@ -330,6 +384,15 @@
'eval' => array('mandatory'=>true, 'rows'=>15, 'allowHTML'=>false, 'tl_class' => 'clr'),
'sql' => "text NULL"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateText'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateText'],
'exclude' => true,
'filter' => false,
'inputType' => 'textarea',
'eval' => array('mandatory'=>true, 'rows'=>15, 'allowHTML'=>false, 'tl_class' => 'clr'),
'sql' => "text NULL"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailTemplate'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailTemplate'],
Expand All @@ -339,6 +402,15 @@
'eval' => array('helpwizard'=>false,'files'=>true, 'fieldType'=>'radio', 'extensions' => 'htm,html,txt,tpl'),
'sql' => "binary(16) NULL"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateTemplate'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateTemplate'],
'exclude' => true,
'filter' => false,
'inputType' => 'fileTree',
'eval' => array('helpwizard'=>false,'files'=>true, 'fieldType'=>'radio', 'extensions' => 'htm,html,txt,tpl'),
'sql' => "binary(16) NULL"
);

$GLOBALS['TL_DCA']['tl_survey']['fields']['sendFormattedMail'] = array
(
Expand Down Expand Up @@ -405,6 +477,15 @@
'eval' => array('submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['addConfirmationMailAlternateAttachments'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['addConfirmationMailAlternateAttachments'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAttachments'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAttachments'],
Expand All @@ -414,6 +495,15 @@
'eval' => array('fieldType'=>'checkbox', 'files'=>true, 'filesOnly'=>true, 'multiple' => true, 'mandatory'=>true),
'sql' => "blob NULL"
);
$GLOBALS['TL_DCA']['tl_survey']['fields']['confirmationMailAlternateAttachments'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_survey']['confirmationMailAlternateAttachments'],
'exclude' => true,
'filter' => false,
'inputType' => 'fileTree',
'eval' => array('fieldType'=>'checkbox', 'files'=>true, 'filesOnly'=>true, 'multiple' => true, 'mandatory'=>true),
'sql' => "blob NULL"
);


if ($hasData) {
Expand Down
Loading

0 comments on commit e4efb46

Please sign in to comment.