Skip to content

Commit

Permalink
Dev: added the possibility to disable question template in the manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 23, 2016
1 parent ada599e commit cc87ccf
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions application/models/QuestionTemplate.php
Expand Up @@ -291,16 +291,24 @@ static public function getQuestionTemplateUserList($type)
// Maybe $file[0] != "." to hide Linux hidden directory
if (!is_file("$sUserQTemplateRootDir/$file") && $file != "." && $file != ".." && $file!=".svn"){

if (is_dir("$sUserQTemplateRootDir/$file/survey/questions/answer/$sFolderName")){
$templateName = $file;
$aQuestionTemplates[$file] = $templateName;
$sFullPathToQuestionTemplate = "$sUserQTemplateRootDir/$file/survey/questions/answer/$sFolderName";
if (is_dir($sFullPathToQuestionTemplate)){

// Get the config file and check if template is available
$oConfig = self::getTemplateConfig($sFullPathToQuestionTemplate);

if (is_object($oConfig) && $oConfig->show_as_template){
$templateName = $file;
$aQuestionTemplates[$file] = $templateName;
}
}
}
}
}
return $aQuestionTemplates;
}

// TODO: code duplication
static public function getQuestionTemplateCoreList($type)
{
$sCoreQTemplateRootDir = Yii::app()->getConfig("corequestiontemplaterootdir");
Expand All @@ -315,16 +323,37 @@ static public function getQuestionTemplateCoreList($type)
// Maybe $file[0] != "." to hide Linux hidden directory
if (!is_file("$sCoreQTemplateRootDir/$file") && $file != "." && $file != ".." && $file!=".svn"){

if (is_dir("$sCoreQTemplateRootDir/$file/survey/questions/answer/$sFolderName")){
$templateName = $file;
$aQuestionTemplates[$file] = $templateName;
$sFullPathToQuestionTemplate = "$sCoreQTemplateRootDir/$file/survey/questions/answer/$sFolderName";

if (is_dir($sFullPathToQuestionTemplate)){
// Get the config file and check if template is available
$oConfig = self::getTemplateConfig($sFullPathToQuestionTemplate);

if (is_object($oConfig) && $oConfig->show_as_template){
$templateName = $file;
$aQuestionTemplates[$file] = $templateName;
}
}
}
}
}
return $aQuestionTemplates;
}

/**
* Retreive the config of the question template
*/
static public function getTemplateConfig($sFullPathToQuestionTemplate)
{
$xmlFile = $sFullPathToQuestionTemplate.'/config.xml';
if(is_file($xmlFile)){
$sXMLConfigFile = file_get_contents( realpath ($xmlFile)); // Entity loader is disabled, so we can't use simplexml_load_file; so we must read the file with file_get_contents and convert it as a string
$oConfig = simplexml_load_string($sXMLConfigFile);
return $oConfig;
}
return false;
}

static public function getFolderName($type)
{
if ($type){
Expand Down

0 comments on commit cc87ccf

Please sign in to comment.