Skip to content

Commit

Permalink
Dev: few refactorisation to handle template editor specificities
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jun 13, 2017
1 parent 124c99e commit 41a1cdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
19 changes: 12 additions & 7 deletions application/core/LSETwigViewRenderer.php
Expand Up @@ -135,21 +135,27 @@ public function renderQuestion( $sView, $aData)
}
}

public function renderTemplateForTemplateEditor($sView, $aDatas, $oEditedTemplate)
{
$oTemplate = $this->getTemplateForView($sView, $oEditedTemplate);
$line = file_get_contents($oTemplate->viewPath.$sView);
$result = $this->renderTemplateFromString( $line, $aDatas, $oTemplate, true);
return $result;
}

public function renderTemplateFromFile($sView, $aDatas, $bReturn)
{
$oTemplate = $this->getTemplateForView($sView);
$oRTemplate = Template::model()->getInstance();
$oTemplate = $this->getTemplateForView($sView, $oRTemplate);
$line = file_get_contents($oTemplate->viewPath.$sView);
$result = $this->renderTemplateFromString( $line, $aDatas, $bReturn);
$result = $this->renderTemplateFromString( $line, $aDatas, $oTemplate, $bReturn);
if ($bReturn){
return $result;
}
}

private function getTemplateForView($sView)
private function getTemplateForView($sView, $oRTemplate)
{
$oRTemplate = Template::model()->getInstance();

while (!file_exists($oRTemplate->viewPath.$sView)){

$oMotherTemplate = $oRTemplate->oMotherTemplate;
Expand All @@ -170,11 +176,10 @@ private function getTemplateForView($sView)
* @param array $aDatas Array containing the datas needed to render the view ($thissurvey)
* @param boolean $bReturn Should the function echo the result, or just returns it?
*/
public function renderTemplateFromString( $line, $aDatas, $bReturn)
public function renderTemplateFromString( $line, $aDatas, $oRTemplate, $bReturn=false)
{
$this->_twig = $twig = parent::getTwig();
$loader = $this->_twig->getLoader();
$oRTemplate = Template::model()->getInstance();
$loader->addPath($oRTemplate->viewPath);
Yii::app()->clientScript->registerPackage( $oRTemplate->sPackageName );

Expand Down
11 changes: 8 additions & 3 deletions templates/default/views/subviews/survey/question.twig
Expand Up @@ -17,7 +17,7 @@
It will render a question. It's included in the for loop in group.twig
Here, you have access to the array aQuestion that contains the data of the current question.
To see what's inside aQuestion, turn debug mode on, and copy the following line to the end of this file:
To see what's inside aQuestion, turn debug mode on, and copy the following line to the end of this file:
{{ dump(aQuestion) }}
All content of aQuestion itself is generated from qanda_helper.
Expand All @@ -28,10 +28,15 @@


{# Showing question code/number is a survey level setting, so it's inside the array aSurveyInfo #}
{% set aShow = aSurveyInfo.aShow %}
{% set aShow = aSurveyInfo.aShow %}
{% set sClasses = '' %}

{% if not (aQuestion.templateeditor) %}
{% set sClasses = getAllQuestionClasses( aQuestion.qid ) %}
{% endif %}

<!-- Question -->
<div id="question{{ aQuestion.qid }}" class=" {{ getAllQuestionClasses( aQuestion.qid ) }} {{ aQuestion.input_error_class }} question-container row">
<div id="question{{ aQuestion.qid }}" class=" {{ sClasses }} {{ aQuestion.input_error_class }} question-container row">

<!-- Question text -->
<div class="question-title-container bg-primary col-xs-12">
Expand Down

0 comments on commit 41a1cdd

Please sign in to comment.