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)
*/
use Framadate\Editable;
use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\Message;
use Framadate\Services\AdminPollService;
use Framadate\Services\InputService;
@ -393,21 +394,21 @@ if (isset($_GET['add_slot'])) {
exit;
}
if (isset($_POST['confirm_add_slot'])) {
if ($poll->format === 'D') {
$newdate = strip_tags($_POST['newdate']);
$newmoment = str_replace(',', '-', strip_tags($_POST['newmoment']));
try {
if ($poll->format === 'D') {
$newdate = strip_tags($_POST['newdate']);
$newmoment = str_replace(',', '-', strip_tags($_POST['newmoment']));
$ex = explode('/', $newdate);
$result = $adminPollService->addDateSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment);
} else {
$newslot = str_replace(',', '-', strip_tags($_POST['choice']));
$result = $adminPollService->addClassicSlot($poll_id, $newslot);
}
$ex = explode('/', $newdate);
$adminPollService->addDateSlot($poll_id, mktime(0, 0, 0, $ex[1], $ex[0], $ex[2]), $newmoment);
} else {
$newslot = str_replace(',', '-', strip_tags($_POST['choice']));
$adminPollService->addClassicSlot($poll_id, $newslot);
}
if ($result) {
$message = new Message('success', __('adminstuds', 'Choice added'));
} else {
$message = new Message('danger', __('Error', 'Failed to add the column'));
} catch (MomentAlreadyExistsException $e) {
$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
namespace Framadate\Services;
use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\FramaDB;
use Framadate\Repositories\RepositoryFactory;
@ -196,7 +197,7 @@ class AdminPollService {
* @param $poll_id int The ID of the poll
* @param $datetime int The datetime
* @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) {
$this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', datetime:' . $datetime . ', moment:' . $new_moment);
@ -207,16 +208,13 @@ class AdminPollService {
// Begin transaction
$this->connect->beginTransaction();
if ($result == null) {
// The moment already exists
return false;
} elseif ($result->slot != null) {
if ($result->slot != null) {
$slot = $result->slot;
$moments = explode(',', $slot->moments);
// Check if moment already exists (maybe not necessary)
if (in_array($new_moment, $moments)) {
return false;
throw new MomentAlreadyExistsException();
}
// Update found slot
@ -232,8 +230,6 @@ class AdminPollService {
// Commit transaction
$this->connect->commit();
return true;
}
/**
@ -244,7 +240,7 @@ class AdminPollService {
*
* @param $poll_id int The ID of the poll
* @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) {
$this->logService->log('ADD_SLOT', 'id:' . $poll_id . ', title:' . $title);
@ -257,7 +253,7 @@ class AdminPollService {
}, $slots);
if (in_array($title, $titles)) {
// The moment already exists
return false;
throw new MomentAlreadyExistsException();
}
@ -272,8 +268,6 @@ class AdminPollService {
// Commit transaction
$this->connect->commit();
return true;
}
/**
@ -283,34 +277,29 @@ class AdminPollService {
*
* @param $slots array All the slots of the poll
* @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) {
$result = new \stdClass();
$result->slot = null;
$result->insert = -1;
$i = 0;
$result->insert = 0;
foreach ($slots as $slot) {
$rowDatetime = $slot->title;
$moments = explode(',', $slot->moments);
if ($datetime == $rowDatetime) {
$i += count($moments);
// Here we have to insert at the end of a slot
$result->insert += count($moments);
$result->slot = $slot;
$result->insert = $i;
break;
} elseif ($datetime < $rowDatetime) {
// Here we have to insert a new slot
// We have to insert before this slot
break;
} else {
$i += count($moments);
$result->insert += count($moments);
}
}
$result->insert = $i;
return $result;
}

View File

@ -335,7 +335,8 @@
"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:",
"Failed to delete column": "Löschen der Spalte fehlgeschlagen",
"The column already exists": "DE_La colonne existe déjà",
"MISSING_VALUES": "Fehlende Werte",
"CANT_CONNECT_TO_DATABASE": "Kann nicht mit der Datenbank verbinden"
}
}
}

View File

@ -335,6 +335,7 @@
"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: ",
"Failed to delete column": "Failed to delete column",
"The column already exists": "The column already exists",
"MISSING_VALUES": "Missing values",
"CANT_CONNECT_TO_DATABASE": "Unable to connect to database"
}

View File

@ -335,6 +335,7 @@
"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 : ",
"Failed to delete column": "Error al eliminar la columna",
"The column already exists": "ES_La colonne existe déjà",
"MISSING_VALUES": "Los valores perdidos",
"CANT_CONNECT_TO_DATABASE": "No se puede conectar a la base de datos"
}

View File

@ -350,6 +350,7 @@
"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 : ",
"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",
"CANT_CONNECT_TO_DATABASE": "Impossible de se connecter à la base de données"
}

View File

@ -335,6 +335,7 @@
"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: : ",
"Failed to delete column": "Impossibile eliminare la colonna",
"The column already exists": "IT_La colonne existe déjà",
"MISSING_VALUES": "Valori mancanti",
"CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database"
}