Commit 22532a1a authored by Tino Goratsch's avatar Tino Goratsch

minor improvements

parent 758b8a7d
......@@ -33,9 +33,8 @@
{/if}
</div>
<div id="tab-2" class="tab-pane fade">
{$i=1}
{foreach $modules as $module => $values}
{if $i % 2 !== 0}
{if $values@iteration % 2 !== 0}
<div class="row">
{/if}
<fieldset class="col-sm-6">
......@@ -60,10 +59,9 @@
</div>
{/foreach}
</fieldset>
{if $i % 2 === 0 || count($modules) === $i}
{if $values@iteration % 2 === 0 || $values@last}
</div>
{/if}
{$i=$i+1}
{/foreach}
</div>
</div>
......
......@@ -60,8 +60,8 @@ class Index extends Core\Modules\AdminController
$answers = $this->addNewAnswer($this->request->getPost()->get('answers', []));
} else {
$answers = [
['number' => 0, 'value' => ''],
['number' => 1, 'value' => '']
['text' => ''],
['text' => '']
];
}
......@@ -124,12 +124,6 @@ class Index extends Core\Modules\AdminController
$answers = $this->addNewAnswer($this->request->getPost()->get('answers', []));
} else {
$answers = $this->pollsModel->getAnswersByPollId($id);
$c_answers = count($answers);
for ($i = 0; $i < $c_answers; ++$i) {
$answers[$i]['number'] = $i;
$answers[$i]['value'] = $answers[$i]['text'];
}
}
$this->view->assign('answers', $answers);
......@@ -247,18 +241,16 @@ class Index extends Core\Modules\AdminController
// Bisherige Antworten
$i = 0;
foreach ($currentAnswers as $row) {
$answers[$i]['number'] = $i;
if (isset($row['id'])) {
$answers[$i]['id'] = $row['id'];
}
$answers[$i]['value'] = $row['value'];
$answers[$i]['text'] = $row['text'];
++$i;
}
// Neue Antwort nur hinzufügen, wenn die vorangegangene nicht leer ist
if (!empty($currentAnswers[$i - 1]['value'])) {
$answers[$i]['number'] = $i;
$answers[$i]['value'] = '';
if (!empty($currentAnswers[$i - 1]['text'])) {
$answers[$i]['text'] = '';
}
return $answers;
......@@ -277,18 +269,18 @@ class Index extends Core\Modules\AdminController
// Neue Antwort hinzufügen
if (empty($row['id'])) {
// Neue Antwort nur hinzufügen, wenn die Löschen-Checkbox nicht gesetzt wurde
if (!empty($row['value']) && !isset($row['delete'])) {
if (!empty($row['text']) && !isset($row['delete'])) {
$bool = $this->pollsModel->insert(
['text' => Core\Functions::strEncode($row['value']), 'poll_id' => $id],
['text' => Core\Functions::strEncode($row['text']), 'poll_id' => $id],
Polls\Model::TABLE_NAME_ANSWERS
);
}
} elseif (isset($row['delete'])) { // Antwort mitsamt Stimmen löschen
$this->pollsModel->delete((int) $row['id'], '', Polls\Model::TABLE_NAME_ANSWERS);
$this->pollsModel->delete((int) $row['id'], 'answer_id', Polls\Model::TABLE_NAME_VOTES);
} elseif (!empty($row['value'])) { // Antwort aktualisieren
} elseif (!empty($row['text'])) { // Antwort aktualisieren
$bool = $this->pollsModel->update(
['text' => Core\Functions::strEncode($row['value'])],
['text' => Core\Functions::strEncode($row['text'])],
(int) $row['id'],
Polls\Model::TABLE_NAME_ANSWERS
);
......
......@@ -24,19 +24,19 @@
</div>
{foreach $answers as $row}
<div class="form-group">
<label for="answer-{$row.number}" class="col-sm-2 control-label">{lang t="polls|answer"} {$row.number+1}</label>
<label for="answer-{$row@index}" class="col-sm-2 control-label">{lang t="polls|answer"} {$row@index+1}</label>
<div class="col-sm-10">
{if isset($row.id)}
<div class="input-group">
<input class="form-control" type="text" name="answers[{$row.number}][value]" id="answer-{$row.number}" value="{$row.value}" maxlength="120">
<input class="form-control" type="text" name="answers[{$row@index}][text]" id="answer-{$row@index}" value="{$row.text}" maxlength="120">
<div class="input-group-addon">
<input type="checkbox" name="answers[{$row.number}][delete]" value="1">
<input type="checkbox" name="answers[{$row@index}][delete]" value="1">
</div>
</div>
<input type="hidden" name="answers[{$row.number}][id]" value="{$row.id}" style="display:none">
<input type="hidden" name="answers[{$row@index}][id]" value="{$row.id}" style="display:none">
{else}
<input class="form-control" type="text" name="answers[{$row.number}][value]" id="answer-{$row.number}" value="{$row.value}" maxlength="120">
<input class="form-control" type="text" name="answers[{$row@index}][text]" id="answer-{$row@index}" value="{$row.text}" maxlength="120">
{/if}
</div>
</div>
......
......@@ -68,7 +68,7 @@ class Validator extends Core\Validator\AbstractValidator
$markedAnswers = 0;
$notEmptyAnswers = 0;
foreach ($formData['answers'] as $row) {
if (!empty($row['value'])) {
if (!empty($row['text'])) {
++$notEmptyAnswers;
}
if (isset($row['delete'])) {
......
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