Skip to content

Commit

Permalink
Dev #T635: Land in the Suvey Builder (Structure) when creating a surv…
Browse files Browse the repository at this point in the history
…ey (#1878)

- Added 'createsample' global setting
- Added 'createsample' personal setting
Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik committed Jun 14, 2021
1 parent 4c124bc commit 583e768
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 14 deletions.
1 change: 1 addition & 0 deletions application/config/config-defaults.php
Expand Up @@ -82,6 +82,7 @@
$config['userideditable'] = 'N'; // Allow editing of user IDs

$config['defaulttheme'] = 'fruity'; // This setting specifys the default theme used for the 'public list' of surveys
$config['createsample'] = true;
$config['customassetversionnumber'] = 1; // Used to generate the path of tmp assets (see: LSYii_AssetManager::generatePath() )

// Please be very careful if you want to allow SVG files - there are several XSS dangerous security issues
Expand Down
37 changes: 29 additions & 8 deletions application/controllers/SurveyAdministrationController.php
Expand Up @@ -499,22 +499,23 @@ public function actionInsert($iSurveyID = null)
// This will force the generation of the entry for survey group
TemplateConfiguration::checkAndcreateSurveyConfig($iNewSurveyid);

$createSample = App()->request->getPost('createsample');
$createSampleChecked = ($createSample === 'on');
$createSample = SettingsUser::getUserSettingValue('createsample');
if ($createSample === null || $createSample === 'default') {
$createSample = Yii::app()->getConfig('createsample');
}

// Figure out destination
if ($createSampleChecked) {
if ($createSample) {
$iNewGroupID = $this->createSampleGroup($iNewSurveyid);
$iNewQuestionID = $this->createSampleQuestion($iNewSurveyid, $iNewGroupID);

Yii::app()->setFlashMessage(gT("Your new survey was created.
We also created a first question group and an example question for you."), 'info');
$landOnSideMenuTab = 'structure';
$redirecturl = $this->getSurveyAndSidemenueDirectionURL(
$iNewSurveyid,
$iNewGroupID,
$iNewQuestionID,
$landOnSideMenuTab
'structure'
);
} elseif (!$ownsPreviousSurveys) {
// SET create question and create question group as default view.
Expand All @@ -529,6 +530,7 @@ public function actionInsert($iSurveyID = null)
);
Yii::app()->setFlashMessage(gT("Your new survey was created."), 'info');
}

return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array(
Expand Down Expand Up @@ -2203,6 +2205,7 @@ public function actionCopy()
$aData['aImportResults'] = $aImportResults;
$aData['action'] = $action;
if (isset($aImportResults['newsid'])) {
// Set link pointing to survey administration overview. This link will be updated if the survey has groups
$aData['sLink'] = $this->createUrl('surveyAdministration/view/', ['iSurveyID' => $aImportResults['newsid']]);
$aData['sLinkApplyThemeOptions'] = 'surveyAdministration/applythemeoptions/surveyid/' . $aImportResults['newsid'];
}
Expand All @@ -2224,6 +2227,22 @@ public function actionCopy()
LimeExpressionManager::FinishProcessingGroup();
}
LimeExpressionManager::FinishProcessingPage();

// Make the link point to the first group/question if available
if (!empty($aGrouplist)) {
$oFirstGroup = $aGrouplist[0];
$oFirstQuestion = Question::model()->findByAttributes(
['gid' => $oFirstGroup->gid],
['order' => 'question_order ASC']
);

$aData['sLink'] = $this->getSurveyAndSidemenueDirectionURL(
$aImportResults['newsid'],
$oFirstGroup->gid,
!empty($oFirstQuestion) ? $oFirstQuestion->qid : null,
'structure'
);
}
}

$this->aData = $aData;
Expand Down Expand Up @@ -2626,13 +2645,15 @@ public function changeTemplate($iSurveyID, $template, $aResults = null, $bReturn
*/
public function getSurveyAndSidemenueDirectionURL($sid, $gid, $qid, $landOnSideMenuTab)
{
$url = 'questionAdministration/view/';
$url = !empty($qid) ? 'questionAdministration/view/' : 'questionGroupsAdministration/view/';
$params = [
'surveyid' => $sid,
'gid' => $gid,
'qid' => $qid,
'landOnSideMenuTab' => $landOnSideMenuTab
];
if (!empty($qid)) {
$params['qid'] = $qid;
}
$params['landOnSideMenuTab'] = $landOnSideMenuTab;
return $this->createUrl($url, $params);
}

Expand Down
2 changes: 2 additions & 0 deletions application/controllers/admin/globalsettings.php
Expand Up @@ -270,6 +270,8 @@ private function _saveSettings()
SettingGlobal::setSetting('allow_unstable_extension_update', sanitize_paranoid_string(Yii::app()->getRequest()->getPost('allow_unstable_extension_update', false)));
}

SettingGlobal::setSetting('createsample', (bool) Yii::app()->getRequest()->getPost('createsample'));

if (!Yii::app()->getConfig('demoMode')) {
$sTemplate = Yii::app()->getRequest()->getPost("defaulttheme");
if (array_key_exists($sTemplate, Template::getTemplateList())) {
Expand Down
1 change: 1 addition & 0 deletions application/controllers/admin/useraction.php
Expand Up @@ -683,6 +683,7 @@ public function personalsettings()
SettingsUser::setUserSetting('answeroptionprefix', Yii::app()->request->getPost('answeroptionprefix'));
SettingsUser::setUserSetting('subquestionprefix', Yii::app()->request->getPost('subquestionprefix'));
SettingsUser::setUserSetting('lock_organizer', Yii::app()->request->getPost('lock_organizer'));
SettingsUser::setUserSetting('createsample', Yii::app()->request->getPost('createsample'));

Yii::app()->setFlashMessage(gT("Your personal settings were successfully saved."));
} else {
Expand Down
21 changes: 21 additions & 0 deletions application/views/admin/globalsettings/_general.php
Expand Up @@ -45,6 +45,27 @@
</div>
</div>
</div>
<!-- Autocreate group and question -->
<div class="row ls-space margin top-10">
<div class="form-group col-xs-12">
<label class="col-sm-12 text-left control-label" for="createsample">
<?php eT("Create example question group and question:");?>
</label>
<div class="col-sm-12">
<?php
$this->widget(
'yiiwheels.widgets.switch.WhSwitch', [
'name' => 'createsample',
'id' => 'createsample',
'value' => Yii::app()->getConfig('createsample'),
'onLabel' => gT('On'),
'offLabel' => gT('Off')
]
);
?>
</div>
</div>
</div>
<!-- Administrative Template -->
<div class="row ls-space margin top-10">
<div class="form-group col-xs-12">
Expand Down
18 changes: 18 additions & 0 deletions application/views/admin/user/personalsettings.php
Expand Up @@ -360,6 +360,24 @@
?>
</div>
</div>
<!-- Create example question group and question -->
<div class="col-sm-12 col-md-6">
<div class="form-group">
<?php echo TbHtml::label( gT("Create example question group and question:"), 'createsample', array('class'=>" control-label")); ?>
<?php
echo TbHtml::dropDownList(
'createsample',
($aUserSettings['createsample'] ?? 'default'),
array(
'default' => gT("Default",'unescaped'),
'0' => gT("No",'unescaped'),
'1' => gT("Yes",'unescaped'),
),
array('class' => "form-control")
);
?>
</div>
</div>
</div>
</div>
</div>
Expand Down
6 changes: 0 additions & 6 deletions application/views/surveyAdministration/tabCreate_view.php
Expand Up @@ -63,12 +63,6 @@
<label for="surveyTitle"><?= gT('Survey title')?></label>
<input type="text" class="form-control" name="surveyls_title" id="surveyTitle" required="required" maxlength="200">
</div>
<div class="form-group col-md-4 col-md-6">
<label for="createsample" class="control-label"><?= gT('Create example question group and question?')?></label>
<div>
<input type="checkbox" name="createsample" />
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-4 col-md-6" >
Expand Down

0 comments on commit 583e768

Please sign in to comment.