Skip to content

Commit

Permalink
Fixed issue #18473: Survey listing - multiple call of SurveyGroup (#3787
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Shnoulle committed Apr 16, 2024
1 parent db9d752 commit 16c8acb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions application/models/SurveysGroupsettings.php
Expand Up @@ -74,12 +74,12 @@ class SurveysGroupsettings extends LSActiveRecord
public $active;
public $additional_languages;

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

/**
* @return string the associated database table name
*/


public function tableName()
{
return '{{surveys_groupsettings}}';
Expand Down Expand Up @@ -112,6 +112,15 @@ 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 +301,24 @@ 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 16c8acb

Please sign in to comment.