diff --git a/application/commands/TwigCommand.php b/application/commands/TwigCommand.php index 40df140c64e..3975133fb74 100644 --- a/application/commands/TwigCommand.php +++ b/application/commands/TwigCommand.php @@ -24,6 +24,7 @@ public function init() Yii::import('application.helpers.surveytranslator_helper', true); Yii::import('application.helpers.common_helper', true); Yii::import('application.helpers.expressions.em_manager_helper', true); + Yii::import('application.helpers.admin.htmleditor_helper', true); // Directories where the assets will be created. Yii::app()->assetManager->setBasePath(realpath(__DIR__.'/../../tmp/assets/')); @@ -48,10 +49,10 @@ public function actionIndex() * Generate twig cache files for each core Survey Theme and core questions views. * */ - public function actionGenerateTwigTmpFiles( $sThemeDir=null, $bGenerateSurveyCache=true, $bGenerateQuestionsCache=true, $bShowLogs=false ) + public function actionGenerateTwigTmpFiles( $sThemeDir=null, $bGenerateSurveyCache=true, $bGenerateQuestionsCache=true, $bGenerateAdminCache=true, $bShowLogs=false ) { $this->aLogs = array(); - $this->aLogs["action"] = "actionGenerateTwigTmpFiles $sThemeDir $bGenerateSurveyCache $bGenerateQuestionsCache $bShowLogs"; + $this->aLogs["action"] = "actionGenerateTwigTmpFiles $sThemeDir $bGenerateSurveyCache $bGenerateQuestionsCache $bGenerateAdminCache $bShowLogs"; if ($bGenerateSurveyCache){ $this->actionGenerateSurveyThemesCache($sThemeDir ); } @@ -60,6 +61,10 @@ public function actionGenerateTwigTmpFiles( $sThemeDir=null, $bGenerateSurveyCac $this->actionGenerateQuestionsCache(null); } + if ($bGenerateAdminCache){ + $this->actionGenerateAdminCache(null); + } + // TODO: here add something more complex to create a file log on the server, something that can be return to the CU server at release creation, etc if ($bShowLogs){ var_dump($this->aLogs); @@ -82,7 +87,6 @@ public function actionGenerateSurveyThemesCache($sThemeDir=null) foreach ($oThemeDir as $fileinfo) { if ($fileinfo->getFilename() != ".." && $fileinfo->getFilename() != "." && $fileinfo->getFilename() != "index.html"){ - $templatename = $fileinfo->getFilename(); $oTemplateForPreview = Template::getInstance($templatename, null, null, true, true)->prepareTemplateRendering($templatename, null, true); @@ -109,7 +113,6 @@ public function actionGenerateQuestionsCache( $sQuestionDir=null ) // Generate cache for question theme $sQuestionDir = ($sQuestionDir===null)?dirname(__FILE__).'/../views/survey/questions/answer':$sQuestionDir; - $oQuestionDir = new DirectoryIterator($sQuestionDir); foreach ($oQuestionDir as $fileinfo) { @@ -145,6 +148,34 @@ public function actionGenerateQuestionsCache( $sQuestionDir=null ) } } + /** + * Generate twig cache files for admin views. + * NOTE: It's a recursive function which build every twig file in admin area. + * + * @param string $sAdminDir the directory to parse, where to find the twig files. + */ + public function actionGenerateAdminCache( $sAdminDir=null ) + { + + $this->aLogs["action"] = "actionGenerateAdminCache $sAdminDir"; + + // Generate cache for admin area + $sAdminDir = ($sAdminDir===null)?dirname(__FILE__).'/../views/admin':$sAdminDir; + $oAdminDirectory = new RecursiveDirectoryIterator($sAdminDir); + $oAdminIterator = new RecursiveIteratorIterator($oAdminDirectory); + $oAdminRegex = new RegexIterator($oAdminIterator, '/^.+\.twig$/i', RecursiveRegexIterator::GET_MATCH); + + $aAdminData = array(); + foreach ($oAdminRegex as $oTwigFile) { + $sTwigFile = $oTwigFile[0]; + if (file_exists($sTwigFile)){ + $this->aLogs["twig"] = "$sTwigFile"; + $line = file_get_contents($sTwigFile); + $sHtml = Yii::app()->twigRenderer->convertTwigToHtml($line); + } + } + } + /** * Generate the cache for a given survey theme * @param TemplateManifest diff --git a/application/core/ConsoleApplication.php b/application/core/ConsoleApplication.php index b6efb6fe0f8..61e481210da 100644 --- a/application/core/ConsoleApplication.php +++ b/application/core/ConsoleApplication.php @@ -51,7 +51,7 @@ public function __construct($aApplicationConfig = null) $emailConfig = require(__DIR__.'/../config/email.php'); $versionConfig = require(__DIR__.'/../config/version.php'); $updaterVersionConfig = require(__DIR__.'/../config/updater_version.php'); - $lsConfig = array_merge($coreConfig, $emailConfig, $versionConfig, $updaterVersionConfig); + $lsConfig = array_merge($coreConfig, $consoleConfig, $emailConfig, $versionConfig, $updaterVersionConfig); /* Custom config file */ $configdir = $coreConfig['configdir']; diff --git a/application/views/admin/survey/Question/answerOptionsEdit_view.twig b/application/views/admin/survey/Question/answerOptionsEdit_view.twig index 447381717d7..ac56ed6067e 100644 --- a/application/views/admin/survey/Question/answerOptionsEdit_view.twig +++ b/application/views/admin/survey/Question/answerOptionsEdit_view.twig @@ -202,8 +202,10 @@ {% endfor %} - {% include 'admin/survey/Question/question_subviews/_modals.twig' %} - + {% if first==false %} {# pseudo condition due to reverse parsing problems while generating twig admin cache via console.php twig generateAdminCache #} + {% include '/admin/survey/Question/question_subviews/_modals.twig' %} + {% endif %} +

@@ -219,7 +221,7 @@ 'gid' : gid }) ) }}" - data-assessmentvisible="{% if assessmentvisible|length and assessmentvisible==true%}1{% else %}0{% endif %}" + data-assessmentvisible="{% if assessmentvisible==true %}1{% else %}0{% endif %}" data-errormessage="An error occured while processing the ajax request." data-surveyid="{{ surveyid }}" data-languages='{{ json_encode(all_languages) }}' diff --git a/application/views/admin/survey/subview/surveydashboard/001-sharingpanel.twig b/application/views/admin/survey/subview/surveydashboard/001-sharingpanel.twig index c051bcbf37b..a09098ba8d7 100644 --- a/application/views/admin/survey/subview/surveydashboard/001-sharingpanel.twig +++ b/application/views/admin/survey/subview/surveydashboard/001-sharingpanel.twig @@ -12,7 +12,9 @@ {{ getLanguageNameFromCode(oSurvey.language, false)}} ({{ gT("Base language") }}):

- {% set tmp_url = createAbsoluteUrl("survey/index", { "sid" : oSurvey.sid, "lang" : oSurvey.language}) %} + {% if oSurvey.sid %} {# pseudo condition due to reverse parsing problems while generating twig admin cache via console.php twig generateAdminCache #} + {% set tmp_url = createAbsoluteUrl("survey/index", { "sid" : oSurvey.sid, "lang" : oSurvey.language}) %} + {% endif %} {{tmp_url}}
@@ -25,8 +27,10 @@ {{ getLanguageNameFromCode(langname, false) ~ ":" }}
- {% set tmp_url = createAbsoluteUrl("survey/index", { "sid" : oSurvey.sid, "lang" : langname}) %} - {{tmp_url}} + {% if oSurvey.sid %} {# pseudo condition due to reverse parsing problems while generating twig admin cache via console.php twig generateAdminCache #} + {% set tmp_url = createAbsoluteUrl("survey/index", { "sid" : oSurvey.sid, "lang" : langname}) %} + {% endif %} + {{tmp_url}}
@@ -86,7 +90,9 @@
{{ gT("Share QR-code:") }}