admin: fix deleteion a slot from a classical poll
This commit is contained in:
parent
1ca7502216
commit
f399b9e543
@ -287,7 +287,19 @@ if (isset($_POST['confirm_delete_poll'])) {
|
||||
if (!empty($_POST['delete_column'])) {
|
||||
$column = filter_input(INPUT_POST, 'delete_column', FILTER_DEFAULT);
|
||||
|
||||
if ($adminPollService->deleteSlot($poll_id, $column)) {
|
||||
if ($poll->format === 'D') {
|
||||
$ex = explode('@', $column);
|
||||
|
||||
$slot = new stdClass();
|
||||
$slot->title = $ex[0];
|
||||
$slot->moment = $ex[1];
|
||||
|
||||
$result = $adminPollService->deleteDateSlot($poll_id, $slot);
|
||||
} else {
|
||||
$result = $adminPollService->deleteClassicSlot($poll_id, $column);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$message = new Message('success', _('Column deleted.'));
|
||||
} else {
|
||||
$message = new Message('danger', _('Failed to delete the column.'));
|
||||
|
@ -92,14 +92,14 @@ class AdminPollService {
|
||||
* Delete a slot from a poll.
|
||||
*
|
||||
* @param $poll_id int The ID of the poll
|
||||
* @param $slot string The name of the slot
|
||||
* @param $slot object The slot informations (datetime + moment)
|
||||
* @return bool true if action succeeded
|
||||
*/
|
||||
public function deleteSlot($poll_id, $slot) {
|
||||
public function deleteDateSlot($poll_id, $slot) {
|
||||
$this->logService->log('DELETE_SLOT', 'id:' . $poll_id . ', slot:' . json_encode($slot));
|
||||
$ex = explode('@', $slot);
|
||||
$datetime = $ex[0];
|
||||
$moment = $ex[1];
|
||||
|
||||
$datetime = $slot->title;
|
||||
$moment = $slot->moment;
|
||||
|
||||
$slots = $this->pollService->allSlotsByPollId($poll_id);
|
||||
|
||||
@ -136,6 +136,31 @@ class AdminPollService {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteClassicSlot($poll_id, $slot_title) {
|
||||
$this->logService->log('DELETE_SLOT', 'id:' . $poll_id . ', slot:' . $slot_title);
|
||||
|
||||
$slots = $this->pollService->allSlotsByPollId($poll_id);
|
||||
|
||||
$index = 0;
|
||||
$indexToDelete = -1;
|
||||
|
||||
// Search the index of the slot to delete
|
||||
foreach ($slots as $aSlot) {
|
||||
if ($slot_title == $aSlot->title) {
|
||||
$indexToDelete = $index;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
// Remove votes
|
||||
$this->connect->beginTransaction();
|
||||
$this->connect->deleteVotesByIndex($poll_id, $indexToDelete);
|
||||
$this->connect->deleteSlot($poll_id, $slot_title);
|
||||
$this->connect->commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new slot to the poll. And insert default values for user's votes.
|
||||
* <ul>
|
||||
|
@ -14,7 +14,7 @@
|
||||
<th role="presentation"></th>
|
||||
{foreach $slots as $id=>$slot}
|
||||
<td headers="C{$id}">
|
||||
<button type="submit" name="delete_column" value="{$slot->id}" class="btn btn-link btn-sm" title="{_('Remove the column')} {$slot->title}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button>
|
||||
<button type="submit" name="delete_column" value="{$slot->title}" class="btn btn-link btn-sm" title="{_('Remove the column')} {$slot->title}"><span class="glyphicon glyphicon-remove text-danger"></span><span class="sr-only">{_('Remove')}</span></button>
|
||||
</td>
|
||||
{/foreach}
|
||||
<td>
|
||||
|
Loading…
Reference in New Issue
Block a user