Skip to content

Commit

Permalink
Dev: Default survey language must be selectable, not fixed (#818)
Browse files Browse the repository at this point in the history
Dev: fix survey mainlanguage: clean code
Dev: fix survey mainlanguage: add laguage selection if new record
Dev: fix survey mainlanguage: refactor survey defaults
Dev: fix survey mainlanguage: additional languages only after initial saving!
  • Loading branch information
TonisOrmisson authored and LouisGac committed Oct 9, 2017
1 parent d139237 commit 2d0aa11
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
23 changes: 8 additions & 15 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -126,8 +126,7 @@ public function regenquestioncodes($iSurveyID, $sSubAction )
*/
public function newsurvey()
{
if (!Permission::model()->hasGlobalPermission('surveys','create'))
{
if (!Permission::model()->hasGlobalPermission('surveys','create')) {
Yii::app()->user->setFlash('error', gT("Access denied"));
$this->getController()->redirect(Yii::app()->request->urlReferrer);
}
Expand All @@ -136,13 +135,6 @@ public function newsurvey()
$this->_registerScriptFiles();
Yii::app()->loadHelper('surveytranslator');
$esrow = $this->_fetchSurveyInfo('newsurvey');
// Default setting is to use the global Google Analytics key If one exists
$globalKey = getGlobalSetting('googleanalyticsapikey');
if($globalKey != ""){
$survey->googleanalyticsapikey = "9999useGlobal9999";
$survey->googleanalyticsapikeysetting = "G";
}

Yii::app()->loadHelper('admin/htmleditor');

$aViewUrls['output'] = PrepareEditorScript(false, $this->getController());
Expand Down Expand Up @@ -173,6 +165,7 @@ public function newsurvey()
$this->_renderWrappedTemplate('survey', $aViewUrls, $arrayed_data);
}

// TODO document me, please :)
public function fakebrowser()
{
Yii::app()->getController()->renderPartial('/admin/survey/newSurveyBrowserMessage', array());
Expand Down Expand Up @@ -1930,14 +1923,14 @@ private function _registerScriptFiles()
}

/**
* Saves the new survey after the creation screen is submitted
*
* @param $iSurveyID The survey id to be used for the new survey. If already taken a new random one will be used.
*/
* Saves the new survey after the creation screen is submitted
*
* @param integer $iSurveyID The survey id to be used for the new survey. If already taken a new random one will be used.
* @return string
*/
function insert($iSurveyID=null)
{
if (Permission::model()->hasGlobalPermission('surveys','create'))
{
if (Permission::model()->hasGlobalPermission('surveys','create')) {
// Check if survey title was set
if (Yii::app()->request->getPost('surveyls_title')=='')
{
Expand Down
7 changes: 7 additions & 0 deletions application/models/Survey.php
Expand Up @@ -171,6 +171,13 @@ public function init()
$this->htmlemail = 'Y';
$this->format = 'G';

// Default setting is to use the global Google Analytics key If one exists
$globalKey = getGlobalSetting('googleanalyticsapikey');
if($globalKey != ""){
$this->googleanalyticsapikey = "9999useGlobal9999";
$this->googleanalyticsapikeysetting = "G";
}


$this->template = Template::templateNameFilter(Yii::app()->getConfig('defaulttemplate'));
$validator= new LSYii_Validators;
Expand Down
Expand Up @@ -68,41 +68,47 @@ function checkSelect2Languages(mylangs)
<div class="col-md-6 col-sm-12">
<!-- Base language -->
<div class="form-group">

<label class=" control-label" ><?php eT("Base language:") ; ?></label>
<div class="" style="padding-top: 7px;">
<?php if($oSurvey->isNewRecord):?>
<?php $this->widget('yiiwheels.widgets.select2.WhSelect2', array(
'asDropDownList' => true,
'htmlOptions'=>array('style'=>"width: 80%"),
'data' => getLanguageDataRestricted (false,'short'),
'value' => $oSurvey->language,
'name' => 'language',
'pluginOptions' => array()
));?>
<?php else:?>
<?php echo getLanguageNameFromCode($oSurvey->language,false); ?>
<?php endif;?>
</div>
</div>

<?php if(!$oSurvey->isNewRecord):?>
<!-- Additional Languages -->
<div class="form-group">
<label class=" control-label" for='additional_languages'><?php eT("Additional Languages"); ?>:</label>
<div class="">
<?php
$aAllLanguages=getLanguageDataRestricted (false,'short');
$aAdditionalLanguages = (isset($surveyid) && $surveyid!=0) ? Survey::model()->findByPk($surveyid)->additionalLanguages : [];
foreach( $aAdditionalLanguages as $sSurveyLang)
{
if(!array_key_exists($sSurveyLang,$aAllLanguages))
{
$aAllLanguages[$sSurveyLang]=getLanguageNameFromCode($sSurveyLang,false);
}
}
unset($aAllLanguages[$oSurvey->language]);

Yii::app()->getController()->widget('yiiwheels.widgets.select2.WhSelect2', array(
'asDropDownList' => true,
'htmlOptions'=>array('multiple'=>'multiple','style'=>"width: 100%"),
'data' => $aAllLanguages,
'value' => $aAdditionalLanguages,
'value' => $oSurvey->additionalLanguages,
'name' => 'additional_languages',
'pluginOptions' => array(
'placeholder' => gt('Select additional languages','unescaped'),
)));
?>
<input type='hidden' name='oldlanguages' id='oldlanguages' value='<?php echo implode(' ', $aAdditionalLanguages); ?>'>
<input type='hidden' name='oldlanguages' id='oldlanguages' value='<?php echo implode(' ', $oSurvey->additionalLanguages); ?>'>
</div>
</div>
<?php endif;?>

<!-- Survey owner -->
<?php
Expand Down

0 comments on commit 2d0aa11

Please sign in to comment.