Skip to content

Commit

Permalink
Merge pull request #36 from pdir/bugfix_and_reference-db
Browse files Browse the repository at this point in the history
Bugfix and reference db
  • Loading branch information
MDevster authored Apr 18, 2023
2 parents 711f7d2 + 18e2d89 commit c444b00
Show file tree
Hide file tree
Showing 15 changed files with 710 additions and 224 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{php,yml}]
indent_style = space
indent_size = 4

[*.{css,scss,js,twig,html5}]
indent_style = space
indent_size = 2

[*.{html5,svg,min.css,min.js}]
insert_final_newline = false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Types of changes
Security in case of vulnerabilities.
)

## [3.4.3](https://github.com/pdir/contao-survey/tree/3.4.3) – 2023-04-18

- [Removed] ...the obsolete attribute **summary** were replaced by the html5-attribute **details** in the templates.
- [Added] ...survey reference tables to define a consistent basis for survey testing [#36](https://github.com/pdir/contao-survey/issues/36).
- [Fixed] ...an error in the widget title display [#33](https://github.com/pdir/contao-survey/issues/33).
- [Fixed] ...some more PHP8 warnings caused by wrong array keys. The answer option 'other' is now displayed correctly in all cases [#31](https://github.com/pdir/contao-survey/issues/31).
- [Fixed] ...some PHP8 warnings caused by wrong array keys [#30](https://github.com/pdir/contao-survey/issues/30).

## [3.4.2](https://github.com/pdir/contao-survey/tree/3.4.2) – 2023-02-27

- [Fixed] An error in the condition that determines the necessity of choices field migration. 🤗 [akroii](https://github.com/akroii) for the financial support.
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ A special thanks goes to Georg Rehfeld for his development of the detailed surve

Made with [contributors-img](https://contrib.rocks).

# run before commit
# Notes for developers

#### Run before commit

vendor/bin/ecs check src tests

#### Test your changes using the survey tables included in the package.

With version 3.4.3 we have added survey tables to the package to allow consistent testing. You can find the tables in the
reference-survey.sql file in the _misc folder. So if you want to test the behavior of your changed code in a
reproducible way, please use these tables.

If you make changes to the survey tables, please commit them also to the reference-survey.sql so developers can
test their own code against this reference survey.

Load the tables into your DB and activate Survey 1, which consists of
five question pages and one results page. For now, you'll need to manually load these tables into your DB, but
we're working on automating the tests a bit more.

The question pages cover all the questions that the package currently offers. The results page shows the results
of the question pages. Currently, however, there are unfortunately still errors on the results page.


vendor/bin/ecs check src tests
307 changes: 307 additions & 0 deletions _misc/reference-survey.sql

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/Resources/contao/classes/SurveyQuestionConstantsum.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ protected function calculateCumulated(): void

if (\is_array($arrAnswer)) {
foreach ($arrAnswer as $answerkey => $answervalue) {
++$cumulated[$answerkey][$answervalue];
if(array_key_exists($answerkey, $cumulated)) {
if(array_key_exists($answervalue, $cumulated[$answerkey])) {
++$cumulated[$answerkey][$answervalue];
} else {
$cumulated[$answerkey][$answervalue] = 1;
}
} else {
$cumulated[$answerkey] = [];
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Resources/contao/classes/SurveyQuestionMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public function resultAsString($res)
$arrAnswer = deserialize($res, true);

if (\is_array($arrAnswer)) {
return implode(', ', $arrAnswer);
// ToDo: fix the following workaround
// $arrAnswer can also be a multidimensional array here, which then does not work
return @implode(', ', $arrAnswer);
}

return '';
Expand Down Expand Up @@ -216,7 +218,8 @@ protected function calculateCumulated(): void
++$cumulated[$row][$singleanswervalue];
}
} else {
++$cumulated[$row][$answervalue];
// ToDo: fix this workaround
@++$cumulated[$row][$answervalue];
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/contao/classes/SurveyQuestionMultiplechoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public function getResultData(): array
* an array of the form question.id => result, where result can be array or string|int
* like
* [5 => "1", 6 => [2 => "1", 4 => "1"]]
* where "1" means selected,
*
* where "1" means that the answer was selected,
*/
if (null === $this->resultData) {
$result = [];
Expand Down Expand Up @@ -102,6 +101,7 @@ public function getResultData(): array
public function getAnswersAsHTML()
{
if (!empty($resultData = $this->getResultData())) {

$survey = SurveyModel::findByQuestionId((int) $this->id);

$template = new FrontendTemplate('survey_answers_multiplechoice');
Expand All @@ -118,7 +118,8 @@ public function getAnswersAsHTML()

if (\count($this->statistics['cumulated']['other'])) {
foreach ($this->statistics['cumulated']['other'] as $value) {
++$otherchoices[StringUtil::specialchars($value)];
$key = StringUtil::specialchars($value);
if(array_key_exists($key, $otherchoices)) ++$otherchoices[$key]; else $otherchoices[$key] = 1;
}
}
$template->otherchoices = $otherchoices;
Expand Down
30 changes: 15 additions & 15 deletions src/Resources/contao/forms/FormOpenEndedQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __set($strKey, $varValue): void
switch ($strKey) {
case 'surveydata':
parent::__set($strKey, $varValue);
$this->strClass = 'openended'.((\strlen($varValue['cssClass']) ? ' '.$varValue['cssClass'] : ''));
$this->strClass = 'openended'.((!empty($varValue['cssClass']) ? ' '.$varValue['cssClass'] : ''));
$this->strTextBefore = $varValue['openended_textbefore'];
$this->strTextAfter = $varValue['openended_textafter'];
$this->questiontype = $varValue['openended_subtype'];
Expand Down Expand Up @@ -143,15 +143,15 @@ public function generate()
$template = new FrontendTemplate('survey_question_openended');
$template->ctrl_name = StringUtil::specialchars($this->strName);
$template->ctrl_id = StringUtil::specialchars($this->strId);
$template->ctrl_class = (\strlen($this->strClass) ? ' '.$this->strClass : '');
$template->ctrl_class = (!empty($this->strClass) ? ' '.$this->strClass : '');
$template->multiLine = 0 === strcmp($this->questiontype, 'oe_multiline');
$template->singleLine = 0 === strcmp($this->questiontype, 'oe_singleline');
$template->value = $this->varValue;
$template->textBefore = $this->strTextBefore;
$template->textAfter = $this->strTextAfter;
$template->attributes = $this->getAttributes();
$strError = $this->getErrorAsHTML();
$template->blnError = (\strlen($strError) ? true : false);
$template->blnError = (!empty($strError) ? true : false);
$widget = $template->parse();
$widget .= $this->addSubmit();

Expand All @@ -160,19 +160,19 @@ public function generate()

protected function setData_oe_singleline($varValue): void
{
if (\strlen($varValue['openended_width'])) {
if (!empty($varValue['openended_width'])) {
$this->arrAttributes['size'] = StringUtil::specialchars($varValue['openended_width']);
}

if (\strlen($varValue['openended_maxlen'])) {
if (!empty($varValue['openended_maxlen'])) {
$this->arrAttributes['maxlength'] = StringUtil::specialchars($varValue['openended_maxlen']);
}

if (\strlen($varValue['openended_textinside'])) {
if (!empty($varValue['openended_textinside'])) {
$this->arrAttributes['value'] = StringUtil::specialchars($varValue['openended_textinside']);
}

if (\strlen($this->varValue)) {
if (!empty($this->varValue)) {
$this->arrAttributes['value'] = StringUtil::specialchars($this->varValue);
}
}
Expand All @@ -199,16 +199,16 @@ protected function setData_oe_time($varValue): void

protected function setData_oe_multiline($varValue): void
{
if (\strlen($varValue['openended_rows'])) {
if (!empty($varValue['openended_rows'])) {
$this->arrAttributes['rows'] = StringUtil::specialchars($varValue['openended_rows']);
}

if (\strlen($varValue['openended_cols'])) {
if (!empty($varValue['openended_cols'])) {
$this->arrAttributes['cols'] = StringUtil::specialchars($varValue['openended_cols']);
}

if (!\strlen($this->varValue)) {
if (\strlen($varValue['openended_textinside'])) {
if (!!empty($this->varValue)) {
if (!empty($varValue['openended_textinside'])) {
$this->varValue = $varValue['openended_textinside'];
}
}
Expand All @@ -225,7 +225,7 @@ protected function setData_oe_multiline($varValue): void
protected function validator($varInput)
{
$oldlabel = $this->label;
$label = \strlen($this->label) ? $this->label : $this->title;
$label = !empty($this->label) ? $this->label : $this->title;
$this->label = $label;

if (\is_array($varInput)) {
Expand All @@ -249,14 +249,14 @@ protected function validator($varInput)
*/
protected function check_bounds($varInput)
{
if ($this->hasErrors() || !\strlen($varInput)) {
if ($this->hasErrors() || empty($varInput)) {
// Don't check any further, value might not be a valid string to be compared against bounds
return $varInput;
}

$result = $varInput;

if (\strlen($this->strLowerBound)) {
if (!empty($this->strLowerBound)) {
$strErrMsg = $GLOBALS['TL_LANG']['ERR']['lower_bound'];
$lower = (int) ($this->strLowerBound);

Expand Down Expand Up @@ -306,7 +306,7 @@ protected function check_bounds($varInput)
}
}

if (\strlen($this->strUpperBound)) {
if (!empty($this->strUpperBound)) {
$strErrMsg = $GLOBALS['TL_LANG']['ERR']['upper_bound'];
$upper = (int) ($this->strUpperBound);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<a href="<?php echo $this->hrefBack; ?>" class="header_back" title="<?php echo $this->back; ?>" accesskey="b" onclick="Backend.getScrollOffset();"><?php echo $this->back; ?></a>
</div>
<h2 class="sub_headline"><?php echo $this->heading; ?></h2>
<table cellpadding="0" cellspacing="0" class="tl_show" summary="<?php echo $this->summary; ?>">
<?php foreach ($this->data as $data): ?>
<table cellpadding="0" cellspacing="0" class="tl_show">
<details noflow><?php echo $this->summary; ?></details>
<?php foreach ($this->data as $data): ?>
<tr>
<td class="<?php echo $data["keyclass"] ?>"><span class="tl_label"><?php echo $data["key"] ?></span></td>
<td class="<?php echo $data["valueclass"] ?>"><?php echo $data["value"] ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
<div id="tl_buttons">
<a href="<?php echo $this->hrefBack; ?>" class="header_back" title="<?php echo $this->back; ?>" accesskey="b" onclick="Backend.getScrollOffset();"><?php echo $this->back; ?></a>
<a href="<?php echo $this->hrefExport; ?>" class="header_export" title="<?php echo $this->export; ?>" onclick="Backend.getScrollOffset();"><?php echo $this->export; ?></a>
<a href="<?php echo $this->hrefBack; ?>" class="header_back" title="<?php echo $this->back; ?>" accesskey="b"
onclick="Backend.getScrollOffset();"><?php echo $this->back; ?></a>
<a href="<?php echo $this->hrefExport; ?>" class="header_export" title="<?php echo $this->export; ?>"
onclick="Backend.getScrollOffset();"><?php echo $this->export; ?></a>
</div>

<?php if (!empty($this->categories)): ?>
<div class="tl_survey_results_categories">
<h2 class="sub_headline"><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['categoryResults'] ?? 'Categories') ?></h2>
<div class="tl_survey_results_categories">
<h2
class="sub_headline"><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['categoryResults'] ?? 'Categories') ?></h2>

<table class="tl_cumulated multiplechoice">
<thead>
<tr>
<th colspan="2"><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['category'] ?? 'Category') ?></th>
<th><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['percent'] ?? 'Percent') ?></th>
</tr>
</thead>
<tbody>
<?php $counter = 1; ?>
<?php foreach ($this->categories as $id => $category): ?>
<tr>
<td class="counter"><?php echo $counter; ?>.</td>
<td class="answer"><?php echo $category['name']; ?></td>
<td class="selections"><?php echo $category['percent']; ?>%</td>
</tr>
<?php $counter++; ?>
<?php endforeach; ?>
</tbody>
</table>
<table class="tl_cumulated multiplechoice">
<thead>
<tr>
<th colspan="2"><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['category'] ?? 'Category') ?></th>
<th><?= ($GLOBALS['TL_LANG']['tl_survey_result']['BE']['percent'] ?? 'Percent') ?></th>
</tr>
</thead>
<tbody>
<?php $counter = 1; ?>
<?php foreach ($this->categories as $id => $category): ?>
<tr>
<td class="counter"><?php echo $counter; ?>.</td>
<td class="answer"><?php echo $category['name']; ?></td>
<td class="selections"><?php echo $category['percent']; ?>%</td>
</tr>
<?php $counter++; ?>
<?php endforeach; ?>
</tbody>
</table>


</div>
</div>
<?php endif; ?>

<div class="tl_survey_results_cumulated">
<div class="tl_listing_container">
<h2><?php echo $this->heading; ?></h2>
<table cellpadding="0" cellspacing="0" class="tl_listing" summary="<?php echo $this->summary; ?>">
<?php foreach ($this->data as $data): ?>
<tr onmouseover="Theme.hoverRow(this, 1);" onmouseout="Theme.hoverRow(this, 0);">
<td class="tl_file_list"><div class="questionheader"><span class="questionnumber"><?php echo $data["number"] ?>.</span> <span class="questiontitle"><?php echo $data["title"] ?></span> <span class="questiontype">[<?php echo $data["type"] ?>]</span></div><div class="statdata"><div><?php echo $this->lngAnswered ?>: <?php echo $data["answered"] ?></div><div><?php echo $this->lngSkipped; ?>: <?php echo $data["skipped"] ?></div></div></td>
<td class="tl_file_list tl_right_nowrap"><a href="<?php echo $data["hrefdetails"] ?>" title="<?php echo $data["titledetails"] ?>"><img src="<?php echo $this->imgdetails; ?>" width="16" height="16" alt="<?php echo $data["titledetails"] ?>" /></a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="tl_listing_container">
<h2><?php echo $this->heading; ?></h2>
<table cellpadding="0" cellspacing="0" class="tl_listing">
<details noflow><?php echo $this->summary; ?></details>
<?php foreach ($this->data as $data): ?>
<tr onmouseover="Theme.hoverRow(this, 1);" onmouseout="Theme.hoverRow(this, 0);">
<td class="tl_file_list">
<div class="questionheader"><span class="questionnumber"><?php echo $data["number"] ?>.</span> <span
class="questiontitle"><?php echo $data["title"] ?></span> <span
class="questiontype">[<?php echo $data["type"] ?>]</span></div>
<div class="statdata">
<div><?php echo $this->lngAnswered ?>: <?php echo $data["answered"] ?></div>
<div><?php echo $this->lngSkipped; ?>: <?php echo $data["skipped"] ?></div>
</div>
</td>
<td class="tl_file_list tl_right_nowrap"><a href="<?php echo $data[" hrefdetails"] ?>"
title="<?php echo $data["titledetails"] ?>"><img src="<?php echo $this->imgdetails; ?>" width="16" height="16"
alt="<?php echo $data[" titledetails"] ?>" /></a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>

Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php $counter = 1; ?>
<?php foreach ($this->choices as $id => $choice): ?>
<h3><?php echo $counter; ?>. <?php echo $choice; ?></h3>
<table class="tl_cumulated constantsum" summary="<?php echo $this->summary; ?>">
<thead>
<tr>
<th colspan="2"><?php echo $this->answer; ?></th>
<th><?php echo $this->nrOfSelections; ?></th>
</tr>
</thead>
<tbody>
<?php $linecounter = 1; ?>
<?php foreach ($this->cumulated[$counter] as $answervalue => $nrOfAnswers): ?>
<tr>
<td class="counter"><?php echo $linecounter; ?>.</td>
<td class="answer"><?php echo $answervalue; ?></td>
<td class="selections"><?php echo (($nrOfAnswers) ? $nrOfAnswers : 0); ?></td>
</tr>
<?php $linecounter++; ?>
<?php endforeach; ?>
<?php $counter++; ?>
</tbody>
<table class="tl_cumulated constantsum">
<details noflow><?php echo $this->summary; ?></details>
<thead>
<tr>
<th colspan="2"><?php echo $this->answer; ?></th>
<th><?php echo $this->nrOfSelections; ?></th>
</tr>
</thead>
<tbody>
<?php $linecounter = 1; ?>
<?php foreach ($this->cumulated[$counter] as $answervalue => $nrOfAnswers): ?>
<tr>
<td class="counter"><?php echo $linecounter; ?>.</td>
<td class="answer"><?php echo $answervalue; ?></td>
<td class="selections"><?php echo (($nrOfAnswers) ? $nrOfAnswers : 0); ?></td>
</tr>
<?php $linecounter++; ?>
<?php endforeach; ?>
<?php $counter++; ?>
</tbody>
</table>
<?php endforeach; ?>
Loading

0 comments on commit c444b00

Please sign in to comment.