From 693d1b2ef50c180fb182ab436e85caa4137cd1cf Mon Sep 17 00:00:00 2001 From: LouisGac Date: Mon, 14 Aug 2017 13:02:55 +0200 Subject: [PATCH] Dev: added a way to disable bUseMagicInherit to get real field value from admin page --- .../controllers/admin/templateoptions.php | 18 +++++++++++------- application/models/TemplateConfiguration.php | 10 ++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/application/controllers/admin/templateoptions.php b/application/controllers/admin/templateoptions.php index fd3192c7e01..da74093a971 100644 --- a/application/controllers/admin/templateoptions.php +++ b/application/controllers/admin/templateoptions.php @@ -49,8 +49,8 @@ public function create() die('No permission'); } - $model=new TemplateOptions; - + $model = new TemplateOptions; + $model->bUseMagicInherit = false; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); @@ -73,7 +73,8 @@ private function _updateCommon($model,$sid=null){ // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); - $templateOptionPage = $model->optionPage; + $oModelWithInheritReplacement = TemplateConfiguration::model()->findByPk($model->id); + $templateOptionPage = $oModelWithInheritReplacement->optionPage; yii::app()->clientScript->registerPackage('bootstrap-switch'); $aData = array( @@ -85,8 +86,7 @@ private function _updateCommon($model,$sid=null){ $aData['title_bar']['title'] = gT("Survey template options"); $aData['subaction'] = gT("Survey template options"); } - - // TODO: twig file from template folder + $this->_renderWrappedTemplate('templateoptions', 'update', $aData); } @@ -102,7 +102,7 @@ public function update($id) $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions")); } $model = $this->loadModel($id); - $model->prepareTemplateRendering(); + $model->bUseMagicInherit = false; if(isset($_POST['TemplateConfiguration'])){ $model->attributes=$_POST['TemplateConfiguration']; @@ -127,7 +127,7 @@ public function updatesurvey($sid) } $model = Template::getTemplateConfiguration(null, $sid); - $model->prepareTemplateRendering(); + $model->bUseMagicInherit = false; if(isset($_POST['TemplateConfiguration'])){ $model->attributes=$_POST['TemplateConfiguration']; @@ -151,6 +151,7 @@ public function index() $aData = array(); $model = new TemplateConfiguration('search'); + $model->bUseMagicInherit = false; $model->sid = $model->gsid = $model->uid = null; $aData['model'] = $model; $this->_renderWrappedTemplate('templateoptions', 'index', $aData); @@ -162,6 +163,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']; @@ -183,6 +185,8 @@ public function loadModel($id) $model=TemplateConfiguration::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); + + $model->bUseMagicInherit = false; return $model; } diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 70fe4928f19..a332de8aa9e 100644 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -15,7 +15,7 @@ /* * This is the model class for table "{{template_configuration}}". * - * NOTE: if you only need to access to the table, you don't need to call + * NOTE: if you only need to access to the table, you don't need to call prepareTemplateRendering * * The followings are the available columns in table '{{template_configuration}}': * @property string $id @@ -49,6 +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; // Caches @@ -254,7 +256,7 @@ public function checkTemplate() } /** - * Constructs a template configuration object + * Prepare all the needed datas to render the temple * If any problem (like template doesn't exist), it will load the default template configuration * NOTE 1: This function will create/update all the packages needed to render the template, which imply to do the same for all mother templates * NOTE 2: So if you just want to access the TemplateConfiguration AR Object, you don't need to call it. Call it only before rendering anything related to the template. @@ -360,7 +362,7 @@ public function getHasOptionPage() } public function getOptionPage() - { + { $this->prepareTemplateRendering(); return Yii::app()->twigRenderer->renderOptionPage($this, array('templateConfiguration' =>$this->attributes)); } @@ -597,7 +599,7 @@ public function __get($name) { $aAttributesThatCanBeInherited = array('files_css', 'files_js', 'options', 'cssframework_name', 'cssframework_css', 'cssframework_js'); - if (in_array($name, $aAttributesThatCanBeInherited)){ + if (in_array($name, $aAttributesThatCanBeInherited) && $this->bUseMagicInherit){ // Full inheritance of the whole field $sAttribute = parent::__get($name); if($sAttribute === 'inherit'){