diff --git a/application/helpers/admin/import_helper.php b/application/helpers/admin/import_helper.php index 38a0d8417f6..248113077ba 100644 --- a/application/helpers/admin/import_helper.php +++ b/application/helpers/admin/import_helper.php @@ -858,6 +858,7 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe $results['quota']=0; $results['quotals']=0; $results['quotamembers']=0; + $results['plugin_settings']=0; $results['survey_url_parameters']=0; $results['importwarnings']=array(); @@ -1538,6 +1539,34 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe } } + // Import Survey plugins settings + if(isset($xml->plugin_settings)) { + $pluginNamesWarning=array(); // To shown not exist warning only one time. + foreach ($xml->plugin_settings->rows->row as $row) + { + // Find plugin id + if(isset($row->name)) { + $oPlugin = Plugin::model()->find("name = :name",array(":name"=>$row->name)); + if($oPlugin) { + $setting = new PluginSetting; + $setting->plugin_id = $oPlugin->id; + $setting->model = "Survey"; + $setting->model_id = $iNewSID; + $setting->key = (string) $row->key; + $setting->value = (string) $row->value; + if($setting->save()) { + $results['plugin_settings']++; + } else { + $results['importwarnings'][] = sprintf(gT("An error happen when try to save %s for plugin %s"),CHtml::encode($row->key),CHtml::encode($row->name)); + } + } elseif(!isset($pluginNamesWarning[(string)$row->name])) { + $results['importwarnings'][] = sprintf(gT("Plugin %s didn't exist, settings not imported"),CHtml::encode($row->name)); + $pluginNamesWarning[(string)$row->name] = 1; + } + } + } + } + // Set survey rights Permission::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'],$iNewSID); $aOldNewFieldmap=reverseTranslateFieldNames($iOldSID,$iNewSID,$aGIDReplacements,$aQIDReplacements); diff --git a/application/helpers/export_helper.php b/application/helpers/export_helper.php index 46de9c03639..c672dedaab1 100644 --- a/application/helpers/export_helper.php +++ b/application/helpers/export_helper.php @@ -744,6 +744,12 @@ function surveyGetXMLStructure($iSurveyID, $xmlwriter, $exclude=array()) WHERE sid={$iSurveyID}"; buildXMLFromQuery($xmlwriter,$slsquery); + // Survey plugin(s) + $slsquery = " SELECT settings.id,name,".Yii::app()->db->quoteColumnName("key").",".Yii::app()->db->quoteColumnName("value") + . " FROM {{plugin_settings}} as settings JOIN {{plugins}} as plugins ON plugins.id = settings.plugin_id" + . " WHERE model='Survey' and model_id=$iSurveyID"; + buildXMLFromQuery($xmlwriter,$slsquery); + } /** diff --git a/application/models/PluginSetting.php b/application/models/PluginSetting.php index a4da7133aa2..a9c776c5d18 100644 --- a/application/models/PluginSetting.php +++ b/application/models/PluginSetting.php @@ -14,8 +14,16 @@ */ /** - * This is the model class for table "{{plugin_settings}}". + * Class PluginSetting + * + * @property integer $id primary key + * @property integer $plugin_id see \Plugin + * @property string $model + * @property integer $model_id + * @property string $key + * @property string $value */ + class PluginSetting extends CActiveRecord { /** @@ -25,8 +33,28 @@ class PluginSetting extends CActiveRecord { public static function model($className = __CLASS__) { return parent::model($className); } - + + /** + * Returns the table's name + * + * @access public + * @return string + */ public function tableName() { return '{{plugin_settings}}'; } -} \ No newline at end of file + + /** + * Returns the validation rules for attributes. + * @return array[] + */ + public function rules() { + return array( + array('plugin_id','numerical', 'integerOnly'=>true), // 'allowEmpty'=>false ? + array('model','string', 'max'=>255,'allowEmpty'=>true), + array('model_id','numerical', 'integerOnly'=>true,'allowEmpty'=>true), + array('key','string', 'max'=>255), + array('value','string'), + ); + } +} diff --git a/application/views/admin/survey/importSurvey_view.php b/application/views/admin/survey/importSurvey_view.php index 9060ceb85ec..c05df5f125f 100644 --- a/application/views/admin/survey/importSurvey_view.php +++ b/application/views/admin/survey/importSurvey_view.php @@ -92,6 +92,9 @@ : + + +