Skip to content

Commit

Permalink
Dev: added a way to disable bUseMagicInherit to get real field value …
Browse files Browse the repository at this point in the history
…from admin page
  • Loading branch information
LouisGac committed Aug 14, 2017
1 parent 96d3966 commit 693d1b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
18 changes: 11 additions & 7 deletions application/controllers/admin/templateoptions.php
Expand Up @@ -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);

Expand All @@ -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(
Expand All @@ -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);
}

Expand All @@ -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'];
Expand All @@ -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'];
Expand All @@ -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);
Expand All @@ -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'];
Expand All @@ -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;
}

Expand Down
10 changes: 6 additions & 4 deletions application/models/TemplateConfiguration.php
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -360,7 +362,7 @@ public function getHasOptionPage()
}

public function getOptionPage()
{
{
$this->prepareTemplateRendering();
return Yii::app()->twigRenderer->renderOptionPage($this, array('templateConfiguration' =>$this->attributes));
}
Expand Down Expand Up @@ -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'){
Expand Down

0 comments on commit 693d1b2

Please sign in to comment.