Skip to content

Commit

Permalink
Fixed issue: some question general settings are wrongly set to disabl…
Browse files Browse the repository at this point in the history
…ed when the survey was not active
  • Loading branch information
ptelu committed May 11, 2021
1 parent a9dcf34 commit 91df10f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
13 changes: 11 additions & 2 deletions application/datavalueobjects/GeneralOption.php
Expand Up @@ -2,6 +2,8 @@

namespace LimeSurvey\Datavalueobjects;

use Survey;

/**
* Wrapper class for question general option.
*/
Expand All @@ -19,9 +21,12 @@ class GeneralOption
/** @var FormElement */
public $formElement;

/** @var bool */
/** @var bool If the Option should be disabled when the survey is active*/
public $disableInActive = false;

/** @var bool If the Option should be disabled*/
public $disabled = false;

public function __construct(
$name,
$title,
Expand All @@ -35,10 +40,14 @@ public function __construct(
}

/**
* @param Survey $survey
* @return void
*/
public function setDisableInActive()
public function setDisableInActive(Survey $survey)
{
$this->disableInActive = true;
if ($survey->active === 'Y') {
$this->disabled = true;
}
}
}
Expand Up @@ -27,6 +27,6 @@ public function __construct(Question $question)
]
]
);
$this->setDisableInActive();
$this->setDisableInActive($question->survey);
}
}
Expand Up @@ -15,7 +15,7 @@ public function __construct(Question $question, array $groupOptions)
$this->name = 'gid';
$this->title = gT('Question group');
$this->inputType = 'questiongroup';
$this->disableInActive = true;
$this->setDisableInActive($question->survey);
$this->formElement = new FormElement(
'gid',
null,
Expand Down
Expand Up @@ -14,7 +14,7 @@ public function __construct(Question $question)
$this->name = 'other';
$this->title = gT('Other');
$this->inputType = 'switch';
$this->disableInActive = true;
$this->setDisableInActive($question->survey);
$this->formElement = new FormElement(
'other',
null,
Expand Down
Expand Up @@ -14,7 +14,7 @@ public function __construct(Question $question)
$this->name = 'save_as_default';
$this->title = gT('Save as default values');
$this->inputType = 'switch';
$this->disableInActive = true;
$this->setDisableInActive($question->survey);
$this->formElement = new FormElement(
'save_as_default',
null,
Expand Down
@@ -1,14 +1,15 @@
<select
<select
class="form-control"
name="question[<?= $this->generalOption->name; ?>]"
id="<?= $this->generalOption->name; ?>"
name="question[<?= $this->generalOption->name ?>]"
id="<?= $this->generalOption->name ?>"
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
>
<!-- TODO: Fix weird object reference. -->
<?php foreach ($this->generalOption->formElement->options['options'] as $option) : ?>
<?php if ($this->generalOption->formElement->value == $option->value) : ?>
<option value="<?= $option->value; ?>" selected="selected"><?= $option->text; ?></option>
<option value="<?= $option->value ?>" selected="selected"><?= $option->text ?></option>
<?php else : ?>
<option value="<?= $option->value; ?>"><?= $option->text; ?></option>
<option value="<?= $option->value ?>"><?= $option->text ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
30 changes: 17 additions & 13 deletions application/extensions/GeneralOptionWidget/views/switch.php
@@ -1,39 +1,43 @@
<div class="btn-group col-12" role="group" data-toggle="buttons">
<?php if ($this->generalOption->formElement->value == 'Y') : ?>
<label class="btn btn-default active">
<?php if ($this->generalOption->formElement->value === 'Y') : ?>
<label class="btn btn-default active <?= $this->generalOption->disabled ? 'disabled' : '' ?>">
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
name="question[<?= $this->generalOption->name ?>]"
value="Y"
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
checked
/>
<?= gT('On'); ?>
<?= gT('On') ?>
</label>
<label class="btn btn-default">
<label class="btn btn-default <?= $this->generalOption->disabled ? 'disabled' : '' ?>">
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
name="question[<?= $this->generalOption->name ?>]"
value="N"
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
/>
<?= gT('Off'); ?>
<?= gT('Off') ?>
</label>
<?php else : ?>
<label class="btn btn-default">
<label class="btn btn-default <?= $this->generalOption->disabled ? 'disabled' : '' ?>">
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
name="question[<?= $this->generalOption->name ?>]"
value="Y"
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
/>
<?= gT('On'); ?>
<?= gT('On') ?>
</label>
<label class="btn btn-default active">
<label class="btn btn-default active <?= $this->generalOption->disabled ? 'disabled' : '' ?>">
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
name="question[<?= $this->generalOption->name ?>]"
value="N"
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
checked
/>
<?= gT('Off'); ?>
<?= gT('Off') ?>
</label>
<?php endif; ?>
</div>

0 comments on commit 91df10f

Please sign in to comment.