Skip to content

Commit

Permalink
Dev: added TemplateConfiguration::changeMotherConfiguration()
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed May 24, 2017
1 parent 662df21 commit b4abafb
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions application/models/TemplateConfiguration.php
Expand Up @@ -158,19 +158,9 @@ private function createTemplatePackage($oTemplate)

// Remove mother files
// TODO: need a general method called for css, js etc
foreach($aCssFiles as $key => $cssFile){
if (!empty($cssFile['replace']) || !empty($cssFile['remove'])){
Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, 'css', $cssFile['replace'] );
unset($aCssFiles[$key]);
}
}

foreach($aJsFiles as $key => $jsFile){
if (!empty($jsFile['replace']) || !empty($jsFile['remove']) ){
Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, 'js', $jsFile['replace'] );
unset($aJsFiles[$key]);
}
}
$aCssFiles = $this->changeMotherConfiguration('css', $aCssFiles);
$aJsFiles = $this->changeMotherConfiguration('js', $aJsFiles);

if (isset($oTemplate->config->files->$dir)) {
$aCssFilesDir = isset($oTemplate->config->files->$dir->css->filename) ? (array) $oTemplate->config->files->$dir->css->filename : array();
Expand Down Expand Up @@ -198,6 +188,24 @@ private function createTemplatePackage($oTemplate)
) );
}

/**
* Change the mother template configuration depending on template settings
* @var $sType string the type of settings to change (css or js)
* @var $aSettings array array of local setting
* @return array
*/
private function changeMotherConfiguration( $sType, $aSettings )
{
foreach( $aSettings as $key => $aSetting){
if (!empty($aSetting['replace']) || !empty($aSetting['remove'])){
Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, $sType, $aSetting['replace'] );
unset($aSettings[$key]);
}
}

return $aSettings;
}

/**
* Read the config.xml file of the template and push its contents to $this->config
*/
Expand Down Expand Up @@ -342,7 +350,7 @@ private function getDependsPackages($oTemplate)

/* Adding rtl/tl specific package (see https://bugs.limesurvey.org/view.php?id=11970#c42317 ) */
$dir = getLanguageRTL(App()->language) ? 'rtl' : 'ltr';

if(!empty($this->packages->$dir->package)) {
$packages=array_merge ($packages,(array)$this->packages->$dir->package);
}
Expand Down

0 comments on commit b4abafb

Please sign in to comment.