Skip to content

Commit

Permalink
Dev: Switch survey to default template if no configuration found.
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Nov 23, 2017
1 parent a3e0300 commit 9f93b5d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -150,10 +150,17 @@ public static function getInstanceFromConfigurationId($iTemplateConfigId) {
* @return TemplateConfiguration
*/
public static function getInstanceFromTemplateName($sTemplateName) {
return self::model()->find(
$oInstance = self::model()->find(
'template_name=:template_name AND sid IS NULL AND gsid IS NULL',
array(':template_name'=>$sTemplateName)
);

// If the survey configuration table of the wanted template doesn't exist (eg: manually deleted), then we provide the default one.
if (! is_a($oInstance, 'TemplateConfiguration') ){
$oInstance = self::getInstanceFromTemplateName('default');
}

return $oInstance;
}

/**
Expand Down Expand Up @@ -215,6 +222,7 @@ public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName = null
// TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok.
if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName);

$oTemplateConfigurationModel->id = null;
$oTemplateConfigurationModel->isNewRecord = true;
$oTemplateConfigurationModel->sid = $iSurveyId;
Expand Down

0 comments on commit 9f93b5d

Please sign in to comment.