From 96d39664e2ee18f4c932de5bdc51ebc8d14c3d58 Mon Sep 17 00:00:00 2001 From: LouisGac Date: Mon, 14 Aug 2017 12:40:20 +0200 Subject: [PATCH] Dev: rename setTemplateConfiguration to prepareTemplateRendering --- .../controllers/admin/templateoptions.php | 10 +++++----- application/controllers/admin/templates.php | 10 +++++----- application/models/Template.php | 8 ++++---- application/models/TemplateConfig.php | 2 +- application/models/TemplateConfiguration.php | 18 ++++++++++-------- application/models/TemplateManifest.php | 6 +++--- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/application/controllers/admin/templateoptions.php b/application/controllers/admin/templateoptions.php index 1cec10629d4..fd3192c7e01 100644 --- a/application/controllers/admin/templateoptions.php +++ b/application/controllers/admin/templateoptions.php @@ -74,10 +74,10 @@ private function _updateCommon($model,$sid=null){ // $this->performAjaxValidation($model); $templateOptionPage = $model->optionPage; - + yii::app()->clientScript->registerPackage('bootstrap-switch'); $aData = array( - 'model'=>$model, + 'model'=>$model, 'templateOptionPage' => $templateOptionPage ); if($sid !== null){ @@ -102,8 +102,8 @@ public function update($id) $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/templateoptions")); } $model = $this->loadModel($id); - $model->setTemplateConfiguration(); - + $model->prepareTemplateRendering(); + if(isset($_POST['TemplateConfiguration'])){ $model->attributes=$_POST['TemplateConfiguration']; if($model->save()) @@ -127,7 +127,7 @@ public function updatesurvey($sid) } $model = Template::getTemplateConfiguration(null, $sid); - $model->setTemplateConfiguration(); + $model->prepareTemplateRendering(); if(isset($_POST['TemplateConfiguration'])){ $model->attributes=$_POST['TemplateConfiguration']; diff --git a/application/controllers/admin/templates.php b/application/controllers/admin/templates.php index bf339a266f3..863cbbc6ef1 100644 --- a/application/controllers/admin/templates.php +++ b/application/controllers/admin/templates.php @@ -43,7 +43,7 @@ public function runWithParams($params) public function templatezip($templatename) { $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); - $oEditedTemplate->setTemplateConfiguration($sTemplateName); + $oEditedTemplate->prepareTemplateRendering($sTemplateName); if (!Permission::model()->hasGlobalPermission('templates','export')) { die('No permission'); @@ -230,7 +230,7 @@ public function uploadfile() $editfile = App()->request->getPost('editfile'); $templatename = returnGlobal('templatename'); $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); - $oEditedTemplate->setTemplateConfiguration($sTemplateName); + $oEditedTemplate->prepareTemplateRendering($sTemplateName); $templatedir = $oEditedTemplate->viewPath; $screenname = returnGlobal('screenname'); $cssfiles = $oEditedTemplate->getValidScreenFiles("css"); @@ -389,7 +389,7 @@ public function templatefiledelete() } $sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename')); - $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName); $oEditedTemplate->setTemplateConfiguration($sTemplateName); + $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName); $oEditedTemplate->prepareTemplateRendering($sTemplateName); $templatedir = $oEditedTemplate->viewPath; $filesdir = $oEditedTemplate->filesPath; $sPostedFile = App()->request->getPost('otherfile'); @@ -587,7 +587,7 @@ public function templatesavechanges() $sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename')); $screenname = returnGlobal('screenname'); $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName, null,null, true); - $oEditedTemplate->setTemplateConfiguration($sTemplateName); + $oEditedTemplate->prepareTemplateRendering($sTemplateName); $aScreenFiles = $oEditedTemplate->getValidScreenFiles("view"); $cssfiles = $oEditedTemplate->getValidScreenFiles("css"); $jsfiles = $oEditedTemplate->getValidScreenFiles("js"); @@ -702,7 +702,7 @@ protected function _templatesummary($templatename, $screenname, $editfile, $rela $aData['time'] = $time; /* Load this template config, else 'survey-template' package can be outdated */ $oEditedTemplate = Template::model()->getTemplateConfiguration($templatename, null,null, true); - $oEditedTemplate->setTemplateConfiguration($templatename); + $oEditedTemplate->prepareTemplateRendering($templatename); if (!$fnew) { $aData['filenotwritten'] = true; }else{ diff --git a/application/models/Template.php b/application/models/Template.php index 068ca4920b1..e66554ab899 100644 --- a/application/models/Template.php +++ b/application/models/Template.php @@ -212,7 +212,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId= $criteria->addCondition('gsid=:gsid'); $criteria->addCondition('templates_name=:templates_name'); $criteria->params = array('gsid' => $iSurveyGroupId, 'templates_name' => $sTemplateName); - + $oTemplateConfigurationModel = TemplateConfiguration::model()->find($criteria); // No specific template configuration for this survey @@ -268,7 +268,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId= $oTemplateConfigurationModel = new TemplateManifest; } - //$oTemplateConfigurationModel->setTemplateConfiguration($sTemplateName, $iSurveyId); + //$oTemplateConfigurationModel->prepareTemplateRendering($sTemplateName, $iSurveyId); return $oTemplateConfigurationModel; } @@ -428,7 +428,7 @@ public static function isStandardTemplate($sTemplateName) * Get instance of template object. * Will instantiate the template object first time it is called. * - * NOTE 1: This function will call setTemplateConfiguration that create/update all the packages needed to render the template, which imply to do the same for all mother templates + * NOTE 1: This function will call prepareTemplateRendering that 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 use this one. Call it only before rendering anything related to the template. * NOTE 3: If you need to get the related configuration to this template, rather use: getTemplateConfiguration() * @@ -449,7 +449,7 @@ public static function getInstance($sTemplateName='', $iSurveyId='', $iSurveyGro if (empty(self::$instance)) { self::$instance = self::getTemplateConfiguration($sTemplateName, $iSurveyId, $iSurveyGroupId, $bForceXML); - self::$instance->setTemplateConfiguration($sTemplateName, $iSurveyId); + self::$instance->prepareTemplateRendering($sTemplateName, $iSurveyId); } return self::$instance; diff --git a/application/models/TemplateConfig.php b/application/models/TemplateConfig.php index dfa75c170b1..7d442ddb8f3 100644 --- a/application/models/TemplateConfig.php +++ b/application/models/TemplateConfig.php @@ -266,7 +266,7 @@ protected function setIsStandard() // Then, the lonely differences between TemplateManifest and TemplateConfiguration should be how to retreive and format the data // Note: signature are already the same - public function setTemplateConfiguration($sTemplateName='', $iSurveyId=''){} + public function prepareTemplateRendering($sTemplateName='', $iSurveyId=''){} public function addFileReplacement($sFile, $sType){} protected function getFilesToLoad($oTemplate, $sType){} diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index bc705352274..70fe4928f19 100644 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -15,6 +15,8 @@ /* * 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 + * * The followings are the available columns in table '{{template_configuration}}': * @property string $id * @property string $templates_name @@ -194,7 +196,7 @@ public function getPreview() public static function importManifest($sTemplateName) { $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName, null,null, false); - $oEditedTemplate->setTemplateConfiguration($sTemplateName); + $oEditedTemplate->prepareTemplateRendering($sTemplateName); $oEditTemplateDb = Template::model()->findByPk($oEditedTemplate->oMotherTemplate->sTemplateName); $oNewTemplate = new Template; @@ -261,7 +263,7 @@ public function checkTemplate() * @param string $iSurveyId the id of the survey. If * @return $this */ - public function setTemplateConfiguration($sTemplateName='', $iSurveyId='') + public function prepareTemplateRendering($sTemplateName='', $iSurveyId='') { $this->sTemplateName = $this->template->name; $this->setIsStandard(); // Check if it is a CORE template @@ -341,7 +343,7 @@ class='btn btn-default'> public function getHasOptionPage() { - $this->setTemplateConfiguration(); + $this->prepareTemplateRendering(); $oRTemplate = $this; $sOptionFile = '/options/options.twig'; while (!file_exists($oRTemplate->path.$sOptionFile)){ @@ -351,7 +353,7 @@ public function getHasOptionPage() return false; break; } - $oMotherTemplate->setTemplateConfiguration(); + $oMotherTemplate->prepareTemplateRendering(); $oRTemplate = $oMotherTemplate; } return true; @@ -359,7 +361,7 @@ public function getHasOptionPage() public function getOptionPage() { - $this->setTemplateConfiguration(); + $this->prepareTemplateRendering(); return Yii::app()->twigRenderer->renderOptionPage($this, array('templateConfiguration' =>$this->attributes)); } @@ -429,16 +431,16 @@ protected function removeFileFromPackage( $sPackageName, $sType, $aSettings ) /** * Configure the mother template (and its mother templates) - * This is an object recursive call to TemplateConfiguration::setTemplateConfiguration() + * This is an object recursive call to TemplateConfiguration::prepareTemplateRendering() */ protected function setMotherTemplates() { if(!empty($this->template->extends_templates_name)){ $sMotherTemplateName = $this->template->extends_templates_name; $this->oMotherTemplate = Template::getTemplateConfiguration($sMotherTemplateName); - $this->oMotherTemplate->setTemplateConfiguration($sMotherTemplateName); + $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName); if ($this->oMotherTemplate->checkTemplate()){ - $this->oMotherTemplate->setTemplateConfiguration($sMotherTemplateName); // Object Recursion + $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName); // Object Recursion }else{ // Throw exception? Set to default template? } diff --git a/application/models/TemplateManifest.php b/application/models/TemplateManifest.php index a261986d8cf..b1b02d12cbb 100644 --- a/application/models/TemplateManifest.php +++ b/application/models/TemplateManifest.php @@ -368,7 +368,7 @@ private function setTemplateName($sTemplateName='', $iSurveyId='') * @param string $iSurveyId the id of the survey. If * @return $this */ - public function setTemplateConfiguration($sTemplateName='', $iSurveyId='') + public function prepareTemplateRendering($sTemplateName='', $iSurveyId='') { $this->setTemplateName($sTemplateName, $iSurveyId); // Check and set template name $this->setIsStandard(); // Check if it is a CORE template @@ -475,14 +475,14 @@ protected function removeFileFromPackage( $sPackageName, $sType, $aSetting ) /** * Configure the mother template (and its mother templates) - * This is an object recursive call to TemplateManifest::setTemplateConfiguration() + * This is an object recursive call to TemplateManifest::prepareTemplateRendering() */ protected function setMotherTemplates() { if (isset($this->config->metadatas->extends)){ $sMotherTemplateName = (string) $this->config->metadatas->extends; $this->oMotherTemplate = new TemplateManifest; - $this->oMotherTemplate->setTemplateConfiguration($sMotherTemplateName); // Object Recursion + $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName); // Object Recursion } }