Skip to content

Commit

Permalink
Fixed issue #16744: No error shown at top even if error exist
Browse files Browse the repository at this point in the history
Dev: clean error between each step
Dev: add a global boolean haveError
Dev: return same than previously (errors seem unused)
Dev: english string
  • Loading branch information
Shnoulle committed Oct 16, 2020
1 parent a5ea515 commit b43c81d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 38 deletions.
10 changes: 10 additions & 0 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -1624,6 +1624,16 @@ public function ResetErrors()
$this->RDP_errs = array();
}

/**
* Reset current errors and current warnings
* @return void
*/
public function ResetErrorsAndWarnings()
{
$this->ResetErrors();
$this->ResetWarnings();
}

/**
* Return true if there are syntax errors
* @return boolean
Expand Down
134 changes: 96 additions & 38 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -9421,8 +9421,11 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$aAttributesDefinitions=\LimeSurvey\Helpers\questionHelper::getAttributesDefinitions();
/* All final survey string must be shown in survey language #12208 */
Yii::app()->setLanguage(Yii::app()->session['LEMlang']);
$allErrors = array();
/** @var array[] questions with warnings : gid,qid and count to create a list ? */
/* @var boolean , did have error */
$haveErrors = false;
/* @var integer[] Used at end for count, number of errors by question */
$allQuestionsErrors = array();
/* @var array[] questions with warnings : gid,qid and count to create a list (@todo) ? */
$aQuestionWarnings = array();
$warnings = 0;

Expand Down Expand Up @@ -9477,52 +9480,87 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
{
if ($aSurveyInfo['surveyls_description'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_description'],0);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td>" . $LEM->gT("Description:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("Description:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_welcometext'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_welcometext'],0);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td >" . $LEM->gT("Welcome:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("Welcome:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_endtext'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_endtext']);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td>" . $LEM->gT("End message:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("End message:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_url'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_urldescription']." - ".$aSurveyInfo['surveyls_url']);
$sPrint= viewHelper::purified($LEM->GetLastPrettyPrintExpression());
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td>" . $LEM->gT("End URL:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("End URL:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_policy_notice'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_policy_notice'],0);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td >" . $LEM->gT("Survey data policy notice:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("Survey data policy notice:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_policy_error'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_policy_error'],0);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td >" . $LEM->gT("Survey data policy error:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("Survey data policy error:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
if ($aSurveyInfo['surveyls_policy_notice_label'] != '')
{
$LEM->em->ResetErrorsAndWarnings();
$LEM->ProcessString($aSurveyInfo['surveyls_policy_notice_label'],0);
$sPrint= viewHelper::purified(viewHelper::filterScript($LEM->GetLastPrettyPrintExpression()));
$errClass = ($LEM->em->HasErrors() ? 'danger' : '');
$out .= "<tr class='LEMgroup $errClass'><td >" . $LEM->gT("Survey data policy label:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
$errClass = "";
if($LEM->em->HasErrors()) {
$errClass = 'danger';
$haveErrors = true;
}
$out .= "<tr class='LEMgroup'><td class='$errClass'>" . $LEM->gT("Survey data policy label:") . "</td><td colspan=\"3\">" . $sPrint . "</td></tr>";
}
}

Expand All @@ -9539,9 +9577,9 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$gid = $q['info']['gid'];
$qid = $q['info']['qid'];
$qseq = $q['info']['qseq'];
$LEM->em->ResetWarnings();
$LEM->em->ResetErrors();
$errorCount=0;
$LEM->em->ResetErrorsAndWarnings();
/* @var integer : count error for **this** question */
$errorCount = 0;
/* @var warnings information for current question, see ExpressionManager::RDP_warnings */
$aWarnings = array();

Expand All @@ -9567,6 +9605,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$errText = "";
if($bGroupHaveError)
{
$haveErrors = true;
$errClass = 'danger';
$errText = "<br><em class='label label-danger'>".$LEM->gT("This group has at least 1 error.")."</em>";
}
Expand All @@ -9577,8 +9616,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
. "<td>{$sGroupText}</td>"
. "</tr>\n";
$out .= $groupRow;
$LEM->em->ResetWarnings();
$LEM->em->ResetErrors();
$LEM->em->ResetErrorsAndWarnings();
}

//////
Expand All @@ -9601,7 +9639,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
$default = '<br />(' . $LEM->gT('Default:') . ' ' . $_default . ')';
}
else
Expand All @@ -9626,7 +9664,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
$sQuestionHelp = '<hr />[' . $LEM->gT("Help:") . ' ' . $sQuestionHelp . ']';
}
$prettyValidTip = (($q['prettyValidTip'] == '') ? '' : '<hr />(' . $LEM->gT("Tip:") . ' ' . viewHelper::stripTagsEM($q['prettyValidTip']) . ')');// Unsure need to filter
Expand Down Expand Up @@ -9673,7 +9711,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
}
if (is_null($value)) {
continue; // since continuing from within a switch statement doesn't work
Expand All @@ -9694,7 +9732,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
//////
// Must parse Relevance this way, otherwise if try to first split expressions, regex equations won't work
$relevanceEqn = (($q['info']['relevance'] == '') ? 1 : $q['info']['relevance']);
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
if (!isset($LEM->ParseResultCache[$relevanceEqn]))
{
$result = $LEM->em->ProcessBooleanExpression($relevanceEqn, $gseq, $qseq);
Expand All @@ -9706,7 +9744,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
'hasErrors' => $hasErrors,
'aWarnings'=> $LEM->em->GetWarnings(),
);
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
}
$relevance = $LEM->ParseResultCache[$relevanceEqn]['prettyprint'];
if ($LEM->ParseResultCache[$relevanceEqn]['hasErrors']) {
Expand All @@ -9732,7 +9770,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
'hasErrors' => $hasErrors,
'aWarnings'=> $LEM->em->GetWarnings(),
);
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
}
$prettyValidEqn = '<hr />(VALIDATION: ' . $LEM->ParseResultCache[$validationEqn]['prettyprint'] . ')';
if ($LEM->ParseResultCache[$validationEqn]['hasErrors']) {
Expand Down Expand Up @@ -9834,7 +9872,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$sq['aWarnings']);
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
}

$sgqaInfo = $LEM->knownVars[$sgqa];
Expand All @@ -9846,7 +9884,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
if (isset($sgqaInfo['default']) && $sgqaInfo['default'] !== '')
{
$LEM->ProcessString($sgqaInfo['default'], $qid,$qReplacement,1,1,false,false);
Expand All @@ -9855,7 +9893,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
$subQeqn .= '<br />(' . $LEM->gT('Default:') . ' ' . $_default . ')';
}
$sqRows .= "<tr class='LEMsubq'>"
Expand Down Expand Up @@ -9906,7 +9944,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
}
$sAnswerText=$valInfo[1];
$LEM->ProcessString($sAnswerText, $qid,$qReplacement,1,1,false,false);
Expand All @@ -9915,7 +9953,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
++$errorCount;
}
$aWarnings = array_merge($aWarnings,$LEM->em->GetWarnings());
$LEM->em->ResetWarnings();
$LEM->em->ResetErrorsAndWarnings();
$answerRows .= "<tr class='LEManswer'>"
. "<td>A[" . $ansInfo[0] . "]-" . $i++ . "</td>"
. "<td><b>" . $ansInfo[1]. "</b></td>"
Expand Down Expand Up @@ -9966,8 +10004,9 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$out .= $sqRows;
$out .= $answerRows;

if ($errorCount > 0) {
$allErrors[$gid . '~' . $qid] = $errorCount;
if ($errorCount) {
$allQuestionsErrors[$gid . '~' . $qid] = $errorCount;
$haveErrors = true;
}
}
$out .= "</table>";
Expand All @@ -9976,12 +10015,31 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
if (($LEMdebugLevel & LEM_DEBUG_TIMING) == LEM_DEBUG_TIMING) {
$out .= LimeExpressionManager::GetDebugTimingMessage();
}
// Here it's added at top
// Here it's added at top
if(count($aQuestionWarnings) > 0) {
$out = "<p class='alert alert-warning'>". $LEM->ngT("{n} question contains warnings that need to be verified.|{n} questions contain warnings that need to be verified.", count($aQuestionWarnings)) . "</p>\n" . $out;
}
if (count($allErrors) > 0) {
$out = "<p class='alert alert-danger'>". $LEM->ngT("{n} question contains errors that need to be corrected.|{n} questions contain errors that need to be corrected.", count($allErrors)) . "</p>\n" . $out;
if($haveErrors) {
if (count($allQuestionsErrors) > 0) {
$out = "<p class='alert alert-danger'>". $LEM->ngT("{n} question contains errors that need to be corrected.|{n} questions contain errors that need to be corrected.", count($allQuestionsErrors)) . "</p>\n" . $out;
} else {
switch ($surveyMode)
{
case 'survey':
$message = $LEM->gT('There are expressions with syntax errors in this survey.');
break;
case 'group':
$message = $LEM->gT('There are expressions with syntax errors in thisgroup.');
break;
case 'question':
$message = $LEM->gT('There are expressions with syntax errors in this question.');// How can happen
break;
default:
$message = $LEM->gT('There are expressions with syntax errors.');// How can happen;
break;
}
$out = "<p class='alert alert-danger'>{$message}</p>\n" . $out;
}
} else {
switch ($surveyMode)
{
Expand All @@ -10003,7 +10061,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL

$out .="</div>";
return array(
'errors'=>$allErrors,
'errors'=>$allQuestionsErrors,
'html'=>$out
);
}
Expand Down

0 comments on commit b43c81d

Please sign in to comment.