Skip to content

Commit

Permalink
Dev: value is not part of definition : this reset value come from DB …
Browse files Browse the repository at this point in the history
…when update template

Dev: really allow question template to update partially core attribute
  • Loading branch information
Shnoulle committed Oct 28, 2018
1 parent 3b6d830 commit 38c1b67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 10 additions & 2 deletions application/controllers/admin/database.php
Expand Up @@ -547,8 +547,16 @@ private function actionUpdateQuestion($iSurveyID)
} else {
$sQuestionType = Yii::app()->request->getPost('type');
}


/* Set 'question_template' to current one before al other action : QuestionTemplate use cirrent one only*/
$question_template = Yii::app()->request->getPost("question_template", "core");
QuestionAttribute::model()->deleteAll("attribute = :attribute",array(":attribute" => "question_template"));
if($question_template != "core") {
$attribute = new QuestionAttribute;
$attribute->qid = $this->iQuestionID;
$attribute->value = $question_template;
$attribute->attribute = "question_template";
$attribute->save();
}
// Remove invalid question attributes on saving
$criteria = new CDbCriteria;
$criteria->compare('qid', $this->iQuestionID);
Expand Down
6 changes: 4 additions & 2 deletions application/controllers/admin/questions.php
Expand Up @@ -1671,7 +1671,6 @@ public function ajaxquestionattributes()
);
$aAttributesWithValues = Question::model()->getAdvancedSettingsWithValues($qid, $type, $surveyid);


// INSERTING CUSTOM ATTRIBUTES FROM CORE QUESTION THEME XML FILE
$currentAttributesDefinition = \LimeSurvey\Helpers\questionHelper::getQuestionAttributesSettings($type);
if (!empty($sQuestionTemplate) && $sQuestionTemplate !== 'core') {
Expand All @@ -1686,7 +1685,10 @@ public function ajaxquestionattributes()
if (!empty($aOldQuestionThemeAttributes)){
foreach ($aOldQuestionThemeAttributes as $key => $value) {
if(array_key_exists($value['name'],$currentAttributesDefinition)) {
$aAttributesWithValues[$value['name']] = array_merge($aAttributesWithValues[$value['name']],$currentAttributesDefinition[$value['name']]);
$aAttributesWithValues[$value['name']] = array_merge(
$aAttributesWithValues[$value['name']],
$currentAttributesDefinition[$value['name']]
);
} else {
unset($aAttributesWithValues[$value['name']]);
}
Expand Down
1 change: 0 additions & 1 deletion application/models/QuestionAttribute.php
Expand Up @@ -307,7 +307,6 @@ public static function getDefaultSettings()
"category" => gT("Attribute"),
"default" => '',
"help" => '',
"value" => '',
"sortorder" => 1000,
"i18n" => false,
"readonly" => false,
Expand Down

0 comments on commit 38c1b67

Please sign in to comment.