Skip to content

Commit

Permalink
Fixed error: Templates that were not the 'default' were not displayed…
Browse files Browse the repository at this point in the history
… properly
  • Loading branch information
lacrioque committed Aug 24, 2017
1 parent 9c3f07f commit a8d3b8f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 76 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/SurveysGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function update($id)
$oSurveySearch->gsid = $model->gsid;
$aData['oSurveySearch'] = $oSurveySearch;

$oTemplateOptions = Template::getTemplateConfiguration(null, null, $model->gsid);
$oTemplateOptions = TemplateConfiguration::getInstance(null, null, $model->gsid);
$oTemplateOptions->bUseMagicInherit = false;
$oTemplateOptionsReplacement = TemplateConfiguration::model()->findByPk($oTemplateOptions->id);
$templateOptionPage = $oTemplateOptionsReplacement->optionPage;
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ private function actionUpdateSurveyLocaleSettings($iSurveyID)
$current_template = $oSurvey->template;
$new_template = $this->_filterEmptyFields($oSurvey,'template');
if( $current_template != '' && $current_template !== $new_template ){
$currentConfiguration = Template::getTemplateConfiguration($current_template, $oSurvey->sid);
$currentConfiguration = TemplateConfiguration::getInstance($current_template, $oSurvey->gsid, $oSurvey->sid);

if(is_a($currentConfiguration, "TemplateConfiguration"))
TemplateConfiguration::model()->deleteByPk($currentConfiguration->id);
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/templateoptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function updatesurvey($sid)
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions/sa/updatesurvey",['surveyid'=>$sid,'sid'=>$sid]));
}

$model = Template::getTemplateConfiguration(null, $sid);
$model = TemplateConfiguration::getInstance(null, null, $sid);


if(isset($_POST['TemplateConfiguration'])){
Expand All @@ -150,7 +150,7 @@ public function updatesurveygroup($gsid)
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid]));
}

$model = Template::getTemplateConfiguration(null, null, $gsid);
$model = TemplateConfiguration::getInstance(null, $gsid);


if(isset($_POST['TemplateConfiguration'])){
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/admin/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function runWithParams($params)
*/
public function templatezip($templatename)
{
$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename);
$oEditedTemplate->prepareTemplateRendering($sTemplateName);
$oEditedTemplate = Template::getInstance($templatename);

if (!Permission::model()->hasGlobalPermission('templates','export'))
{
die('No permission');
Expand Down Expand Up @@ -229,8 +229,8 @@ public function uploadfile()
$action = returnGlobal('action');
$editfile = App()->request->getPost('editfile');
$templatename = returnGlobal('templatename');
$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename);
$oEditedTemplate->prepareTemplateRendering($sTemplateName);
$oEditedTemplate = Template::getInstance($templatename);

$templatedir = $oEditedTemplate->viewPath;
$screenname = returnGlobal('screenname');
$cssfiles = $oEditedTemplate->getValidScreenFiles("css");
Expand Down Expand Up @@ -389,7 +389,7 @@ public function templatefiledelete()
}

$sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename'));
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName); $oEditedTemplate->prepareTemplateRendering($sTemplateName);
$oEditedTemplate = Template::getInstance($sTemplateName);
$templatedir = $oEditedTemplate->viewPath;
$filesdir = $oEditedTemplate->filesPath;
$sPostedFile = App()->request->getPost('otherfile');
Expand Down Expand Up @@ -781,7 +781,7 @@ protected function _templatesummary($templatename, $screenname, $editfile, $rela
protected function _initialise($templatename, $screenname, $editfile, $showsummary = true)
{
// LimeSurvey style
$oEditedTemplate = Template::model()->getInstance($templatename, null,null, true);
$oEditedTemplate = Template::getInstance($templatename, null,null, true);

//App()->getClientScript()->reset();
Yii::app()->loadHelper('surveytranslator');
Expand Down
49 changes: 0 additions & 49 deletions application/helpers/admin/template_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ function getListOfFiles($wh){
return $arr;
}

/**
* Load this editfile
*
* @param string $template name
* @param string $templatefile
* @param string[] $templates directory
* @return string
*/
function filetext($templatename,$templatefile,$templates) {
$sFileName = gettemplatefilename($templatename,$templatefile);
if (file_exists($sFileName))
{
return file_get_contents($sFileName);
}
else
{
}
}

/**
* @param string $target
Expand Down Expand Up @@ -155,34 +137,3 @@ function templateExtractFilter($p_event, &$p_header)
}
}

/**
* Determine the storage path for a file
* TODO: remove all that logic.
*
* @param string $template
* @param string $templatefile
*/
function gettemplatefilename($template, $templatefile) {
$oEditedTemplate = Template::model()->getTemplateConfiguration($template);
switch (pathinfo($templatefile, PATHINFO_EXTENSION))
{
case 'twig':
// TODO: recursivity
$oEditedTemplate = Template::model()->getTemplateConfiguration($template);
return $oEditedTemplate->viewPath.$templatefile;
break;
case 'pstpl':
$oEditedTemplate = Template::model()->getTemplateConfiguration($template);
return $oEditedTemplate->viewPath.$templatefile;
break;
case 'css':
return $oEditedTemplate->path.DIRECTORY_SEPARATOR.$templatefile;
break;
case 'js':
return $oEditedTemplate->path.DIRECTORY_SEPARATOR.$templatefile;
break;
default:
return $oEditedTemplate->path.DIRECTORY_SEPARATOR.$templatefile;
break;
}
}
2 changes: 1 addition & 1 deletion application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public function getGoogleanalyticsapikey(){
}

public function getSurveyTemplateConfiguration(){
return Template::getTemplateConfiguration(null, $this->sid);
return TemplateConfiguration::getInstance(null, null, $this->sid);
}

private function _createSurveymenuArray($oSurveyMenuObjects)
Expand Down
17 changes: 9 additions & 8 deletions application/models/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,19 @@ public static function isStandardTemplate($sTemplateName)
* @param int|string $iSurveyGroupId
* @return TemplateConfiguration
*/
public static function getInstance($sTemplateName='', $iSurveyId='', $iSurveyGroupId='', $bForceXML=false)
public static function getInstance($sTemplateName=null, $iSurveyId=null, $iSurveyGroupId=null, $bForceXML=null)
{

// Template developper could prefer to work with XML rather than DB as a first step, for quick and easy changes
if (App()->getConfig('force_xmlsettings_for_survey_rendering') && YII_DEBUG){
$bForceXML=true;
}elseif( App()->getConfig('force_xmlsettings_for_survey_rendering') && YII_DEBUG){
$bForceXML=false;
if($bForceXML === null){
// Template developper could prefer to work with XML rather than DB as a first step, for quick and easy changes
if (App()->getConfig('force_xmlsettings_for_survey_rendering') && YII_DEBUG){
$bForceXML=true;
}elseif( App()->getConfig('force_xmlsettings_for_survey_rendering') && YII_DEBUG){
$bForceXML=false;
}
}

if (empty(self::$instance)) {
self::$instance = self::getTemplateConfiguration($sTemplateName, $iSurveyId, $iSurveyGroupId, $bForceXML);
self::$instance = self::getTemplateConfiguration($sTemplateName, $iSurveyGroupId, $iSurveyId, $bForceXML);
self::$instance->prepareTemplateRendering($sTemplateName, $iSurveyId);
}

Expand Down
2 changes: 1 addition & 1 deletion application/models/TemplateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ protected function setIsStandard()
// Then, the lonely differences between TemplateManifest and TemplateConfiguration should be how to retreive and format the data
// Note: signature are already the same

public function prepareTemplateRendering($sTemplateName='', $iSurveyId=''){}
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='', $bUseMagicInherit=true){}
public function addFileReplacement($sFile, $sType){}

protected function getFilesToLoad($oTemplate, $sType){}
Expand Down
10 changes: 5 additions & 5 deletions application/models/TemplateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ public function checkTemplate()
* @param string $iSurveyId the id of the survey. If
* @return $this
*/
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='')
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='', $bUseMagicInherit=true)
{
$this->bUseMagicInherit = true;
$this->bUseMagicInherit = $bUseMagicInherit;
$this->sTemplateName = $this->template->name;
$this->setIsStandard(); // Check if it is a CORE template
$this->path = ($this->isStandard)
Expand Down Expand Up @@ -553,10 +553,10 @@ protected function setMotherTemplates()
{
if(!empty($this->template->extends_templates_name)){
$sMotherTemplateName = $this->template->extends_templates_name;
$this->oMotherTemplate = Template::getTemplateConfiguration($sMotherTemplateName);
$this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName);
$this->oMotherTemplate = TemplateConfiguration::getInstanceFromTemplateName($sMotherTemplateName);
$this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName, null);
if ($this->oMotherTemplate->checkTemplate()){
$this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName); // Object Recursion
$this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName, null); // Object Recursion
}else{
// Throw exception? Set to default template?
}
Expand Down
2 changes: 1 addition & 1 deletion application/models/TemplateManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private function setTemplateName($sTemplateName='', $iSurveyId='')
* @param string $iSurveyId the id of the survey. If
* @return $this
*/
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='')
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='', $bUseMagicInherit=true)
{
$this->setTemplateName($sTemplateName, $iSurveyId); // Check and set template name
$this->setIsStandard(); // Check if it is a CORE template
Expand Down
2 changes: 1 addition & 1 deletion templates/default/views/subviews/start_form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'id' : 'limesurvey',
'name' : 'limesurvey',
'autocomplete': 'off',
'class' : 'survey-form-container',
'class' : 'survey-form-container form-horizontal',
}
%}

Expand Down

0 comments on commit a8d3b8f

Please sign in to comment.