Skip to content

Commit

Permalink
Dev: options field coherence between manifest and db
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 17, 2017
1 parent 9b93a3a commit d64fa2f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 3 additions & 5 deletions application/core/LSETwigViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,8 @@ public function renderTemplateFromString( $line, $aDatas, $oTemplate, $bReturn=f
}

// Add the template options
foreach($oRTemplate->oOptions as $oOption){
foreach($oOption as $key => $value){
$aDatas["aSurveyInfo"]["options"][$key] = (string) $value;
}
foreach($oTemplate->oOptions as $key => $value){
$aDatas["aSurveyInfo"]["options"][$key] = (string) $value;
}


Expand Down Expand Up @@ -242,7 +240,7 @@ public function renderTemplateFromString( $line, $aDatas, $oTemplate, $bReturn=f
$nvLine = $oTwigTemplate->render($aDatas, false);


if (!$bReturn){
if (!$bReturn){
Yii::app()->clientScript->registerPackage( $oTemplate->sPackageName );
ob_start(function($buffer, $phase)
{
Expand Down
2 changes: 1 addition & 1 deletion application/models/TemplateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TemplateConfig extends CActiveRecord
/** @var TemplateConfiguration $oMotherTemplate The template name */
public $oMotherTemplate;

/** @var SimpleXMLElement $oOptions The template options */
/** @var array $oOptions The template options */
public $oOptions;


Expand Down
13 changes: 10 additions & 3 deletions application/models/TemplateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public static function importManifest($sTemplateName)
if ($oNewTemplate->save()){
$oNewTemplateConfiguration = new TemplateConfiguration;
$oNewTemplateConfiguration->templates_name = $oEditedTemplate->sTemplateName;
$oNewTemplateConfiguration->templates_name = $oEditedTemplate->sTemplateName;
$oNewTemplateConfiguration->options = json_encode($oEditedTemplate->oOptions);


if ($oNewTemplateConfiguration->save()){
return true;
}else{
Expand Down Expand Up @@ -320,9 +324,12 @@ protected function setThisTemplate()
// TODO: twig getOption should return mother template option when option = inherit
$this->oOptions = array();
if (!empty($this->options)){
$this->oOptions[] = (array) json_decode($this->options);
$this->oOptions = json_decode($this->options);
}elseif(!empty($this->oMotherTemplate->oOptions)){
$this->oOptions[] = $this->oMotherTemplate->oOptions;
// NB: This case should never happen with core template edited via template editor
// Options are inherited from global settings to survey settings, not from mother template.
// But: a 3rd template provider could use that logic
$this->oOptions = $this->oMotherTemplate->oOptions;
}

// Not mandatory (use package dependances)
Expand Down Expand Up @@ -367,7 +374,7 @@ protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false)
$aAssetsToRemove = array();
if (!empty( $aFieldValue )){
$aAssetsToRemove = (array) $aFieldValue['replace'] ;
if($bInlcudeRemove){
if($bInlcudeRemove && isset($aFieldValue['remove'])){
$aAssetsToRemove = array_merge($aAssetsToRemove, (array) $aFieldValue['remove'] );
}
}
Expand Down
3 changes: 2 additions & 1 deletion application/models/TemplateManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ protected function setThisTemplate()

// Options are optional
if (!empty($this->config->xpath("//options"))){
$this->oOptions = $this->config->xpath("//options");
$aOptions = $this->config->xpath("//options");
$this->oOptions = $aOptions[0];
}elseif(!empty($this->oMotherTemplate->oOptions)){
$this->oOptions = $this->oMotherTemplate->oOptions;
}else{
Expand Down

0 comments on commit d64fa2f

Please sign in to comment.