Skip to content

Commit

Permalink
Merge pull request #211 from KRav007/feature_defaultvalue_yesno
Browse files Browse the repository at this point in the history
New feature: Default value for yes/no question type
  • Loading branch information
c-schmitz committed Aug 28, 2014
2 parents c5aa059 + 09eaf5e commit f51d66a
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,3 +18,4 @@
/third_party/jqgrid/src
.settings/org.eclipse.php.core.prefs
.buildpath
/application/config/*

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 29, 2014

Collaborator

See : 09eaf5e :)
I think we can replace by /application/config/config.php ?

27 changes: 23 additions & 4 deletions application/controllers/admin/database.php
Expand Up @@ -95,11 +95,30 @@ function index($sa = null)
{
foreach ($aSurveyLanguages as $sLanguage)
{
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage.'_0')))
{
$this->_updateDefaultValues($iQuestionID,0,0,'',$sLanguage,Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage.'_0'),true);
// Qick and dirty insert for yes/no defaul value
// write the the selectbox option, or if "EM" is slected, this value to table
if ($sQuestionType == 'Y'){
/// value for all langs
if (Yii::app()->request->getPost('samedefault') == 1){
$sLanguage = $aSurveyLanguages[0]; // turn
}else{
$sCurrentLang = $sLanguage; // edit the next lines
}
if ( Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage) == 'EM') { // Case EM, write expression to database
$this->_updateDefaultValues($iQuestionID,0,0,'',$sLanguage,Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage.'_EM'),true);
}
else{
// Case "other", write list value to database
$this->_updateDefaultValues($iQuestionID,0,0,'',$sLanguage,Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage),true);
}
///// end yes/no
}else{
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage.'_0')))
{
$this->_updateDefaultValues($iQuestionID,0,0,'',$sLanguage,Yii::app()->request->getPost('defaultanswerscale_0_'.$sLanguage.'_0'),true);
}
}
}
}
}
Yii::app()->session['flashmessage'] = $clang->gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
Expand Down
2 changes: 1 addition & 1 deletion application/models/Question.php
Expand Up @@ -590,7 +590,7 @@ public static function typeList()
'description' => gT("Yes/No"),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0),
"!" => array(
Expand Down
16 changes: 16 additions & 0 deletions application/views/admin/survey/Question/editdefaultvalues_view.php
Expand Up @@ -146,6 +146,21 @@
case 'U':*
*/
?>
<?php
/**
* Call default value widget for yes/no question type
* This is fast insert rewrite of this view follows
*/
$widgetOptions = array(
'language' =>$language ,
'questionrow' => $questionrow,
'qtproperties' => $qtproperties,
'langopts' => $langopts,
'clang' => $clang
);
$this->widget('application.views.admin.survey.Question.yesNo_defaultvalue_widget', array('widgetOptions'=>$widgetOptions));
?>
<?php if ($questionrow['type'] != 'Y'): //temporary solution - until everything is move to widgets?>
<li>
<label for='defaultanswerscale_<?php echo "0_{$language}_0" ?>'>
<?php $clang->eT("Default value:")?>
Expand All @@ -155,6 +170,7 @@
id='defaultanswerscale_<?php echo "0_{$language}_0" ?>'><?php
echo htmlspecialchars($langopts[$language][$questionrow['type']][0]); ?></textarea>
</li>
<?php endif; //temporary solution?>
<?php
}

Expand Down
@@ -0,0 +1,94 @@
<?php

/**
* @file
*
* This file holds the widget for the yes-no question type, to edit it's default values.
*
* Features:
* - YES/NO preselection
* - EM integration to insert an em expression like {TOKEN:ATTRIBUTE_6}. At this state there is no validation implemented. Attributes must hold Y or N.
*
* DEV MEMO:
* Validation could be difficult cause if you using tokens and you don't had setup a working token dataset
*
* For this feature you need editDefaultvalues.php, database.php, adminstyle.css
*/

class yesNo_defaultvalue_widget extends CWidget
{
public $widgetOptions;

//init() method is called automatically before all others
public function init()
{
/*you can set initial default values and other stuff here.
* it's also a good place to register any CSS or Javascript your
* widget may need. */

}

public function run()
{

$qtproperties = $this->widgetOptions['qtproperties'];
$questionrow = $this->widgetOptions['questionrow'];
$langopts = $this->widgetOptions['langopts'];
$language = $this->widgetOptions['language'];
$defaultValues = $this->widgetOptions['langopts'][$language][$questionrow['type']][0];
$clang = $this->widgetOptions['clang'];

$emfield_css = '';
$emValue = '';
$select = '';
$sEmfield_css_class = '';

// prepare variables for prefilling the form
if(!is_null ($defaultValues))
{
$sDefaultValue = $defaultValues;
if(($sDefaultValue == 'N') || ($sDefaultValue == 'Y') || ($sDefaultValue == '') ){ //|| 'Y' || NULL)){
$select = $defaultValues;
}else{
$select = 'EM';
$emValue = $defaultValues;
}
}

if($questionrow['type'] == 'Y') // do we need this?
{
$sElement_id = 'defaultanswerscale_0_' . $language;

$aList = array(
'N' => $clang->gT('No'),
'Y' => $clang->gT('YES'),
'EM' => $clang->gT('EM Value')
);

$aHtmlOptions = array(
'empty' => $clang->gT('<No default value>'),
'class' => $sElement_id,
'onchange' => '// show EM Value Field
if ($(this).val() == "EM"){
$("#"+$(this).closest("select").attr("id")+ "_EM").removeClass("hide");
}else{
$("#"+$(this).closest("select").attr("id")+ "_EM").addClass("hide");} '
);

echo '<li>';
echo CHtml::dropDownList($sElement_id, $select, $aList, $aHtmlOptions);

// textfield preparation
if(empty($defaultValues) || $defaultValues == 'Y')
{
$sEmfield_css_class = 'hide';
}
echo CHtml::textField ($sElement_id . '_EM', $emValue,array(
'id' => $sElement_id . '_EM',
'class' => $sEmfield_css_class,
'width' => 100
));
echo '</li>';
}
}
}
5 changes: 5 additions & 0 deletions styles/adminstyle.css
Expand Up @@ -217,3 +217,8 @@ legend { line-height: normal; }
.exporttip li { overflow: visible;}
li input+label { display: inline;}
#resultexport ol, #resultexport ul { margin: 0 0 10px 10px;}


.hide {
display: none !important;
}

4 comments on commit f51d66a

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question about default_value with EM : it can work only with a GUI ?
I you put for a list : {if(QCODE=="Y","A1","A2)} in default value for a list via phpMyAdmin, it work ?

If yes : this can be in 2.06 or 2.05 ?

@maziminke
Copy link
Collaborator

@maziminke maziminke commented on f51d66a Aug 29, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c-schmitz
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the patch. It is supposed to do this - at least for the Yes/No question. Since the functionality did not exist before and has no effect on existing code it was merged to 2.05

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but looking at code, i think same think can be applied without updating qanda and/or EM. Then think we can do it for all actual question tye with default value :) .

Please sign in to comment.