Merge branch 'olivierperez/framadate-fix/Error_message_when_delete_column'

Conflicts:
	locale/it.json
This commit is contained in:
Antonin 2015-11-05 22:30:10 +01:00
commit af175e40d7
8 changed files with 39 additions and 35 deletions

View File

@ -17,6 +17,7 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/ */
use Framadate\Editable; use Framadate\Editable;
use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\Message; use Framadate\Message;
use Framadate\Services\AdminPollService; use Framadate\Services\AdminPollService;
use Framadate\Services\InputService; use Framadate\Services\InputService;
@ -393,21 +394,21 @@ if (isset($_GET['add_slot'])) {
exit; exit;
} }
if (isset($_POST['confirm_add_slot'])) { if (isset($_POST['confirm_add_slot'])) {
if ($poll->format === 'D') { try {
$newdate = strip_tags($_POST['newdate']); if ($poll->format === 'D') {
$newmoment = str_replace(',', '-', strip_tags($_POST['newmoment'])); $newdate = strip_tags($_POST['newdate']);
$newmoment = str_replace(',', '-', strip_tags($_POST['newmoment']));
$ex = explode('/', $newdate); $ex = explode('/', $newdate);
$result = $adminPollService->addDateSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment); $adminPollService->addDateSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment);
} else { } else {
$newslot = str_replace(',', '-', strip_tags($_POST['choice'])); $newslot = str_replace(',', '-', strip_tags($_POST['choice']));
$result = $adminPollService->addClassicSlot($poll_id, $newslot); $adminPollService->addClassicSlot($poll_id, $newslot);
} }
if ($result) {
$message = new Message('success', __('adminstuds', 'Choice added')); $message = new Message('success', __('adminstuds', 'Choice added'));
} else { } catch (MomentAlreadyExistsException $e) {
$message = new Message('danger', __('Error', 'Failed to add the column')); $message = new Message('danger', __('Error', 'The column already exists'));
} }
} }

View File

@ -0,0 +1,9 @@
<?php
namespace Framadate\Exception;
class MomentAlreadyExistsException extends \Exception {
function __construct() {
}
}

View File

@ -1,6 +1,7 @@
<?php <?php
namespace Framadate\Services; namespace Framadate\Services;
use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\FramaDB; use Framadate\FramaDB;
use Framadate\Repositories\RepositoryFactory; use Framadate\Repositories\RepositoryFactory;
@ -196,7 +197,7 @@ class AdminPollService {
* @param $poll_id int The ID of the poll * @param $poll_id int The ID of the poll
* @param $datetime int The datetime * @param $datetime int The datetime
* @param $new_moment string The moment's name * @param $new_moment string The moment's name
* @return bool true if added * @throws MomentAlreadyExistsException When the moment to add already exists in database
*/ */
public function addDateSlot($poll_id, $datetime, $new_moment) { public function addDateSlot($poll_id, $datetime, $new_moment) {
$this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment); $this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment);
@ -207,16 +208,13 @@ class AdminPollService {
// Begin transaction // Begin transaction
$this->connect->beginTransaction(); $this->connect->beginTransaction();
if ($result == null) { if ($result->slot != null) {
// The moment already exists
return false;
} elseif ($result->slot != null) {
$slot = $result->slot; $slot = $result->slot;
$moments = explode(',', $slot->moments); $moments = explode(',', $slot->moments);
// Check if moment already exists (maybe not necessary) // Check if moment already exists (maybe not necessary)
if (in_array($new_moment, $moments)) { if (in_array($new_moment, $moments)) {
return false; throw new MomentAlreadyExistsException();
} }
// Update found slot // Update found slot
@ -232,8 +230,6 @@ class AdminPollService {
// Commit transaction // Commit transaction
$this->connect->commit(); $this->connect->commit();
return true;
} }
/** /**
@ -244,7 +240,7 @@ class AdminPollService {
* *
* @param $poll_id int The ID of the poll * @param $poll_id int The ID of the poll
* @param $title int The title * @param $title int The title
* @return bool true if added * @throws MomentAlreadyExistsException When the moment to add already exists in database
*/ */
public function addClassicSlot($poll_id, $title) { public function addClassicSlot($poll_id, $title) {
$this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', title:' . $title); $this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', title:' . $title);
@ -257,7 +253,7 @@ class AdminPollService {
}, $slots); }, $slots);
if (in_array($title, $titles)) { if (in_array($title, $titles)) {
// The moment already exists // The moment already exists
return false; throw new MomentAlreadyExistsException();
} }
@ -272,8 +268,6 @@ class AdminPollService {
// Commit transaction // Commit transaction
$this->connect->commit(); $this->connect->commit();
return true;
} }
/** /**
@ -283,34 +277,29 @@ class AdminPollService {
* *
* @param $slots array All the slots of the poll * @param $slots array All the slots of the poll
* @param $datetime int The datetime of the new slot * @param $datetime int The datetime of the new slot
* @return null|\stdClass An object like this one: {insert:X, slot:Y} where Y can be null. * @return \stdClass An object like this one: {insert:X, slot:Y} where Y can be null.
*/ */
private function findInsertPosition($slots, $datetime) { private function findInsertPosition($slots, $datetime) {
$result = new \stdClass(); $result = new \stdClass();
$result->slot = null; $result->slot = null;
$result->insert = -1; $result->insert = 0;
$i = 0;
foreach ($slots as $slot) { foreach ($slots as $slot) {
$rowDatetime = $slot->title; $rowDatetime = $slot->title;
$moments = explode(',', $slot->moments); $moments = explode(',', $slot->moments);
if ($datetime == $rowDatetime) { if ($datetime == $rowDatetime) {
$i += count($moments);
// Here we have to insert at the end of a slot // Here we have to insert at the end of a slot
$result->insert += count($moments);
$result->slot = $slot; $result->slot = $slot;
$result->insert = $i;
break; break;
} elseif ($datetime < $rowDatetime) { } elseif ($datetime < $rowDatetime) {
// Here we have to insert a new slot // We have to insert before this slot
break; break;
} else { } else {
$i += count($moments); $result->insert += count($moments);
} }
} }
$result->insert = $i;
return $result; return $result;
} }

View File

@ -335,7 +335,8 @@
"Comment failed": "Abgabe des Kommentars gescheitert", "Comment failed": "Abgabe des Kommentars gescheitert",
"You can't create a poll with hidden results with the following edition option:": "Sie können mit der folgenden Editier-Option keine Umfrage mit versteckten Ergebnissen erzeugen:", "You can't create a poll with hidden results with the following edition option:": "Sie können mit der folgenden Editier-Option keine Umfrage mit versteckten Ergebnissen erzeugen:",
"Failed to delete column": "Löschen der Spalte fehlgeschlagen", "Failed to delete column": "Löschen der Spalte fehlgeschlagen",
"The column already exists": "DE_La colonne existe déjà",
"MISSING_VALUES": "Fehlende Werte", "MISSING_VALUES": "Fehlende Werte",
"CANT_CONNECT_TO_DATABASE": "Kann nicht mit der Datenbank verbinden" "CANT_CONNECT_TO_DATABASE": "Kann nicht mit der Datenbank verbinden"
} }
} }

View File

@ -335,6 +335,7 @@
"Comment failed": "Comment failed", "Comment failed": "Comment failed",
"You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following option: ", "You can't create a poll with hidden results with the following edition option:": "You can't create a poll with hidden results with the following option: ",
"Failed to delete column": "Failed to delete column", "Failed to delete column": "Failed to delete column",
"The column already exists": "The column already exists",
"MISSING_VALUES": "Missing values", "MISSING_VALUES": "Missing values",
"CANT_CONNECT_TO_DATABASE": "Unable to connect to database" "CANT_CONNECT_TO_DATABASE": "Unable to connect to database"
} }

View File

@ -335,6 +335,7 @@
"Comment failed": "ES_Commentaire échoué", "Comment failed": "ES_Commentaire échoué",
"You can't create a poll with hidden results with the following edition option:": "ES_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ", "You can't create a poll with hidden results with the following edition option:": "ES_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ",
"Failed to delete column": "Error al eliminar la columna", "Failed to delete column": "Error al eliminar la columna",
"The column already exists": "ES_La colonne existe déjà",
"MISSING_VALUES": "Los valores perdidos", "MISSING_VALUES": "Los valores perdidos",
"CANT_CONNECT_TO_DATABASE": "No se puede conectar a la base de datos" "CANT_CONNECT_TO_DATABASE": "No se puede conectar a la base de datos"
} }

View File

@ -350,6 +350,7 @@
"Comment failed": "Commentaire échoué", "Comment failed": "Commentaire échoué",
"You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ", "You can't create a poll with hidden results with the following edition option:": "Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : ",
"Failed to delete column": "Échec de la suppression de colonne", "Failed to delete column": "Échec de la suppression de colonne",
"The column already exists": "La colonne existe déjà",
"MISSING_VALUES": "Il manque des valeurs", "MISSING_VALUES": "Il manque des valeurs",
"CANT_CONNECT_TO_DATABASE": "Impossible de se connecter à la base de données" "CANT_CONNECT_TO_DATABASE": "Impossible de se connecter à la base de données"
} }

View File

@ -335,6 +335,7 @@
"Comment failed": "Commento fallito", "Comment failed": "Commento fallito",
"You can't create a poll with hidden results with the following edition option:": "Non potete creare un sondaggio con i risultati nascosti con queste opzioni: : ", "You can't create a poll with hidden results with the following edition option:": "Non potete creare un sondaggio con i risultati nascosti con queste opzioni: : ",
"Failed to delete column": "Impossibile eliminare la colonna", "Failed to delete column": "Impossibile eliminare la colonna",
"The column already exists": "IT_La colonne existe déjà",
"MISSING_VALUES": "Valori mancanti", "MISSING_VALUES": "Valori mancanti",
"CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database" "CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database"
} }