Skip to content

Commit

Permalink
Dev: updated quanda to use LSETwigViewRenderer::renderFile
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 15, 2016
1 parent 40dd0ed commit 300cc0e
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions application/helpers/qanda_helper.php
Expand Up @@ -6548,33 +6548,17 @@ function getLabelInputWidth($labelAttributeWidth,$inputAttributeWidth){
* If the Survey template is configured to overwrite the question views, then the function will check if the required view exist in the template directory
* and then will use this one to render the question.
*
* Rem: all the logic has been moved to LSETwigViewRenderer::renderFile()
* We keep the function doRender here, to add the first parameter Yii::app()->getController()
* It can't be done in LSETwigViewRenderer because it implements IViewRenderer which force the signature of renderFile
*
* TODO: replace the 162 occurences of doRender([sView], $aData, [bReturn]) by App()->twigRenderer->renderFile( Yii::app()->getController(), [sView], $aData, [bReturn]);
*
* @param string $sView name of the view to be rendered.
* @param array $aData data to be extracted into PHP variables and made available to the view script
* @param boolean $bReturn whether the rendering result should be returned instead of being displayed to end users (should be always true)
*/
function doRender($sView, $aData, $bReturn=true)
{
global $thissurvey;
$requiredView = Yii::getPathOfAlias('application.views').$sView;
if(isset($thissurvey['template']))
{
$sTemplate = $thissurvey['template'];
$oTemplate = Template::model()->getInstance($sTemplate); // we get the template configuration
if($oTemplate->overwrite_question_views===true && Yii::app()->getConfig('allow_templates_to_overwrite_views')) // If it's configured to overwrite the views
{
$requiredView = $oTemplate->viewPath.ltrim($sView, '/'); // Then we check if it has its own version of the required view
if( file_exists($requiredView.'.php') ) // If it the case, the function will render this view
{
Yii::setPathOfAlias('survey.template.view', $requiredView); // to render a view from an absolute path outside of application/, path alias must be used.
$sView = 'survey.template.view'; // See : http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail
}
}
}

// Twig or not twig?
if( file_exists($requiredView.'.twig') ){
return Yii::app()->twigRenderer->renderFile( Yii::app()->getController(), $requiredView.'.twig', $aData, $bReturn);
}else{
return Yii::app()->getController()->renderPartial($sView, $aData, $bReturn);
}
return Yii::app()->twigRenderer->renderFile( Yii::app()->getController(), $sView, $aData, $bReturn);
}

0 comments on commit 300cc0e

Please sign in to comment.