Skip to content

Commit

Permalink
Fixed issue : standard template toot dir is not really updatable by a…
Browse files Browse the repository at this point in the history
…dmin

Dev: get the list of template name in a static var
  • Loading branch information
Shnoulle committed Oct 25, 2016
1 parent 6198cd5 commit 5b8edc5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -3439,7 +3439,7 @@ function do_shortfreetext($ia)
global $thissurvey;

$sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
$coreClass="ls-answers text-item";
$coreClass="ls-answers answer-item text-item";
if ($sGoogleMapsAPIKey!='')
{
$sGoogleMapsAPIKey = '&key='.$sGoogleMapsAPIKey;
Expand Down
79 changes: 44 additions & 35 deletions application/models/Template.php
Expand Up @@ -23,6 +23,9 @@ class Template extends LSActiveRecord
/** @var Template - The instance of template object */
private static $instance;

/** @var string[] list of standard template */
private static $standardTemplates = array();

/**
* Returns the static model of Settings table
*
Expand Down Expand Up @@ -199,19 +202,10 @@ public static function getTemplateList()

$aTemplateList=array();

if ($handle = opendir($standardtemplaterootdir))
{
while (false !== ($sFileName = readdir($handle)))
{
// Why not return directly standardTemplate list ?
if (!is_file("$standardtemplaterootdir/$sFileName") && self::isStandardTemplate($sFileName))
{
$aTemplateList[$sFileName] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$sFileName;
}
}
closedir($handle);
$aStandardTemplates=self::getStandardTemplateList();
foreach($aStandardTemplates as $templateName){
$aTemplateList[$templateName] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$templateName;
}

if ($sUserTemplateRootDir && $handle = opendir($sUserTemplateRootDir))
{
while (false !== ($sFileName = readdir($handle)))
Expand All @@ -237,21 +231,11 @@ public static function getTemplateListWithPreviews()
$standardtemplaterooturl=Yii::app()->getConfig("standardtemplaterooturl");

$aTemplateList=array();

if ($handle = opendir($standardtemplaterootdir))
{
while (false !== ($file = readdir($handle)))
{
// Why not return directly standardTemplate list ?
if (!is_file("$standardtemplaterootdir/$file") && self::isStandardTemplate($file))
{
$aTemplateList[$file]['directory'] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$file;
$aTemplateList[$file]['preview'] = $standardtemplaterooturl.'/'.$file.'/preview.png';
}
}
closedir($handle);
$aStandardTemplates=self::getStandardTemplateList();
foreach($aStandardTemplates as $templateName){
$aTemplateList[$file]['directory'] = $standardtemplaterootdir.DIRECTORY_SEPARATOR.$templateName;
$aTemplateList[$file]['preview'] = $standardtemplaterooturl.'/'.$templateName.'/preview.png';
}

if ($usertemplaterootdir && $handle = opendir($usertemplaterootdir))
{
while (false !== ($file = readdir($handle)))
Expand Down Expand Up @@ -279,15 +263,8 @@ public static function getTemplateListWithPreviews()
*/
public static function isStandardTemplate($sTemplateName)
{
return in_array($sTemplateName,
array(
'default',
'basic',
//~ 'news_paper',
//~ 'ubuntu_orange',
'test'
)
);
$standardTemplates=self::getStandardTemplateList();
return in_array($sTemplateName,$standardTemplates);
}

/**
Expand Down Expand Up @@ -325,4 +302,36 @@ public static function forceAssets()
}
}
}

/**
* Return the standard template list
* @return string[]
*/
public static function getStandardTemplateList()
{
$standardTemplates=self::$standardTemplates;
if(empty($standardTemplates)){
$standardTemplates = array();
$sStandardTemplateRootDir=Yii::app()->getConfig("standardtemplaterootdir");
if ($sStandardTemplateRootDir && $handle = opendir($sStandardTemplateRootDir))
{
while (false !== ($sFileName = readdir($handle)))
{
// Maybe $file[0] != "." to hide Linux hidden directory
if (!is_file("$sStandardTemplateRootDir/$sFileName") && $sFileName[0] != "." && file_exists("{$sStandardTemplateRootDir}/{$sFileName}/config.xml"))
{
$standardTemplates[$sFileName] = $sFileName;
}
}
closedir($handle);
}
ksort($standardTemplates);
if(!in_array("default",$standardTemplates)){
throw new Exception('There are no default template in stantard template root dir.');
}
self::$standardTemplates = $standardTemplates;
}

return self::$standardTemplates;
}
}
1 change: 0 additions & 1 deletion application/models/TemplateConfiguration.php
Expand Up @@ -74,7 +74,6 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')

// We check if it's a CORE template
$this->isStandard = $this->setIsStandard();

// If the template is standard, its root is based on standardtemplaterootdir, else, it's 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;

Expand Down
Expand Up @@ -241,3 +241,7 @@ function checkSelect2Languages(mylangs)
<img class="img-responsive" alt='<?php eT("Template preview image"); ?>' id='preview' src='<?php echo getTemplateURL($esrow['template']); ?>/preview.png' />
</div>
</div>
<?php
/* @todo : add a js var with standard template list name */
//$aStandardTemplateLis=Template::getStandardTemplateList();
?>
22 changes: 5 additions & 17 deletions scripts/admin/surveysettings.js
Expand Up @@ -79,7 +79,7 @@ $(document).ready(function(){
$('#btnSaveParams').click(saveParameter);
$('#addnewsurvey').submit(PostParameterGrid);
$('#globalsetting').submit(PostParameterGrid); // This is the name of survey settings update form

$( "#tabs" ).bind( "tabsactivate", function(event, ui) {
if (ui.newTab.index() > 4) // Hide on import and copy tab, otherwise show
{
Expand Down Expand Up @@ -175,24 +175,12 @@ function editParameter(rowid)

function templatechange(template)
{
/* @todo : fix it */
standardtemplates=[
'default',
'blue_sky',
'metro_ode',
'electric_black',
'night_mode',
'flat_and_modern',
'news_paper',
'light_and_shadow',
'material_design',
'readable',
'sandstone',
'minimalist',
'gunmetal',
'super_blue',
'ubuntu_orange',
'yeti'
];
'test',
'basic',
];
if (in_array(template,standardtemplates))
{
$("#preview").attr('src',standardtemplaterooturl+'/'+template+'/preview.png');
Expand Down

0 comments on commit 5b8edc5

Please sign in to comment.