Skip to content

Commit

Permalink
Dev: Factor out view in qanda for array-by-column
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Apr 14, 2016
1 parent 4fb9442 commit b2cb656
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 42 deletions.
121 changes: 84 additions & 37 deletions application/helpers/qanda_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5589,12 +5589,14 @@ function do_arraycolumns($ia)
$labelans=array();
$labelcode=array();
$labels=array();

foreach ($aAnswers as $lrow)
{
$labelans[]=$lrow['answer'];
$labelcode[]=$lrow['code'];
$labels[]=array("answer"=>$lrow['answer'], "code"=>$lrow['code']);
}

if (count($labelans) > 0)
{
if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
Expand All @@ -5613,34 +5615,48 @@ function do_arraycolumns($ia)
$ansresult = dbExecuteAssoc($ansquery); //Checked
$aQuestions = $ansresult->readAll();
$anscount = count($aQuestions);

$aData = array();
$aData['labelans'] = $labelans;
$aData['labelcode'] = $labelcode;

if ($anscount>0)
{
$fn=1;
$cellwidth=$anscount;
$cellwidth=round(( 50 / $cellwidth ) , 1);
//$answer = "\n<table class=\"table-in-qanda-8 question subquestions-list questions-list\" summary=\"{$caption}\">\n"
$answer = "\n<table class=\"array-by-columns-table table-array-by-column table question subquestion-list questions-list\">\n"
. "\t<colgroup class=\"col-responses\">\n"
//. "\t<col class=\"col-answers\" width=\"50%\" />\n";
. "\t<col class=\"col-answers\" style='width: 50%' />\n";
$answer = '';
//$answer = "\n<table class=\"array-by-columns-table table-array-by-column table question subquestion-list questions-list\">\n"
//. "\t<colgroup class=\"col-responses\">\n"
//. "\t<col class=\"col-answers\" style='width: 50%' />\n";
$odd_even = '';

$aData['anscount'] = $anscount;
$aData['cellwidth'] = $cellwidth;

for( $c = 0 ; $c < $anscount ; ++$c )
{
$odd_even = alternation($odd_even);
$odd_even_well = ($odd_even == 'odd')?$odd_even.' well':$odd_even;
//$odd_even = alternation($odd_even);
//$odd_even_well = ($odd_even == 'odd')?$odd_even.' well':$odd_even;
//$answer .= "<col class=\"$odd_even question-item answers-list radio-list\" width=\"$cellwidth%\" />\n";
$answer .= "<col class=\"$odd_even_well question-item answers-list radio-list\" style='width: $cellwidth%;' />\n";
//$answer .= "<col class=\"$odd_even_well question-item answers-list radio-list\" style='width: $cellwidth%;' />\n";
}
$answer .= "\t</colgroup>\n\n"
. "\t<thead class='thead-array-by-column'>\n"
. "<tr>\n"
. "\t<td>&nbsp;</td>\n";
//$answer .= "\t</colgroup>\n\n"
//. "\t<thead class='thead-array-by-column'>\n"
//. "<tr>\n"
//. "\t<td>&nbsp;</td>\n";

$aData['aQuestions'] = $aQuestions;

foreach ($aQuestions as $ansrow)
{
$anscode[]=$ansrow['title'];
$answers[]=$ansrow['question'];
}

$aData['anscode'] = $anscode;
$aData['answers'] = $answers;

$trbc = '';
$odd_even = '';
for ($_i=0;$_i<count($answers);++$_i)
Expand All @@ -5651,72 +5667,103 @@ function do_arraycolumns($ia)
/* Check the Sub Q mandatory violation */
if ($ia[6]=='Y' && in_array($myfname, $aMandatoryViolationSubQ))
{
$aData['aQuestions'][$_i]['errormandatory'] = true;
//$ld = "<span class=\"errormandatory\">{$ld}</span>";
$ld ='
<div class="alert alert-danger " role="alert">'.
$ld
.'
</div>';
//$ld ='
//<div class="alert alert-danger " role="alert">'.
//$ld
//.'
//</div>';

}
$odd_even = alternation($odd_even);
$answer .= "\t<th class=\"$odd_even\">$ld</th>\n";
else
{
$aData['aQuestions'][$_i]['errormandatory'] = false;
}
//$odd_even = alternation($odd_even);
//$answer .= "\t<th class=\"$odd_even\">$ld</th>\n";
}
unset($trbc);
$answer .= "</tr>\n\t</thead>\n\n\t<tbody>\n";
//$answer .= "</tr>\n\t</thead>\n\n\t<tbody>\n";
$ansrowcount=0;
$ansrowtotallength=0;
foreach($aQuestions as $ansrow)
{
$ansrowcount++;
$ansrowtotallength=$ansrowtotallength+strlen($ansrow['question']);
}
$percwidth=100 - ($cellwidth*$anscount);

$aData['ansrowtotallength'] = $ansrowtotallength;

$percwidth = 100 - ($cellwidth*$anscount);

$aData['labels'] = $labels;
$aData['checkconditionFunction'] = $checkconditionFunction;

foreach($labels as $ansrow)
{
$answer .= "<tr>\n"
. "\t<th class=\"arraycaptionleft dontread\">{$ansrow['answer']}</th>\n";
//$answer .= "<tr>\n"
//. "\t<th class=\"arraycaptionleft dontread\">{$ansrow['answer']}</th>\n";
$i = 0;
foreach ($anscode as $ld)
foreach ($anscode as $j => $ld)
{
//if (!isset($trbc) || $trbc == 'array1') {$trbc = 'array2';} else {$trbc = 'array1';}
$myfname=$ia[1].$ld;
$answer .= "\t<td data-title='" . $ansrow['answer'] . "' class=\"answer-cell-7 answer_cell_$ld answer-item radio-item\">\n"
. "\t<label for=\"answer".$myfname.'-'.$ansrow['code']."\"><input class=\"radio\" type=\"radio\" name=\"".$myfname.'" value="'.$ansrow['code'].'" '
. 'id="answer'.$myfname.'-'.$ansrow['code'].'" ';
$aData['aQuestions'][$j]['myfname'] = $myfname;
//$answer .= "\t<td data-title='" . $ansrow['answer'] . "' class=\"answer-cell-7 answer_cell_$ld answer-item radio-item\">\n"
//. "\t<label for=\"answer".$myfname.'-'.$ansrow['code']."\">
// <input class=\"radio\" type=\"radio\" name=\"".$myfname.'" value="'.$ansrow['code'].'" '
//. 'id="answer'.$myfname.'-'.$ansrow['code'].'" ';
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]) && $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] == $ansrow['code'])
{
$answer .= CHECKED;
$aData['aQuestions'][$j]['checked'] = CHECKED;
}
elseif (!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]) && $ansrow['code'] == '')
{
$answer .= CHECKED;
$aData['aQuestions'][$j]['checked'] = CHECKED;
// Humm.. (by lemeur), not sure this section can be reached
// because I think $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname] is always set (by save.php ??) !
// should remove the !isset part I think !!
}
$answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n"
//. "<label class=\"hide read\" for=\"answer".$myfname.'-'.$ansrow['code']."\">{$ansrow['answer']}</label>\n"
. "\t</label></td>\n";
else
{
$aData['aQuestions'][$j]['checked'] = "";
}
//$answer .= " onclick=\"$checkconditionFunction(this.value, this.name, this.type)\" />\n"
//. "\t</label></td>\n";
$i += 1;
}
unset($trbc);
$answer .= "</tr>\n";
//$answer .= "</tr>\n";
$fn++;
}

$answer .= "\t</tbody>\n</table>\n";
foreach($anscode as $ld)
//$answer .= "\t</tbody>\n</table>\n";
foreach($anscode as $j => $ld)
{
$myfname=$ia[1].$ld;
$answer .= '<input type="hidden" name="java'.$myfname.'" id="java'.$myfname.'" value="';
//$answer .= '<input type="hidden" name="java'.$myfname.'" id="java'.$myfname.'" value="';
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]))
{
$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];
//$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];
$aData['aQuestions'][$j]['myfname_value'] = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];
}
$answer .= "\" />\n";
else
{
$aData['aQuestions'][$j]['myfname_value'] = '';
}

//$answer .= "\" />\n";
$inputnames[]=$myfname;
}

// Render question
$answer = Yii::app()->getController()->renderPartial(
'/survey/questions/arrays/column/answer',
$aData,
true
);
}
else
{
Expand Down
75 changes: 75 additions & 0 deletions application/views/survey/questions/arrays/column/answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Array by column
*
* @var $anscount
* @var $cellwidth
*/
?>

<table class="array-by-columns-table table-array-by-column table question subquestion-list questions-list">
<colgroup class="col-responses">
<col class="col-answers" style='width: 50%' />

<?php for ($i = 0; $i < $anscount; $i++): ?>
<col class="question-item answers-list radio-list <?php echo ($i % 2 == 0 ? "odd well" : "even"); ?>" style='width: <?php echo $cellwidth; ?>%;' />
<?php endfor; ?>

</colgroup>
<thead class='thead-array-by-column'>
<tr>
<td>&nbsp;</td>

<?php foreach ($aQuestions as $question): ?>
<?php if ($question['errormandatory']): ?>
<th>
<div class="alert alert-danger " role="alert">
<?php echo $question['question']; ?>
</div>
</th>
<?php else: ?>
<th class="text-center">
<?php echo $question['question']; ?>
</th>
<?php endif; ?>
<?php endforeach; ?>

</tr>
</thead>
<tbody>
<?php foreach ($labels as $ansrow): ?>
<tr>
<th class="arraycaptionleft dontread">
<?php echo $ansrow['answer']; ?>
</th>
<?php foreach ($anscode as $i => $ld): ?>
<td data-title='<?php echo $ansrow['answer']; ?>' class="answer-cell-7 answer_cell_<?php echo $ld; ?> answer-item radio-item text-center radio">
<input
class="radio"
type="radio"
name="<?php echo $aQuestions[$i]['myfname']; ?>"
value="<?php echo $ansrow['code']; ?>"
id="answer<?php echo $aQuestions[$i]['myfname']; ?>-<?php echo $ansrow['code']; ?>"
<?php echo $aQuestions[$i]['checked']; ?>
onclick="<?php echo $checkconditionFunction; ?>(this.value, this.name, this.type)"
/>
<label for="answer<?php echo $aQuestions[$i]['myfname']; ?>-<?php echo $ansrow['code']; ?>">
<span class="hide label-text"><?php echo $ld;?></span>
</label>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>

</table>

<?php foreach ($anscode as $i => $ld): ?>
<input
type="hidden"
name="java<?php echo $aQuestions[$i]['myfname']; ?>"
id="java<?php echo $aQuestions[$i]['myfname']; ?>"
value="<?php echo $aQuestions[$i]['myfname_value']; ?>"
/>
<?php endforeach; ?>
8 changes: 3 additions & 5 deletions templates/default/css/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,16 @@ body .navbar-default .navbar-brand:hover {
font-weight: normal;
}

.table-multi-num label {
/* Center radio buttons in array-by-column */
.table-array-by-column td.radio-item.text-center.answer-item {
padding-left: 47px;
}

/**
* On big screen only, iPad and up
*/
@media only screen and (min-width: 768px) {



.table-dual-scale .separator {
width: 6%;
}
Expand Down Expand Up @@ -705,8 +705,6 @@ body .navbar-default .navbar-brand:hover {
}
}

/******** OBS: Media specific CSS must be last in this file. ********/


/**
* Display adjust, question type by question type
Expand Down

0 comments on commit b2cb656

Please sign in to comment.