Skip to content

Commit

Permalink
Fixed issue#05766: exclude_all_others_auto does not work
Browse files Browse the repository at this point in the history
Dev Now works properly even if question is array_filtered (e.g. sets exclusive option if all other visible/relevant options are set)
  • Loading branch information
TMSWhite committed May 15, 2012
1 parent c16bb49 commit 114cef2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 90 deletions.
75 changes: 73 additions & 2 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -624,7 +624,12 @@ class LimeExpressionManager {
* @var array
*/
private $qrootVarName2arrayFilter = array();

/**
* Array, keyed on qid, to JavaScript needed to implement exclude_all_others_auto
* @var type
*/
private $qid2exclusiveAutoJS = array();

/**
* A private constructor; prevents direct creation of object
*/
Expand Down Expand Up @@ -1224,7 +1229,62 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
// exclude_all_others_auto
// if (count(this.relevanceStatus) == count(this)) { set exclusive option value to "Y" and call checkconditions() }
// However, note that would need to blank the values, not use relevance, otherwise can't unclick the _auto option without having it re-enable itself
// TODO
if (isset($qattr['exclude_all_others_auto']) && trim($qattr['exclude_all_others_auto']) != ''
&& isset($qattr['exclude_all_others']) && count(explode(';',trim($qattr['exclude_all_others']))) == 1)
{
$exclusive_option = trim($qattr['exclude_all_others']);
if ($hasSubqs) {
$subqs = $qinfo['subqs'];
$sq_names = array();
foreach ($subqs as $sq) {
$sq_name = NULL;
switch ($type)
{
case 'M': //Multiple choice checkbox
if ($this->sgqaNaming)
{
$sq_name = substr($sq['jsVarName'],4);
}
else
{
$sq_name = $sq['varName'];
}
break;
default:
break;
}
if (!is_null($sq_name))
{
if ($sq['csuffix'] == $exclusive_option)
{
$eoVarName = substr($sq['jsVarName'],4);
}
else
{
$sq_names[] = $sq_name;
}
}
}
if (count($sq_names) > 0) {
$relpart = "LEMsum(LEMval('" . implode(".relevanceStatus'), LEMval('", $sq_names) . ".relevanceStatus'))";
$checkedpart = "LEMcount(LEMval('" . implode("'), LEMval('", $sq_names) . "'))";
$eoRelevantAndUnchecked = "(LEMval('" . $eoVarName . ".relevanceStatus') && LEMval('" . $eoVarName . "')=='')";
$eosaJS = "if (" . $eoRelevantAndUnchecked . " && (" . $relpart . " == " . $checkedpart . ")) {\n";
// Unset all checkboxes and hidden values for this question (irregardless of whether they are array filtered)
$eosaJS .=" $('#question" . $questionNum . " [type=checkbox]').attr('checked',false);\n";
$eosaJS .=" $('#java" . $qinfo['sgqa'] . "other').val('');\n";
$eosaJS .=" $('#answer" . $qinfo['sgqa'] . "other').val('');\n";
$eosaJS .=" $('[id^=java" . $qinfo['sgqa'] . "]').val('');\n";
$eosaJS .=" $('#answer" . $eoVarName . "').attr('checked',true);\n";
$eosaJS .=" $('#java" . $eoVarName . "').val('Y');\n";
$eosaJS .=" LEMrel" . $questionNum . "();\n";
$eosaJS .=" relChange" . $questionNum ."=true;\n";
$eosaJS .="}\n";

$this->qid2exclusiveAutoJS[$questionNum] = $eosaJS;
}
}
}

// min_answers
// Validation:= count(sq1,...,sqN) >= value (which could be an expression).
Expand Down Expand Up @@ -3438,6 +3498,7 @@ static function StartProcessingPage($allOnOnePage=false,$initializeVars=false)
$LEM->allOnOnePage=$allOnOnePage;
$LEM->processedRelevance=false;
$LEM->surveyOptions['hyperlinkSyntaxHighlighting']=true; // this will be temporary - should be reset in running survey
$LEM->qid2exclusiveAutoJS=array();

// $LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));

Expand Down Expand Up @@ -5981,6 +6042,11 @@ static function GetRelevanceAndTailoringJavaScript()
if ($_val==1)
{
$jsParts[] = " LEMrel" . $_qid . "(sgqa);\n";
if (isset($LEM->qattr[$_qid]['exclude_all_others_auto']) && $LEM->qattr[$_qid]['exclude_all_others_auto'] == '1'
&& isset($LEM->qid2exclusiveAutoJS[$_qid]) && strlen($LEM->qid2exclusiveAutoJS[$_qid]) > 0)
{
$jsParts[] = $LEM->qid2exclusiveAutoJS[$_qid];
}
if (isset($LEM->qattr[$_qid]['exclude_all_others']))
{
foreach (explode(';',trim($LEM->qattr[$_qid]['exclude_all_others'])) as $eo)
Expand All @@ -6006,6 +6072,11 @@ static function GetRelevanceAndTailoringJavaScript()
if ($_val == 1)
{
$jsParts[] = " LEMrel" . $_qid . "(sgqa);\n";
if (isset($LEM->qattr[$_qid]['exclude_all_others_auto']) && $LEM->qattr[$_qid]['exclude_all_others_auto'] == '1'
&& isset($LEM->qid2exclusiveAutoJS[$_qid]) && strlen($LEM->qid2exclusiveAutoJS[$_qid]) > 0)
{
$jsParts[] = $LEM->qid2exclusiveAutoJS[$_qid];
}
if (isset($LEM->qattr[$_qid]['exclude_all_others']))
{
foreach (explode(';',trim($LEM->qattr[$_qid]['exclude_all_others'])) as $eo)
Expand Down
57 changes: 1 addition & 56 deletions application/helpers/qanda_helper.php
Expand Up @@ -2345,50 +2345,6 @@ function do_multiplechoice($ia)
$oth_checkconditionFunction = "checkconditions";
}

// Check if the max_answers attribute is set
// $maxansw = 0;
// $callmaxanswscriptcheckbox = '';
// $callmaxanswscriptother = '';
// $maxanswscript = '';

$exclude_all_others_auto = trim($aQuestionAttributes["exclude_all_others_auto"]);

if ($exclude_all_others_auto=='1'){
$autoArray['list'][]=$ia[1];
$autoArray[$ia[1]]['parent'] = $ia[1];
}

// if (((int)$aQuestionAttributes['max_answers']>0) && $exclude_all_others_auto=='0')
// {
// $maxansw=$aQuestionAttributes['max_answers'];
// $callmaxanswscriptcheckbox = "limitmaxansw_{$ia[0]}(this);";
// $callmaxanswscriptother = "onkeyup='limitmaxansw_{$ia[0]}(this)'";
// $maxanswscript = "\t<script type='text/javascript'>\n"
// . "\t<!--\n"
// . "function limitmaxansw_{$ia[0]}(me)\n"
// . "{\n"
// . "\tmax=$maxansw\n"
// . "\tcount=0;\n"
// . "\tif (max == 0) { return count; }\n";
// }
//
//
// // Check if the min_answers attribute is set
// $minansw=0;
// $minanswscript = "";
//
// if ((int)$aQuestionAttributes['min_answers']>0)
// {
// $minansw=trim($aQuestionAttributes["min_answers"]);
// $minanswscript = "<script type='text/javascript'>\n"
// . "\t<!--\n"
// . "oldonsubmit_{$ia[0]} = document.limesurvey.onsubmit;\n"
// . "function ensureminansw_{$ia[0]}()\n"
// . "{\n"
// . "\tcount=0;\n"
// ;
// }

$qquery = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and parent_qid=0";
$qresult = dbExecuteAssoc($qquery); //Checked
$qrow = $qresult->read(); $other = $qrow['other'];
Expand Down Expand Up @@ -2446,15 +2402,6 @@ function do_multiplechoice($ia)
{
$myfname = $ia[1].$ansrow['title'];
$extra_class="";
if ($exclude_all_others_auto==1){
if ($ansrow['title']==trim($aQuestionAttributes['exclude_all_others'])){
$autoArray[$ia[1]]['focus'] = $ia[1].trim($aQuestionAttributes['exclude_all_others']);
}
else{
$autoArray[$ia[1]]['children'][] = $myfname;
$extra_class=" excludeallothers";
}
}

$trbc='';
/* Check for array_filter */
Expand Down Expand Up @@ -2518,9 +2465,7 @@ function do_multiplechoice($ia)
++$colcounter;
}
}
if ($exclude_all_others_auto==1){
$answer .= "<script type='text/javascript'>autoArray = ".ls_json_encode($autoArray).";</script>";
}

if ($other == 'Y')
{
$myfname = $ia[1].'other';
Expand Down
32 changes: 0 additions & 32 deletions scripts/survey_runtime.js
Expand Up @@ -86,38 +86,6 @@ $(document).ready(function()
currentMap.panTo(markerLatLng);
});

if ((typeof(autoArray) != "undefined")){
if ((autoArray.list != 'undefined') && (autoArray.list.length > 0)){
var aListOfQuestions = autoArray.list;

$(aListOfQuestions).each(function(index,element){

var elementInfo = autoArray[element];
var strJSelector = "#answer" + (elementInfo.children.join(", #answer"));

var aJSelectors = strJSelector.split(", ");
var strCheckedSelector = (aJSelectors.join(":checked ,"))+":checked";

$(strJSelector).live('change',function(event){

if ($(strCheckedSelector).length == $(strJSelector).length){

$("#answer"+elementInfo.focus).trigger('click');

eval("excludeAllOthers"+elementInfo.parent + "('answer"+elementInfo.focus + "', 'yes')");

checkconditions($("#answer"+elementInfo.focus).val(),
$("#answer"+elementInfo.focus).attr("name"),
$("#answer"+elementInfo.focus).attr('type')
);

}
});

});
}
}

// #index
if ($("#index").size() && $("#index .row.current").size()){
var idx = $("#index");
Expand Down

0 comments on commit 114cef2

Please sign in to comment.