Commit 68455fb1 authored by Chenu Denis's avatar Chenu Denis
Browse files

[fix] MsSQL issue with token update and create

[fix] Leave No data for template
parent 5e2847cf
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2020-2021 Denis Chenu <http://www.sondages.pro>
* @license GPL v3
* @version 0.16.0
* @version 0.16.1
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
......@@ -1057,7 +1057,7 @@ class TokenUsersListAndManage extends PluginBase
$aSettings[$this->translate('Childs token attribute update')]['tokenAttributeSetChildrensAction'] = array(
'type' => 'info',
'content' => '<div class="col-md-6 col-md-offset-6">'
. '<p class="text-warning"><strong>' . $this->translate("Warning") . '</stong> ' . $this->translate('This update child survey and can delete attribute information and token') . '</p>'
. '<p class="text-warning"><strong>' . $this->translate("Warning") . '</strong> ' . $this->translate('This update child survey and can delete attribute information and token') . '</p>'
. '<button type="submit" name="saveTokenUsersListAndManage" value="tokenAttributeSetChildrensAction" class="btn btn-default"><i class="fa fa-check-circle-o " aria-hidden="true"></i>'
. $this->translate("Save and set attributes to child survey")
. '</button>'
......@@ -1355,9 +1355,10 @@ class TokenUsersListAndManage extends PluginBase
* @param integer $surveyId
* @param integer $childSurveyId
* @param string $action in ['settings','attributes','tokens']
* @param boolean $createtable
* @return void
*/
private function setChildrenAction($surveyId, $childSurveyId, $action)
private function setChildrenAction($surveyId, $childSurveyId, $action, $createtable = true)
{
if (!in_array($action,['settings','attributes','tokens'])) {
throw new CHttpException(400, $this->translate("Invalid action on children"));
......@@ -1391,36 +1392,53 @@ class TokenUsersListAndManage extends PluginBase
'Survey',
$childSurveyId
);
/* */
if($action == 'attributes' || $action == 'tokens') {
if (Survey::model()->findByPk($surveyId)->hasTokensTable) {
if (Survey::model()->findByPk($childSurveyId)->hasTokensTable) {
$surveyTokenAttributes = Token::model($surveyId)->getAttributes();
$childTokenAttributes = Token::model($childSurveyId)->getAttributes();
$sTableName = "{{tokens_{$childSurveyId}}}";
$newAttributes = array_diff_key($surveyTokenAttributes, $childTokenAttributes);
$oldAttributes = array_diff_key($childTokenAttributes, $surveyTokenAttributes);
foreach ($newAttributes as $attribute => $value) {
App()->db->createCommand(App()->db->getSchema()->addColumn($sTableName, $attribute, 'text'))->execute();
}
foreach ($oldAttributes as $attribute => $value) {
App()->db->createCommand(App()->db->getSchema()->dropColumn($sTableName, $attribute))->execute();
}
}
}
Survey::model()->updateByPk(
$childSurveyId,
array(
'attributedescriptions' => Survey::model()->findByPk($surveyId)->getAttribute('attributedescriptions')
)
);
if (Survey::model()->findByPk($surveyId)->hasTokensTable) {
if (!Survey::model()->findByPk($childSurveyId)->hasTokensTable) {
if (!$createtable) {
return;
}
Token::createTable($childSurveyId);
App()->db->getSchema()->getTable("{{tokens_$childSurveyId}}", true);
}
$surveyTokenAttributes = Token::model($surveyId)->getAttributes();
$childTokenAttributes = Token::model($childSurveyId)->getAttributes();
$sTableName = "{{tokens_{$childSurveyId}}}";
$newAttributes = array_diff_key($surveyTokenAttributes, $childTokenAttributes);
$oldAttributes = array_diff_key($childTokenAttributes, $surveyTokenAttributes);
foreach ($newAttributes as $attribute => $value) {
App()->db->createCommand(App()->db->getSchema()->addColumn($sTableName, $attribute, 'text'))->execute();
}
foreach ($oldAttributes as $attribute => $value) {
App()->db->createCommand(App()->db->getSchema()->dropColumn($sTableName, $attribute))->execute();
}
App()->db->getSchema()->getTable("{{tokens_$childSurveyId}}", true);
}
}
if (!Survey::model()->findByPk($surveyId)->hasTokensTable) {
return;
}
if($action == 'tokens') {
Token::model($childSurveyId)->deleteAll();
$parentTable = "{{tokens_{$surveyId}}}";
$chieldTable = "{{tokens_{$childSurveyId}}}";
$surveyTokenAttributes = array_map(
function( $attribute ) {
return App()->db->quoteColumnName($attribute);
},
array_keys(Token::model($surveyId)->getAttributes())
);
$columnsToInsert = implode(',',$surveyTokenAttributes);
switchMSSQLIdentityInsert("tokens_{$childSurveyId}", true);
App()->db->createCommand("INSERT $chieldTable SELECT * FROM $parentTable WHERE 1")->execute();
App()->db->createCommand("INSERT INTO $chieldTable ({$columnsToInsert}) SELECT * FROM $parentTable WHERE tid > 0")->execute();
switchMSSQLIdentityInsert("tokens_{$childSurveyId}", false);
App()->db->schema->getTable($chieldTable, true);
}
......
......@@ -1401,13 +1401,12 @@ class TokenUsersManager
$oSurvey = Survey::model()->active()->with('languagesettings')->findByPk($childSurveyId);
if($oSurvey && Utilities::getSetting($childSurveyId, 'useAttributeRestricted')) {
$responseList = $this->getResponseList($childSurveyId, $managerToken);
if(!empty($responseList)) {
$aRestrictedSurveys[$childSurveyId] = array(
'title' => $oSurvey->getLocalizedTitle(),
'responses' => $responseList,
'access' => $this->getAccesList($childSurveyId, $usertoken)
);
}
$aRestrictedSurveys[$childSurveyId] = array(
'title' => $oSurvey->getLocalizedTitle(),
'responses' => $responseList,
'access' => $this->getAccesList($childSurveyId, $usertoken)
);
$this->language['No response'] = self::translate("No response");
}
}
$aTokenUsersAttributes[$key]["tokenAttributeRestrictedSurveys"] = $aRestrictedSurveys;
......
......@@ -47,7 +47,7 @@
})
) }}
{% else %}
<div>No data in survey</div>
<div class="form-control-static">{{ language['No response'] }}</div>
{% endif %}
</li>
{% endfor %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment