Skip to content

Commit

Permalink
Dev: added TemplateConfiguration::setPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed May 24, 2017
1 parent d5b91dc commit 6e44b0b
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions application/models/TemplateConfiguration.php
Expand Up @@ -96,29 +96,8 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
// We check if it is a CORE template
$this->setIsStandard();

// If the template is standard, its root is based on standardtemplaterootdir, else, it is a user template, its root is based on usertemplaterootdir
$this->path = ($this->isStandard)?Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName:Yii::app()->getConfig("usertemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;

// If the template directory doesn't exist, it can be that:
// - user deleted a custom theme
// In any case, we just set Default as the template to use
if (!is_dir($this->path)) {
$this->sTemplateName = 'default';
$this->isStandard = true;
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
if(!$this->iSurveyId){
setGlobalSetting('defaulttemplate', 'default');
}
}

// If the template doesn't have a config file (maybe it has been deleted, or whatever),
// then, we load the default template
$this->hasConfigFile = (string) is_file($this->path.DIRECTORY_SEPARATOR.'config.xml');
$this->setPath();

if (!$this->hasConfigFile) {
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;

}

$this->xmlFile = $this->path.DIRECTORY_SEPARATOR.'config.xml';

Expand Down Expand Up @@ -151,6 +130,33 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
return $this;
}

private function setPath()
{
// If the template is standard, its root is based on standardtemplaterootdir, else, it is a user template, its root is based on usertemplaterootdir
$this->path = ($this->isStandard)?Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName:Yii::app()->getConfig("usertemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;

// If the template directory doesn't exist, it can be that:
// - user deleted a custom theme
// In any case, we just set Default as the template to use
if (!is_dir($this->path)) {
$this->sTemplateName = 'default';
$this->isStandard = true;
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
if(!$this->iSurveyId){
setGlobalSetting('defaulttemplate', 'default');
}
}

// If the template doesn't have a config file (maybe it has been deleted, or whatever),
// then, we load the default template

$this->hasConfigFile = (string) is_file($this->path.DIRECTORY_SEPARATOR.'config.xml');
if (!$this->hasConfigFile) {
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;

}
}

private function setTemplateName($sTemplateName)
{
// If it is called from the template editor, a template name will be provided.
Expand Down

0 comments on commit 6e44b0b

Please sign in to comment.