Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training module: Use validator for more inputs #1110

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/modules/training/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Config extends \Ilch\Config\Install
{
public array $config = [
'key' => 'training',
'version' => '1.9.1',
'version' => '1.9.2',
'icon_small' => 'fa-solid fa-graduation-cap',
'author' => 'Veldscholten, Kevin',
'link' => 'https://ilch.de',
Expand Down
17 changes: 14 additions & 3 deletions application/modules/training/controllers/admin/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,22 @@ public function treatAction()
if ($this->getRequest()->isPost()) {
$rules = [
'title' => 'required',
'contact' => 'required',
'contact' => 'required|integer|min:1|exists:users,id,id,' . $this->getRequest()->getPost('contact'),
'voiceServer' => 'required|integer|min:0|max:1',
'gameServer' => 'required|integer|min:0|max:1',
'groups' => 'required',
'time' => 'required|integer'
'time' => 'required|integer',
'calendarShow' => 'required|integer|min:0|max:1',
];

// Require atleast the address of the voice or gameserver if enabled.
if ($this->getRequest()->getPost('voiceServer')) {
$rules['voiceServerIP'] = 'required';
}
if ($this->getRequest()->getPost('gameServer')) {
$rules['gameServerIP'] = 'required';
}

$validation = Validation::create($this->getRequest()->getPost(), $rules);
if ($validation->isValid()) {
$model->setTitle($this->getRequest()->getPost('title'))
Expand Down Expand Up @@ -119,7 +130,7 @@ public function treatAction()
$this->redirect()
->withInput()
->withErrors($validation->getErrorBag())
->to(['action' => 'index']);
->to(($this->getRequest()->getParam('id')) ? ['action' => 'treat', 'id' => $this->getRequest()->getParam('id')] : ['action' => 'treat']);
}

if ($trainingMapper->existsTable('calendar')) {
Expand Down
26 changes: 13 additions & 13 deletions application/modules/training/views/admin/index/treat.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class="form-control"
value="<?=$this->escape($this->originalInput('title', $training->getTitle())) ?>" />
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('date') ? ' has-error' : '' ?>">
<label for="date" class="col-md-2 col-form-label">
<?=$this->getTrans('dateTime') ?>:
</label>
Expand All @@ -50,7 +50,7 @@ class="form-control"
</span>
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('time') ? ' has-error' : '' ?>">
<label for="time" class="col-xl-2 col-form-label">
<?=$this->getTrans('time') ?>:
</label>
Expand All @@ -63,7 +63,7 @@ class="form-control"
value="<?=$this->escape($this->originalInput('time', $training->getTime())) ?>">
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('place') ? ' has-error' : '' ?>">
<label for="place" class="col-xl-2 col-form-label">
<?=$this->getTrans('place') ?>:
</label>
Expand All @@ -75,7 +75,7 @@ class="form-control"
value="<?=$this->escape($this->originalInput('place', $training->getPlace())) ?>" />
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('contact') ? ' has-error' : '' ?>">
<label for="contact" class="col-xl-2 col-form-label">
<?=$this->getTrans('contactPerson') ?>:
</label>
Expand All @@ -93,7 +93,7 @@ class="form-control"
</select>
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('voiceServer') ? ' has-error' : '' ?>">
<label for="voiceServer" class="col-xl-2 col-form-label">
<?=$this->getTrans('voiceServer') ?>:
</label>
Expand All @@ -115,7 +115,7 @@ class="form-control"
}
?>
<div id="voiceServerInfo" <?=$voiceDisplay ?>>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('voiceServerIP') ? ' has-error' : '' ?>">
<label for="voiceServerIP" class="col-xl-2 col-form-label">
<?=$this->getTrans('voiceServerIP') ?>:
</label>
Expand All @@ -128,7 +128,7 @@ class="form-control"
value="<?=$this->escape($this->originalInput('voiceServerIP', $training->getVoiceServerIP())) ?>" />
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('voiceServerPW') ? ' has-error' : '' ?>">
<label for="voiceServerPW" class="col-xl-2 col-form-label">
<?=$this->getTrans('voiceServerPW') ?>:
</label>
Expand All @@ -142,7 +142,7 @@ class="form-control"
</div>
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('gameServer') ? ' has-error' : '' ?>">
<label for="gameServer" class="col-xl-2 col-form-label">
<?=$this->getTrans('gameServer') ?>:
</label>
Expand All @@ -164,7 +164,7 @@ class="form-control"
}
?>
<div id="gameServerInfo" <?=$gameDisplay ?>>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('gameServerIP') ? ' has-error' : '' ?>">
<label for="gameServerIP" class="col-xl-2 col-form-label">
<?=$this->getTrans('gameServerIP') ?>:
</label>
Expand All @@ -177,7 +177,7 @@ class="form-control"
value="<?=$this->escape($this->originalInput('gameServerIP', $training->getGameServerIP())) ?>" />
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('gameServerPW') ? ' has-error' : '' ?>">
<label for="gameServerPW" class="col-xl-2 col-form-label">
<?=$this->getTrans('gameServerPW') ?>:
</label>
Expand All @@ -191,7 +191,7 @@ class="form-control"
</div>
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('text') ? ' has-error' : '' ?>">
<label for="ck_1" class="col-xl-2 col-form-label">
<?=$this->getTrans('otherInfo') ?>:
</label>
Expand All @@ -203,7 +203,7 @@ class="form-control"
rows="5"><?=$this->escape($this->originalInput('text', $training->getText())) ?></textarea>
</div>
</div>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('access') ? ' has-error' : '' ?>">
<label for="access" class="col-xl-2 col-form-label">
<?=$this->getTrans('visibleFor') ?>
</label>
Expand All @@ -218,7 +218,7 @@ class="form-control"
</div>
</div>
<?php if ($this->get('calendarShow')) : ?>
<div class="row mb-3<?=$this->validation()->hasError('title') ? ' has-error' : '' ?>">
<div class="row mb-3<?=$this->validation()->hasError('calendarShow') ? ' has-error' : '' ?>">
<label for="calendarShow" class="col-xl-2 col-form-label">
<?=$this->getTrans('calendarShow') ?>
</label>
Expand Down