Skip to content

Commit

Permalink
Fixed issue #18473: Survey listing - multiple calls of template (#3738)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Mar 5, 2024
1 parent 0d7300c commit bbc3eb6
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions application/models/Template.php
Expand Up @@ -312,11 +312,8 @@ public static function checkTemplateXML($templateName, $templateFolder)
*/
public static function checkIfTemplateExists($sTemplateName)
{
$aTemplates = self::getTemplateList();
if (array_key_exists($sTemplateName, $aTemplates)) {
return true;
}
return false;
// isset is faster, and we need a value, no need var here
return isset(self::getTemplateList()[$sTemplateName]);
}

/**
Expand Down Expand Up @@ -470,23 +467,31 @@ public static function getTemplatesFileFolder($sTemplateName = "")
}

/**
* Returns an array of all available template names - does a basic check if the template might be valid
*
* TODO: replace the calls to that function by a data provider based on search
*
* @return array
* Returns an array of all available template names - check if template exist
* key is template name, value is template folder
* @return string|]
*/
public static function getTemplateList()
{


$aTemplateList = array();

$oTemplateList = TemplateConfiguration::model()->search();
$oTemplateList->setPagination(false);

foreach ($oTemplateList->getData() as $oTemplate) {
$aTemplateList[$oTemplate->template_name] = (self::isStandardTemplate($oTemplate->template_name)) ? Yii::app()->getConfig("standardthemerootdir") . DIRECTORY_SEPARATOR . $oTemplate->template->folder : Yii::app()->getConfig("userthemerootdir") . DIRECTORY_SEPARATOR . $oTemplate->template->folder;
static $aTemplateList = null;
if (!is_null($aTemplateList)) {
return $aTemplateList;
}
$aTemplateList = [];
/* Get the template name by TemplateConfiguration and fiolder by template , no need other data */
$criteria = new CDBCriteria();
$criteria->select = 'template_name';
$criteria->with = ['template' => ['select' => 'folder']];
$criteria->order = 'template_name';
$oTemplateList = TemplateConfiguration::model()->with('template')->findAll($criteria);
$aTemplateInStandard = SurveyThemeHelper::getTemplateInStandard();
$aTemplateInUpload = SurveyThemeHelper::getTemplateInUpload();
foreach ($oTemplateList as $oTemplate) {
if (isset($aTemplateInStandard[$oTemplate->template->folder])) {
$aTemplateList[$oTemplate->template_name] = $aTemplateInStandard[$oTemplate->template->folder];
} elseif (isset($aTemplateInUpload[$oTemplate->template->folder])) {
$aTemplateList[$oTemplate->template_name] = $aTemplateInUpload[$oTemplate->template->folder];
}
}
return $aTemplateList;
}
Expand Down

0 comments on commit bbc3eb6

Please sign in to comment.