Skip to content

Commit

Permalink
Dev: transparent usage of bUseMagicInherit
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Aug 18, 2017
1 parent 3b3654c commit f55424e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
16 changes: 8 additions & 8 deletions application/controllers/admin/templateoptions.php
Expand Up @@ -50,7 +50,7 @@ public function create()
}

$model = new TemplateOptions;
$model->bUseMagicInherit = false;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

Expand Down Expand Up @@ -86,7 +86,7 @@ private function _updateCommon($model,$sid=null){
$aData['title_bar']['title'] = gT("Survey template options");
$aData['subaction'] = gT("Survey template options");
}

$this->_renderWrappedTemplate('templateoptions', 'update', $aData);
}

Expand All @@ -102,7 +102,7 @@ public function update($id)
$this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions"));
}
$model = $this->loadModel($id);
$model->bUseMagicInherit = false;


if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
Expand All @@ -127,7 +127,7 @@ public function updatesurvey($sid)
}

$model = Template::getTemplateConfiguration(null, $sid);
$model->bUseMagicInherit = false;


if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
Expand All @@ -151,7 +151,7 @@ public function updatesurveygroup($gsid)
}

$model = Template::getTemplateConfiguration(null, null, $gsid);
$model->bUseMagicInherit = false;


if(isset($_POST['TemplateConfiguration'])){
$model->attributes=$_POST['TemplateConfiguration'];
Expand All @@ -175,7 +175,7 @@ public function index()
$aData = array();

$model = new TemplateConfiguration('search');
$model->bUseMagicInherit = false;

$aData['model'] = $model;
$this->_renderWrappedTemplate('templateoptions', 'index', $aData);
}
Expand All @@ -186,7 +186,7 @@ public function index()
public function admin()
{
$model=new TemplateOptions('search');
$model->bUseMagicInherit = false;

$model->unsetAttributes(); // clear any default values
if(isset($_GET['TemplateOptions']))
$model->attributes=$_GET['TemplateOptions'];
Expand All @@ -209,7 +209,7 @@ public function loadModel($id)
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');

$model->bUseMagicInherit = false;

return $model;
}

Expand Down
28 changes: 16 additions & 12 deletions application/models/TemplateConfiguration.php
Expand Up @@ -49,8 +49,8 @@ class TemplateConfiguration extends TemplateConfig
*/
public $oParentTemplate;

/**@var boolean Should the magic getters automatically retreives the parent value when field is set to inherit */
public $bUseMagicInherit = true;
/**@var boolean Should the magic getters automatically retreives the parent value when field is set to inherit. Only turn to on for template rendering */
public $bUseMagicInherit = false;

// Caches

Expand Down Expand Up @@ -147,15 +147,15 @@ public static function getInstanceFromTemplateName($sTemplateName){
* Returns a TemplateConfiguration Object based on a surveygroup ID
* If no instance is existing, it will create one.
*
* @param [Integer] $iSurveyGroupId
* @param [Integer] $iSurveyGroupId
* @param [String] $sTemplateName
* @return TemplateConfiguration
*/
public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName=null){

//if a template name is given also check against that
$sTemplateName = $sTemplateName != null ? $sTemplateName : SurveysGroups::model()->findByPk($iSurveyGroupId)->template;

$criteria = new CDbCriteria();
$criteria->addCondition('gsid=:gsid');
$criteria->addCondition('templates_name=:templates_name');
Expand All @@ -174,14 +174,14 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam
}

return $oTemplateConfigurationModel;

}

/**
* Returns a TemplateConfiguration Object based on a surveyID
* If no instance is existing, it will create one.
*
* @param [Integer] $iSurveyId
* @param [Integer] $iSurveyId
* @param [String] $sTemplateName
* @return TemplateConfiguration
*/
Expand All @@ -197,7 +197,7 @@ public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName=null){

$oTemplateConfigurationModel = TemplateConfiguration::model()->find($criteria);


// No specific template configuration for this surveygroup => create one
// TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok.
if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null){
Expand Down Expand Up @@ -231,7 +231,7 @@ public static function getInstance($sTemplateName=null, $iSurveyGroupId=null, $i
if($iSurveyGroupId!=null && $iSurveyId==null) {
$oTemplateConfigurationModel = @TemplateConfiguration::getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName);
}

if($iSurveyId!=null) {
$oTemplateConfigurationModel = @TemplateConfiguration::getInstanceFromSurveyId($iSurveyId, $sTemplateName);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ public function search()
$criteria->compare('cssframework_css',$this->cssframework_css,true);
$criteria->compare('cssframework_js',$this->cssframework_js,true);
$criteria->compare('packages_to_load',$this->packages_to_load,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
Expand Down Expand Up @@ -377,6 +377,7 @@ public function checkTemplate()
*/
public function prepareTemplateRendering($sTemplateName='', $iSurveyId='')
{
$this->bUseMagicInherit = true;
$this->sTemplateName = $this->template->name;
$this->setIsStandard(); // Check if it is a CORE template
$this->path = ($this->isStandard)
Expand Down Expand Up @@ -472,7 +473,7 @@ public function getHasOptionPage()
}

public function getOptionPage()
{
{
$this->prepareTemplateRendering();
return Yii::app()->twigRenderer->renderOptionPage($this, array('templateConfiguration' =>$this->attributes));
}
Expand Down Expand Up @@ -707,21 +708,24 @@ public function getParentConfiguration(){
if($this->sid != null ){
$oSurvey = Survey::model()->findByPk($this->sid);
$this->oParentTemplate = Template::getTemplateConfiguration(null,null,$oSurvey->gsid);
$this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit;
return $this->oParentTemplate;
}

//check for surveygroup id if a surveygroup is given
if($this->sid == null && $this->gsid != null ){
$oSurveyGroup = SurveysGroups::model()->findByPk($this->gsid);
//Switch if the surveygroup inherits from a parent surveygroup
if($oSurveyGroup->parent_id != 0) {
$this->oParentTemplate = Template::getTemplateConfiguration(null,null,$oSurveyGroup->parent_id);
$this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit;
return $this->oParentTemplate;
}
}

//in the endcheck for general global template
$this->oParentTemplate = Template::getTemplateConfiguration($this->templates_name);
$this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit;
return $this->oParentTemplate;
}
return $this->oParentTemplate;
Expand Down

0 comments on commit f55424e

Please sign in to comment.