Skip to content

Commit

Permalink
Fixed issue: can't set css/js files of uploaded templates
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Oct 27, 2017
1 parent 2827d55 commit 0a34bd8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 37 deletions.
20 changes: 16 additions & 4 deletions application/models/TemplateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ public static function importManifest($sTemplateName, $aDatas)
throw new InvalidArgumentException('$aDatas cannot be empty');
}


$oNewTemplate = new Template;
$oNewTemplate->name = $sTemplateName;
$oNewTemplate->folder = $sTemplateName;
Expand All @@ -827,11 +828,22 @@ public static function importManifest($sTemplateName, $aDatas)
$oNewTemplate->files_folder = $aDatas['files_folder'];
$oNewTemplate->owner_id = Yii::app()->user->id;
$oNewTemplate->extends = $aDatas['extends'];

if ($oNewTemplate->save()){
$oNewTemplateConfiguration = new TemplateConfiguration;
$oNewTemplateConfiguration->template_name = $sTemplateName;
$oNewTemplateConfiguration->template_name = $sTemplateName;
$oNewTemplateConfiguration = new TemplateConfiguration;
$oNewTemplateConfiguration->template_name = $sTemplateName;
$oNewTemplateConfiguration->template_name = $sTemplateName;

// Those ones are only filled when importing manifest from upload directory

$oNewTemplateConfiguration->files_css = json_encode($aDatas['files_css']);
$oNewTemplateConfiguration->files_js = json_encode($aDatas['files_js']);
$oNewTemplateConfiguration->files_print_css = json_encode($aDatas['files_print_css']);

$oNewTemplateConfiguration->cssframework_name = $aDatas['cssframework_name'];
$oNewTemplateConfiguration->cssframework_css = json_encode($aDatas['cssframework_css']);
$oNewTemplateConfiguration->cssframework_js = json_encode($aDatas['cssframework_js']);

$oNewTemplateConfiguration->options = json_encode($aDatas['aOptions']);
$oNewTemplateConfiguration->packages_to_load = json_encode($aDatas['packages_to_load']);

Expand Down
45 changes: 34 additions & 11 deletions application/models/TemplateManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,44 @@ public static function importManifest($sTemplateName, $aDatas=array() )
{
$oTemplate = Template::getTemplateConfiguration($sTemplateName, null, null, true);

$aDatas['api_version'] = (string) $oTemplate->config->metadatas->apiVersion;
$aDatas['extends'] = (string) $oTemplate->config->metadatas->extends;
$aDatas['author_email'] = (string) $oTemplate->config->metadatas->authorEmail;
$aDatas['author_url'] = (string) $oTemplate->config->metadatas->authorUrl;
$aDatas['copyright'] = (string) $oTemplate->config->metadatas->copyright;
$aDatas['version'] = (string) $oTemplate->config->metadatas->version;
$aDatas['license'] = (string) $oTemplate->config->metadatas->license;
$aDatas['view_folder'] = (string) $oTemplate->config->engine->viewdirectory;
$aDatas['files_folder'] = (string) $oTemplate->config->engine->filesdirectory;
$aDatas['packages_to_load'] = !empty($oTemplate->config->engine->packages) ? ((array) $oTemplate->config->engine->packages) : [];
$aDatas['aOptions'] = (!empty($oTemplate->config->options[0]) && count($oTemplate->config->options[0]) == 0 )?array():$oTemplate->config->options[0]; // If template provide empty options, it must be cleaned to avoid crashes
$aDatas['api_version'] = (string) $oTemplate->config->metadatas->apiVersion;
$aDatas['extends'] = (string) $oTemplate->config->metadatas->extends;
$aDatas['author_email'] = (string) $oTemplate->config->metadatas->authorEmail;
$aDatas['author_url'] = (string) $oTemplate->config->metadatas->authorUrl;
$aDatas['copyright'] = (string) $oTemplate->config->metadatas->copyright;
$aDatas['version'] = (string) $oTemplate->config->metadatas->version;
$aDatas['license'] = (string) $oTemplate->config->metadatas->license;
$aDatas['view_folder'] = (string) $oTemplate->config->engine->viewdirectory;
$aDatas['files_folder'] = (string) $oTemplate->config->engine->filesdirectory;

$aDatas['files_css'] = self::formatArrayFields($oTemplate, 'files', 'css');
$aDatas['files_js'] = self::formatArrayFields($oTemplate, 'files', 'js');
$aDatas['files_print_css'] = self::formatArrayFields($oTemplate, 'files', 'print_css');

$aDatas['cssframework_name'] = (string) $oTemplate->config->engine->cssframework_name;
$aDatas['cssframework_css'] = self::formatArrayFields($oTemplate, 'engine', 'cssframework_css');
$aDatas['cssframework_js'] = self::formatArrayFields($oTemplate, 'engine', 'cssframework_js');
$aDatas['packages_to_load'] = self::formatArrayFields($oTemplate, 'engine', 'packages');

$aDatas['aOptions'] = (!empty($oTemplate->config->options[0]) && count($oTemplate->config->options[0]) == 0 )?array():$oTemplate->config->options[0]; // If template provide empty options, it must be cleaned to avoid crashes

return parent::importManifest($sTemplateName, $aDatas );
}

/**
* This will prepare an array for the field, so the json_encode will create
* If a field is empty, its value should not be null, but an empty array for the json encoding in DB
*
* @param TemplateManifest $oTemplate
* @param string $sFieldPath path to the field (under config)
* @param string $sFieldName name of the field
* @return array field value | empty array
*/
public static function formatArrayFields($oTemplate, $sFieldPath, $sFieldName)
{
return !empty($oTemplate->config->$sFieldPath->$sFieldName) ? ((array) $oTemplate->config->$sFieldPath->$sFieldName) : array();
}

/**
* Get the DOMDocument of the Manifest
* @param string $sConfigPath path where to find the manifest
Expand Down
18 changes: 9 additions & 9 deletions templates/default/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@
-->
<files>
<css>
<filename>css/template.css</filename>
<filename>css/animate.css</filename>
<filename>css/ajaxify.css</filename>
<add>css/template.css</add>
<add>css/animate.css</add>
<add>css/ajaxify.css</add>
</css>
<js>
<filename>scripts/template.js</filename>
<filename>scripts/ajaxify.js</filename>
<add>scripts/template.js</add>
<add>scripts/ajaxify.js</add>
</js>
<print_css>
<filename>css/print_template.css</filename>
<add>css/print_template.css</add>
</print_css>
</files>

<!-- You can add here any option you want. It will be available in twig file via aSurveyInfo.options.youroptionname -->
<!-- eg: Ajaxmode: will be available with aSurveyInfo.options.ajaxmode -->
<!-- for animations, see https://daneden.github.io/animate.css/ -->
<options>
<ajaxmode>on</ajaxmode>
<ajaxmode>off</ajaxmode>
<brandlogo>on</brandlogo>
<brandlogofile>./files/logo.png</brandlogofile>
<boxcontainer>on</boxcontainer>
Expand Down Expand Up @@ -75,8 +75,8 @@
<!-- If bootstrap is registered as a css framework, it will be loaded first -->
<!-- Example: <packages>moment</packages> -->
<packages>pjax</packages>



<!--
List of pages/files for tempalte editor
Expand Down
14 changes: 7 additions & 7 deletions templates/material/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
-->
<files>
<css>
<filename>css/template.css</filename>
<filename>css/bootstrap-material-design.css</filename>
<filename>css/ripples.min.css</filename>
<add>css/template.css</add>
<add>css/bootstrap-material-design.css</add>
<add>css/ripples.min.css</add>
</css>
<js>
<filename>scripts/template.js</filename>
<filename>scripts/material.js</filename>
<filename>scripts/ripples.min.js</filename>
<add>scripts/template.js</add>
<add>scripts/material.js</add>
<add>scripts/ripples.min.js</add>
</js>
<print_css>
<filename>css/print_template.css</filename>
<add>css/print_template.css</add>
</print_css>
</files>

Expand Down
6 changes: 3 additions & 3 deletions templates/no_bootstrap/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
-->
<files>
<css>
<filename>css/template.css</filename>
<add>css/template.css</add>
</css>
<js>
<filename>scripts/template.js</filename>
<add>scripts/template.js</add>
</js>
<print_css>
<filename>css/print_template.css</filename>
<add>css/print_template.css</add>
</print_css>
</files>

Expand Down
6 changes: 3 additions & 3 deletions templates/vanilla/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
-->
<files>
<css>
<filename>css/template.css</filename>
<add>css/template.css</add>
</css>
<js>
<filename>scripts/template.js</filename>
<add>scripts/template.js</add>
</js>
<print_css>
<filename>css/print_template.css</filename>
<add>css/print_template.css</add>
</print_css>
</files>

Expand Down

0 comments on commit 0a34bd8

Please sign in to comment.