Skip to content

Commit

Permalink
Dev: deleted methods passed to TemplateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 14, 2017
1 parent 30a5f63 commit 3895333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 199 deletions.
101 changes: 2 additions & 99 deletions application/models/TemplateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,9 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
return $this;
}

/**
* get the template API version
* @return integer
*/
public function getApiVersion()
{
return $this->apiVersion;
}

/**
* Returns the complete URL path to a given template name
*
* @param string $sTemplateName
* @return string template url
*/
public function getTemplateURL()
{
if(!isset($this->sTemplateurl)){
$this->sTemplateurl = Template::getTemplateURL($this->sTemplateName);
}
return $this->sTemplateurl;
}

// Different in both

/**
* Add a file replacement in the field `file_{css|js|print_css}` in table {{template_configuration}},
Expand All @@ -247,84 +228,6 @@ public function addFileReplacement($sFile, $sType)
}
}

/**
* Get the template for a given file. It checks if a file exist in the current template or in one of its mother templates
*
* @param string $sFile the file to look for (must contain relative path, unless it's a view file)
* @param string $oRTemplate template from which the recurrence should start
* @return TemplateManifest
*/
public function getTemplateForFile($sFile, $oRTemplate)
{
while (!file_exists($oRTemplate->path.'/'.$sFile) && !file_exists($oRTemplate->viewPath.$sFile)){
$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
throw new Exception("no template found for $sFile!");
break;
}
$oRTemplate = $oMotherTemplate;
}

return $oRTemplate;
}


/**
* Create a package for the asset manager.
* The asset manager will push to tmp/assets/xyxyxy/ the whole template directory (with css, js, files, etc.)
* And it will publish the CSS and the JS defined in config.xml. So CSS can use relative path for pictures.
* The publication of the package itself is in LSETwigViewRenderer::renderTemplateFromString()
*
*/
private function createTemplatePackage($oTemplate)
{
// Each template in the inheritance tree needs a specific alias
$sPathName = 'survey.template-'.$oTemplate->sTemplateName.'.path';
$sViewName = 'survey.template-'.$oTemplate->sTemplateName.'.viewpath';

Yii::setPathOfAlias($sPathName, $oTemplate->path);
Yii::setPathOfAlias($sViewName, $oTemplate->viewPath);

$aCssFiles = $aJsFiles = array();

// First we add the framework replacement (bootstrap.css must be loaded before template.css)
$aCssFiles = $this->getFrameworkAssetsToReplace('css');
$aJsFiles = $this->getFrameworkAssetsToReplace('js');

// Then we add the template config files
$aTCssFiles = $this->getFilesToLoad($oTemplate, 'css');
$aTJsFiles = $this->getFilesToLoad($oTemplate, 'js');

$aCssFiles = array_merge($aCssFiles, $aTCssFiles);
$aTJsFiles = array_merge($aCssFiles, $aTJsFiles);

$dir = getLanguageRTL(App()->language) ? 'rtl' : 'ltr';

// Remove/Replace mother template files
$aCssFiles = $this->changeMotherConfiguration('css', $aCssFiles);
$aJsFiles = $this->changeMotherConfiguration('js', $aJsFiles);

// Then we add the direction files if they exist
// TODO: attribute system rather than specific fields for RTL

$this->sPackageName = 'survey-template-'.$this->sTemplateName;
$sTemplateurl = $oTemplate->getTemplateURL();

// The package "survey-template-{sTemplateName}" will be available from anywhere in the app now.
// To publish it : Yii::app()->clientScript->registerPackage( 'survey-template-{sTemplateName}' );
// Depending on settings, it will create the asset directory, and publish the css and js files
Yii::app()->clientScript->addPackage( $this->sPackageName, array(
'devBaseUrl' => $sTemplateurl, // Used when asset manager is off
'basePath' => $sPathName, // Used when asset manager is on
'css' => $aCssFiles,
'js' => $aJsFiles,
'depends' => $oTemplate->depends,
) );
}



// Different in both

/**
* From a list of json files in db it will generate a PHP array ready to use by removeFileFromPackage()
Expand Down
104 changes: 4 additions & 100 deletions application/models/TemplateManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @subpackage Backend
*/
class TemplateManifest extends TemplateConfig
{
{
public $templateEditor;

/** @var string $iSurveyId The current Survey Id. It can be void. It's use only to retreive the current template of a given survey */
Expand Down Expand Up @@ -330,28 +330,10 @@ private function readManifest()

// Shared interface with TemplateConfiguration

/**
* get the template API version
* @return integer
*/
public function getApiVersion()
{
return $this->apiVersion;
}

/**
* Returns the complete URL path to a given template name
*
* @param string $sTemplateName
* @return string template url
*/
public function getTemplateURL()
{
if(!isset($this->sTemplateurl)){
$this->sTemplateurl = Template::getTemplateURL($this->sTemplateName);
}
return $this->sTemplateurl;
}


// Different in both

/**
* Add a file replacement entry
Expand Down Expand Up @@ -394,84 +376,6 @@ public function addFileReplacement($sFile, $sType)
}


/**
* Get the template for a given file. It checks if a file exist in the current template or in one of its mother templates
*
* @param string $sFile the file to look for (must contain relative path, unless it's a view file)
* @param string $oRTemplate template from which the recurrence should start
* @return TemplateManifest
*/
public function getTemplateForFile($sFile, $oRTemplate)
{
while (!file_exists($oRTemplate->path.'/'.$sFile) && !file_exists($oRTemplate->viewPath.$sFile)){
$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
throw new Exception("no template found for $sFile!");
break;
}
$oRTemplate = $oMotherTemplate;
}

return $oRTemplate;
}


/**
* Create a package for the asset manager.
* The asset manager will push to tmp/assets/xyxyxy/ the whole template directory (with css, js, files, etc.)
* And it will publish the CSS and the JS defined in config.xml. So CSS can use relative path for pictures.
* The publication of the package itself is in LSETwigViewRenderer::renderTemplateFromString()
*
* @param $oTemplate TemplateManifest
*/
private function createTemplatePackage($oTemplate)
{
// Each template in the inheritance tree needs a specific alias
$sPathName = 'survey.template-'.$oTemplate->sTemplateName.'.path';
$sViewName = 'survey.template-'.$oTemplate->sTemplateName.'.viewpath';

Yii::setPathOfAlias($sPathName, $oTemplate->path);
Yii::setPathOfAlias($sViewName, $oTemplate->viewPath);

$aCssFiles = $aJsFiles = array();

// First we add the framework replacement (bootstrap.css must be loaded before template.css)
$aCssFiles = $this->getFrameworkAssetsToReplace('css');
$aJsFiles = $this->getFrameworkAssetsToReplace('js');

// Then we add the template config files
$aTCssFiles = $this->getFilesToLoad($oTemplate, 'css');
$aTJsFiles = $this->getFilesToLoad($oTemplate, 'js');

$aCssFiles = array_merge($aCssFiles, $aTCssFiles);
$aTJsFiles = array_merge($aCssFiles, $aTJsFiles);

$dir = getLanguageRTL(App()->language) ? 'rtl' : 'ltr';

// Remove/Replace mother template files
$aCssFiles = $this->changeMotherConfiguration('css', $aCssFiles);
$aJsFiles = $this->changeMotherConfiguration('js', $aJsFiles);

// Then we add the direction files if they exist
// TODO: attribute system rather than specific fields for RTL

$this->sPackageName = 'survey-template-'.$this->sTemplateName;
$sTemplateurl = $oTemplate->getTemplateURL();

// The package "survey-template-{sTemplateName}" will be available from anywhere in the app now.
// To publish it : Yii::app()->clientScript->registerPackage( 'survey-template-{sTemplateName}' );
// Depending on settings, it will create the asset directory, and publish the css and js files
Yii::app()->clientScript->addPackage( $this->sPackageName, array(
'devBaseUrl' => $sTemplateurl, // Used when asset manager is off
'basePath' => $sPathName, // Used when asset manager is on
'css' => $aCssFiles,
'js' => $aJsFiles,
'depends' => $oTemplate->depends,
) );
}


// Different in both

/**
* From a list of json files in db it will generate a PHP array ready to use by removeFileFromPackage()
Expand Down

0 comments on commit 3895333

Please sign in to comment.