Skip to content

Commit

Permalink
Dev: list dropdown, Human readable views
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Apr 4, 2016
1 parent bfea401 commit 295eca8
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 103 deletions.
108 changes: 54 additions & 54 deletions application/helpers/qanda_helper.php
Expand Up @@ -1182,39 +1182,43 @@ function do_list_dropdown($ia)
$checkconditionFunction = "checkconditions";

// Question attribute variables
//$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
$iSurveyId = Yii::app()->getConfig('surveyID'); // survey id
$sSurveyLang = $_SESSION['survey_'.$iSurveyId]['s_lang']; // survey language
$othertext = (trim($aQuestionAttributes['other_replace_text'][$sSurveyLang])!='')?$aQuestionAttributes['other_replace_text'][$sSurveyLang]:gT('Other:'); // text for 'other'
$optCategorySeparator = (trim($aQuestionAttributes['category_separator'])!='')?$aQuestionAttributes['category_separator']:'';
if($optCategorySeparator=='')

if ($optCategorySeparator=='')
{
unset($optCategorySeparator);
}

//// Retrieving datas

// Getting question
$oQuestion = Question::model()->findByPk(array('qid'=>$ia[0], 'language'=>$sSurveyLang));
$other = $oQuestion->other;
$other = $oQuestion->other;

// Getting answers
$ansresult = $oQuestion->getOrderedAnswers($aQuestionAttributes['random_order'], $aQuestionAttributes['alphasort'] );

$dropdownSize = '';


if (isset($aQuestionAttributes['dropdown_size']) && $aQuestionAttributes['dropdown_size'] > 0)
{
$_height = sanitize_int($aQuestionAttributes['dropdown_size']) ;
$_height = sanitize_int($aQuestionAttributes['dropdown_size']) ;
$_maxHeight = count($ansresult);

if ((!empty($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])) && $ia[6] != 'Y' && $ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
{
++$_maxHeight; // for No Answer
}

if (isset($other) && $other=='Y')
{
++$_maxHeight; // for Other
}

if (!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])
{
++$_maxHeight; // for 'Please choose:'
Expand All @@ -1228,43 +1232,27 @@ function do_list_dropdown($ia)
}

$prefixStyle = 0;

if (isset($aQuestionAttributes['dropdown_prefix']))
{
$prefixStyle = sanitize_int($aQuestionAttributes['dropdown_prefix']) ;
}
$_rowNum=0;
$_prefix='';

$selectData = array(
'name'=>$ia[1],
'dropdownSize'=>$dropdownSize,
'checkconditionFunction'=>$checkconditionFunction,
'value'=>'',
);
$_rowNum = 0;
$_prefix = '';

if (isset($other) && $other=='Y')
{
$sselect_show_hide = ' showhideother(this.name, this.value);';
$selectData = array(
'name'=>$ia[1],
'dropdownSize'=>$dropdownSize,
'checkconditionFunction'=> $checkconditionFunction.'(this.value, this.name, this.type);'.$sselect_show_hide,
'value'=>$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]],
);

}


$answer = Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/select', $selectData, true);
$value = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]];
$select_show_hide = (isset($other) && $other=='Y')?' showhideother(this.name, this.value);':'';
$sOptions = '';

// If no answer previously selected
if (!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]])
{
$optionData = array(
$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', array(
'value'=>'',
'opt_select'=>'SELECTED',
'answer'=>gT('Please choose...')
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
), true);
}

if (!isset($optCategorySeparator))
Expand All @@ -1280,12 +1268,12 @@ function do_list_dropdown($ia)
{
$_prefix = ++$_rowNum . ') ';
}
$optionData = array(
// ==> rows
$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', array(
'value'=>$ansrow['code'],
'opt_select'=>$opt_select,
'answer'=>flattenText($_prefix.$ansrow['answer'])
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
), true);
}
}
else
Expand All @@ -1309,9 +1297,8 @@ function do_list_dropdown($ia)

foreach ($optgroups as $categoryname => $optionlistarray)
{
$optgroupData = array('categoryname'=>flattenText($categoryname));
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/optgroup_header', $optgroupData, true);

$sOptGroupOptions = '';
foreach ($optionlistarray as $optionarray)
{
if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $optionarray['code'])
Expand All @@ -1323,15 +1310,19 @@ function do_list_dropdown($ia)
$opt_select = '';
}

$optionData = array(
// ==> rows
$sOptGroupOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', array(
'value'=>$optionarray['code'],
'opt_select'=>$opt_select,
'answer'=>flattenText($optionarray['answer'])
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
), true);
}

$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/optgroup_footer', $optgroupData, true);

$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/optgroup', array(
'categoryname' => flattenText($categoryname),
'sOptGroupOptions' => $sOptGroupOptions,
), true);
}
$opt_select='';
foreach ($defaultopts as $optionarray)
Expand All @@ -1345,13 +1336,12 @@ function do_list_dropdown($ia)
$opt_select = '';
}


$optionData = array(
// ==> rows
$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', array(
'value'=>$optionarray['code'],
'opt_select'=>$opt_select,
'answer'=>flattenText($optionarray['answer'])
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
), true);
}
}

Expand All @@ -1369,17 +1359,17 @@ function do_list_dropdown($ia)
$_prefix = ++$_rowNum . ') ';
}

$optionData = array(
$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', array(
'value'=>'-oth-',
'opt_select'=>$opt_select,
'answer'=>flattenText($_prefix.$othertext)
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
), true);
}

if (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] != '') && $ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
{
if ($prefixStyle == 1) {
if ($prefixStyle == 1)
{
$_prefix = ++$_rowNum . ') ';
}

Expand All @@ -1389,13 +1379,11 @@ function do_list_dropdown($ia)
'opt_select'=>$opt_select,
'answer'=>$_prefix.gT('No answer')
);
$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/option', $optionData, true);
// ==> rows
$sOptions .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/option', $optionData, true);
}



$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/select_footer', $selectData, true);

$sOther = '';
if (isset($other) && $other=='Y')
{
$aData = array();
Expand All @@ -1405,13 +1393,25 @@ function do_list_dropdown($ia)
$thisfieldname="$ia[1]other";
$aData['value'] = (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname]))?htmlspecialchars($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname],ENT_QUOTES):'';

$answer .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/othertext', $aData, true);
// ==> other
$sOther .= Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/rows/othertext', $aData, true);

$inputnames[]=$ia[1].'other';

// TODO: check if needed : $answer .= "</p>";
}

// ==> answer
$answer = Yii::app()->getController()->renderPartial('/survey/questions/list_dropdown/answer', array(
'sOptions' => $sOptions,
'sOther' => $sOther,
'name' => $ia[1],
'dropdownSize' => $dropdownSize,
'checkconditionFunction' => $checkconditionFunction,
'value' => $value,
'select_show_hide' => $select_show_hide,
), true);


$inputnames[]=$ia[1];

//Time Limit Code
Expand Down
51 changes: 51 additions & 0 deletions application/views/survey/questions/list_dropdown/answer.php
@@ -0,0 +1,51 @@
<?php
/**
* List DropDown select Html
*
* @var $sOptions : the select options, generated with the view item_options.php
* @var $sOther : the other input field, generated with the view item_noanswer.php
*
* @var $name
* @var $dropdownSize
* @var $checkconditionFunction
* @var $select_show_hide
*
*/
?>

<!-- List Dropdown -->

<!-- answer-->

<p class="question answer-item dropdown-item">
<label for="answer<?php echo $name; ?>" class="hide label">
<?php eT('Please choose'); ?>
</label>

<select
class="form-control list-question-select"
name="<?php echo $name; ?>"
id="answer<?php echo $name; ?>"
<?php echo $dropdownSize; ?>
onchange="<?php echo $checkconditionFunction; ?>(this.value, this.name, this.type);<?php echo $select_show_hide; ?>"
>
<?php
// rows/item_options.php
echo $sOptions;
?>

</select>

<input
type="hidden"
name="java<?php echo $name; ?>"
id="java<?php echo $name; ?>"
value="<?php echo $value; ?>"
/>

<?php
// rows/item_options.php
echo $sOther;
?>
</p>
<!-- end of answer -->

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 17 additions & 0 deletions application/views/survey/questions/list_dropdown/rows/optgroup.php
@@ -0,0 +1,17 @@
<?php
/**
* List DropDown Option group header Html
* @var $sOptGroupOptions the current options for this group, generated with the view rows/options.php
*
* @var $categoryname
*/
?>

<!-- optgroup -->
<optgroup class="dropdowncategory" label="<?php echo $categoryname;?>">
<?php
// rows/option.php
echo $sOptGroupOptions;
?>
</optgroup>
<!-- end of optgroup -->
Expand Up @@ -8,6 +8,8 @@
*/
?>

<!-- option -->
<option value='<?php echo $value?>' <?php echo $opt_select;?> <?php if(isset($classes)):?> class="<?php echo $classes;?>" <?php endif;?> >
<?php echo $answer;?>
</option>
<!-- end of option -->
Expand Up @@ -8,6 +8,8 @@
* @var $checkconditionFunction
*/
?>

<!-- othertext -->
<script type="text/javascript">
<!--
function showhideother(name, value)
Expand Down Expand Up @@ -37,3 +39,4 @@ class="form-control"
alt='<?php eT('Other answer'); ?>'
onchange='<?php echo $checkconditionFunction;?>(this.value, this.name, this.type);'
/>
<!-- end of othertext -->
20 changes: 0 additions & 20 deletions application/views/survey/questions/list_dropdown/select.php

This file was deleted.

15 changes: 0 additions & 15 deletions application/views/survey/questions/list_dropdown/select_footer.php

This file was deleted.

0 comments on commit 295eca8

Please sign in to comment.