Skip to content

Commit

Permalink
Fixed issue #18473: Survey listing : multiple call of SurveyGroup (#3737
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Shnoulle committed Feb 22, 2024
1 parent 19bffea commit 7406e0a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions application/models/SurveysGroupsettings.php
Expand Up @@ -74,6 +74,8 @@ class SurveysGroupsettings extends LSActiveRecord
public $active;
public $additional_languages;

/* self[] used in self::getInstance() */
private static $aSurveysGroupSettings = [];

/**
* @return string the associated database table name
Expand Down Expand Up @@ -112,6 +114,14 @@ public function rules()
);
}

/** @inheritdoc
* unset static aSurveysGroupSettings
**/
public function save($runValidation = true, $attributes = null)
{
unset(self::$aSurveysGroupSettings[$this->gsid]);
parent::save($runValidation, $attributes);
}
/**
* @return array relational rules.
*/
Expand Down Expand Up @@ -292,21 +302,23 @@ public function getIsAnonymized()
* It steps up (see param $iStep) until it has found the real settings ...
*
* @param int $iSurveyGroupId
* @param null $oSurvey
* @param null $instance
* @param \Survey|null $oSurvey
* @param \self|null $instance
* @param int $iStep this is inheritance step (recursive step) (parent, parentParent, parentParentParent ?)
* @param bool $bRealValues
* @return SurveysGroupsettings instance
*/
public static function getInstance($iSurveyGroupId = 0, $oSurvey = null, $instance = null, $iStep = 1, $bRealValues = false)
{

if ($iSurveyGroupId > 0) {
$model = SurveysGroupsettings::model()->with('SurveysGroups')->findByPk($iSurveyGroupId);
} else {
//this is the default group setting with gsid=0 !!!
$model = SurveysGroupsettings::model()->findByPk($iSurveyGroupId);
if (!array_key_exists($iSurveyGroupId, self::$aSurveysGroupSettings)) {
if ($iSurveyGroupId > 0) {
self::$aSurveysGroupSettings[$iSurveyGroupId] = SurveysGroupsettings::model()->with('SurveysGroups')->findByPk($iSurveyGroupId);
} else {
//this is the default group setting with gsid=0 !!!
self::$aSurveysGroupSettings[$iSurveyGroupId] = SurveysGroupsettings::model()->findByPk($iSurveyGroupId);
}
}
$model = self::$aSurveysGroupSettings[$iSurveyGroupId];

// set initial values to instance on first run
if ($instance === null) {
Expand Down

0 comments on commit 7406e0a

Please sign in to comment.