Skip to content

Commit

Permalink
Fix end time and date validations
Browse files Browse the repository at this point in the history
  • Loading branch information
catdesu committed May 6, 2024
1 parent b41008e commit b6bdd02
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions orif/timbreuse/Language/fr/tim_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@
'btn_hard_delete_user' => 'Supprimer définitivement cet utilisateur',
'siteAccountNotLinked' => 'Ce compte utilisateur de la timbreuse n\'est pas lié à un compte de l\'application web.',
'fillFieldsToCreateAccount' => 'Complétez les champs ci-dessous et enregistrez pour lui créer un compte dans l\'application.',
'msg_err_end_time_greater_than' => 'L\'heure de fin doit être supérieur à l\'heure de début.',
'msg_err_end_date_greater_than' => 'La date de fin doit être supérieur à la date de début.',
];
8 changes: 6 additions & 2 deletions orif/timbreuse/Models/EventPlanningsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
'end_time' =>
[
'label' => lang('tim_lang.field_event_end_time'),
'rules' => 'required|valid_date'
'rules' => 'required|valid_date|cb_date_time_greater_than[start_time]'
],
'is_work_time' =>
[
Expand All @@ -80,7 +80,11 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
],
];

$this->validationMessages = [];
$this->validationMessages = [
'end_time' => [
'cb_date_time_greater_than' => lang('tim_lang.msg_err_end_time_greater_than')
]
];

parent::__construct($db, $validation);
}
Expand Down
8 changes: 6 additions & 2 deletions orif/timbreuse/Models/EventSeriesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
'end_date' =>
[
'label' => lang('tim_lang.field_end_date'),
'rules' => 'required|valid_date'
'rules' => 'required|valid_date|cb_date_time_greater_than[start_date]'
],
'recurrence_frequency' =>
[
Expand All @@ -62,7 +62,11 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
],
];

$this->validationMessages = [];
$this->validationMessages = [
'end_date' => [
'cb_date_time_greater_than' => lang('tim_lang.msg_err_end_date_greater_than')
]
];

parent::__construct($db, $validation);
}
Expand Down
14 changes: 14 additions & 0 deletions orif/timbreuse/Validation/TimbreuseRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,19 @@ public function cb_valid_array($array) : bool {
public function cb_array_not_empty($array) : bool {
return count($array) > 0;
}

/**
* Compares two date-time values to check if the end date-time is greater than the start date-time.
*
* @param mixed $endTime
* @param mixed $fieldToCompare
* @param mixed $values
* @return bool
*/
public function cb_date_time_greater_than($end, $fieldToCompare, $values) : bool {
$start = strtotime($values[$fieldToCompare]);
$end = strtotime($end);

return $start < $end;
}
}
1 change: 1 addition & 0 deletions orif/timbreuse/Views/eventPlannings/group/save_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<?= form_input('', $userGroup['name'] ?? '', [
'class' => 'form-control', 'id' => 'linked_user_group', 'disabled' => ''
]); ?>
<span class="text-danger"><?= isset($errors['fk_user_group_id']) ? esc($errors['fk_user_group_id']) : ''; ?></span>
<?= form_submit('select_user_group', lang('tim_lang.select_user_group'), ['class' => 'mt-3 w-100 btn btn-secondary']); ?>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion orif/timbreuse/Views/eventPlannings/personal/save_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<?= form_input('', !is_null($user) ? "{$user['name']} {$user['surname']}" : '', [
'class' => 'form-control', 'id' => 'linked_user', 'disabled' => ''
]); ?>
<span class="text-danger"><?= isset($errors['end_time']) ? esc($errors['end_time']) : ''; ?></span>
<span class="text-danger"><?= isset($errors['fk_user_sync_id']) ? esc($errors['fk_user_sync_id']) : ''; ?></span>
<?php if (url_is('*admin*')) : ?>
<?= form_submit('select_linked_user', lang('tim_lang.btn_select_linked_user'), ['class' => 'mt-3 w-100 btn btn-secondary']); ?>
<?php endif; ?>
Expand Down

0 comments on commit b6bdd02

Please sign in to comment.