Fixed expiry date edition

This commit is contained in:
Olivier Perez 2016-06-30 20:48:30 +02:00
parent d3db76ccd7
commit fa5014de32
No known key found for this signature in database
GPG Key ID: 3AA3C84A71F35E71
3 changed files with 10 additions and 4 deletions

View File

@ -122,8 +122,7 @@ if (isset($_POST['update_poll_info'])) {
break; break;
} }
} elseif ($field == 'expiration_date') { } elseif ($field == 'expiration_date') {
$expiration_date = filter_input(INPUT_POST, 'expiration_date', FILTER_VALIDATE_REGEXP, $expiration_date = $inputService->filterDate($_POST['expiration_date']);
['options' => ['regexp' => '#^[0-9]{4}-[0-9]{2}-[0-9]{2}$#']]);
if ($expiration_date) { if ($expiration_date) {
$poll->end_date = $expiration_date; $poll->end_date = $expiration_date;
$updated = true; $updated = true;

View File

@ -4,6 +4,7 @@ namespace Framadate\Services;
use Framadate\Exception\MomentAlreadyExistsException; use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\FramaDB; use Framadate\FramaDB;
use Framadate\Repositories\RepositoryFactory; use Framadate\Repositories\RepositoryFactory;
use Framadate\Utils;
/** /**
* Class AdminPollService * Class AdminPollService
@ -33,7 +34,7 @@ class AdminPollService {
function updatePoll($poll) { function updatePoll($poll) {
global $config; global $config;
if ($poll->end_date > $poll->creation_date && $poll->end_date <= strtotime($poll->creation_date) + (86400 * $config['default_poll_duration'])) { if ($poll->end_date > $poll->creation_date) {
return $this->pollRepository->update($poll); return $this->pollRepository->update($poll);
} else { } else {
return false; return false;

View File

@ -17,6 +17,7 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/ */
namespace Framadate\Services; namespace Framadate\Services;
use DateTime;
/** /**
* This class helps to clean all inputs from the users or external services. * This class helps to clean all inputs from the users or external services.
@ -90,6 +91,11 @@ class InputService {
return $this->returnIfNotBlank($comment); return $this->returnIfNotBlank($comment);
} }
public function filterDate($date) {
$dDate = DateTime::createFromFormat(__('Date', 'datetime_parseformat'), $date)->setTime(0, 0, 0);
return $dDate->format('Y-m-d H:i:s');
}
/** /**
* Return the value if it's not blank. * Return the value if it's not blank.
* *
@ -107,4 +113,4 @@ class InputService {
return null; return null;
} }
} }