Event blacklist context completed

pull/663/head
iglocska 2015-09-16 14:19:22 +02:00
parent 26e640e19c
commit c06e687b5e
5 changed files with 109 additions and 7 deletions

View File

@ -22,7 +22,6 @@ class EventBlacklistsController extends AppController {
);
public function index() {
if ($this->response->type() === 'application/json' || $this->response->type() == 'application/xml' || $this->_isRest()) {
$blackList = $this->paginate();
$eventBlacklist= array();
@ -57,7 +56,15 @@ class EventBlacklistsController extends AppController {
$uuid = trim($uuid);
if (strlen($uuid) == 36) {
$this->EventBlacklist->create();
if ($this->EventBlacklist->save(array('event_uuid' => $uuid, 'comment' => $data['EventBlacklist']['comment']))) {
if ($this->EventBlacklist->save(
array(
'event_uuid' => $uuid,
'comment' => $data['EventBlacklist']['comment'],
'event_info' => $data['EventBlacklist']['info'],
'event_orgc' => $data['EventBlacklist']['orgc'],
)
)
) {
$successes[] = $uuid;
} else {
$fails[] = $uuid;
@ -69,13 +76,57 @@ class EventBlacklistsController extends AppController {
$message = 'Done. Added ' . count($successes) . ' new entries to the blacklist. ' . count($fails) . ' entries could not be saved.';
if ($this->_isRest()) {
$this->set('result', array('successes' => $successes, 'fails' => $fails));
$this->set('_serialize', array('result'));
$this->set('message', $message);
$this->set('_serialize', array('message', 'result'));
} else {
$this->Session->setFlash(__($message));
$this->redirect(array('action' => 'index'));
}
}
}
public function edit($id) {
if (strlen($id) == 36) {
$eb = $this->EventBlacklist->find('first', array('conditions' => array('uuid' => $id)));
} else {
$eb = $this->EventBlacklist->find('first', array('conditions' => array('id' => $id)));
}
if (empty($eb)) throw new NotFoundException('Blacklist item not found.');
$this->set('eb', $eb);
if ($this->request->is('post')) {
if ($this->_isRest()) {
if ($this->response->type() === 'application/json') {
$isJson = true;
$data = $this->request->input('json_decode', true);
} else {
$data = $this->request->data;
}
if (isset($data['request'])) $data = $data['request'];
} else {
$data = $this->request->data;
}
$fields = array('comment', 'event_info', 'event_orgc');
foreach ($fields as $f) {
if (isset($data['EventBlacklist'][$f])) $eb['EventBlacklist'][$f] = $data['EventBlacklist'][$f];
}
if ($this->EventBlacklist->save($eb)) {
if ($this->_isRest()) {
$this->set('message', array('Blacklist item added.'));
$this->set('_serialize', array('message'));
} else {
$this->Session->setFlash(__('Blacklist item added.'));
$this->redirect(array('action' => 'index'));
}
} else {
if ($this->_isRest()) {
throw new MethodNotAllowedException('Could not save the blacklist item.');
} else {
$this->Session->setFlash('Could not save the blacklist item');
$this->redirect(array('action' => 'index'));
}
}
}
}
public function delete($id) {
if (strlen($id) == 36) {

View File

@ -61,7 +61,7 @@ class AppModel extends Model {
$model= 'Log';
break;
case 'addEventBlacklists':
$sql = 'CREATE TABLE IF NOT EXISTS `event_blacklists` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event_uuid` varchar(40) COLLATE utf8_bin NOT NULL, `created` datetime NOT NULL, PRIMARY KEY (`id`), `event_info` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `event_orgc` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;';
$sql = 'CREATE TABLE IF NOT EXISTS `event_blacklists` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event_uuid` varchar(40) COLLATE utf8_bin NOT NULL, `created` datetime NOT NULL, PRIMARY KEY (`id`), `event_info` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `comment` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `event_orgc` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;';
break;
case 'addEventBlacklistsContext':
$sql = 'ALTER TABLE `event_blacklists` ADD `event_orgc` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL , ADD `event_info` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ADD `comment` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ;';

View File

@ -7,12 +7,27 @@
echo $this->Form->input('uuids', array(
'type' => 'textarea',
'div' => 'input clear',
'class' => 'input-xxlarge'
'class' => 'input-xxlarge',
'placeholder' => 'Enter a single or a list of UUIDs'
));
echo $this->Form->input('event_orgc', array(
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => 'Creating organisation',
'placeholder' => '(Optional) The organisation that the event is associated with'
));
echo $this->Form->input('event_info', array(
'type' => 'textarea',
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => 'Event info',
'placeholder' => '(Optional) the event info of the event that you would like to block. It\'s best to leave this empty if you are adding a list of UUIDs.'
));
echo $this->Form->input('comment', array(
'type' => 'textarea',
'div' => 'input clear',
'class' => 'input-xxlarge'
'class' => 'input-xxlarge',
'placeholder' => '(Optional) Any comments you would like to add regarding this (or these) entries.'
));
?>
</fieldset>

View File

@ -0,0 +1,35 @@
<div class="eventBlacklist form">
<?php echo $this->Form->create('EventBlacklist');?>
<fieldset>
<legend>Add Event Blacklist Entries</legend>
<p>Simply paste a list of all the event UUIDs that you wish to block from being entered.</p>
<?php
echo $this->Form->input('event_orgc', array(
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => 'Creating organisation',
'default' => $eb['EventBlacklist']['event_orgc'],
));
echo $this->Form->input('event_info', array(
'type' => 'textarea',
'div' => 'input clear',
'class' => 'input-xxlarge',
'label' => 'Event info',
'default' => $eb['EventBlacklist']['event_info'],
));
echo $this->Form->input('comment', array(
'type' => 'textarea',
'div' => 'input clear',
'class' => 'input-xxlarge',
'default' => $eb['EventBlacklist']['comment'],
));
?>
</fieldset>
<?php
echo $this->Form->button('Add', array('class' => 'btn btn-primary'));
echo $this->Form->end();
?>
</div>
<?php
echo $this->element('side_menu', array('menuList' => 'admin', 'menuItem' => 'eventBlacklistsAdd'));
?>

View File

@ -35,7 +35,8 @@ foreach ($response as $item): ?>
<td class="short"><?php echo (isset($item['EventBlacklist']['event_info']) ? h($item['EventBlacklist']['event_info']) : '&nbsp;'); ?></td>
<td class="short"><?php echo (isset($item['EventBlacklist']['comment']) ? h($item['EventBlacklist']['comment']) : '&nbsp;'); ?></td>
<td class="short action-links">
<?php echo $this->Form->postLink('', array('action' => 'delete', $item['EventBlacklist']['id']), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete the blacklist entry for the event UUID %s?', $item['EventBlacklist']['event_uuid'])); ?>
<a href="/eventBlacklists/edit/<?php echo h($item['EventBlacklist']['id']); ?>"><span class="icon-edit" title="edit">&nbsp;</span></a>
<?php echo $this->Form->postLink('', array('action' => 'delete', h($item['EventBlacklist']['id'])), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete the blacklist entry for the event UUID %s?', h($item['EventBlacklist']['event_uuid']))); ?>
</td>
</tr><?php
endforeach; ?>