mirror of https://github.com/MISP/MISP
Show the number of events for each tag in the tag index
parent
08b2db6895
commit
7e2b8ceb85
|
@ -25,7 +25,27 @@ class TagsController extends AppController {
|
|||
}
|
||||
|
||||
public function index() {
|
||||
$this->set('list', $this->paginate());
|
||||
$this->loadModel('Event');
|
||||
$this->Event->recursive = -1;
|
||||
$this->paginate['contain'] = array('EventTag' => array('fields' => 'event_id'));
|
||||
$paginated = $this->paginate();
|
||||
foreach ($paginated as $k => &$tag) {
|
||||
$eventIDs = array();
|
||||
if (empty($tag['EventTag'])) $tag['Tag']['count'] = 0;
|
||||
else {
|
||||
foreach ($tag['EventTag'] as $eventTag) {
|
||||
$eventIDs[] = $eventTag['event_id'];
|
||||
}
|
||||
$conditions = array('Event.id' => $eventIDs);
|
||||
if (!$this->_isSiteAdmin()) $conditions = array_merge($conditions, array('OR' => array(array('Event.distribution >' => 0), array('Event.orgc' => $this->Auth->user('org')))));
|
||||
$events = $this->Event->find('all', array(
|
||||
'fields' => array('Event.id', 'Event.distribution', 'Event.orgc'),
|
||||
'conditions' => $conditions
|
||||
));
|
||||
$tag['Tag']['count'] = count($events);
|
||||
}
|
||||
}
|
||||
$this->set('list', $paginated);
|
||||
// send perm_tagger to view for action buttons
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<tr>
|
||||
<th><?php echo $this->Paginator->sort('id');?></th>
|
||||
<th><?php echo $this->Paginator->sort('name');?></th>
|
||||
<th>Count</th>
|
||||
<?php if ($isAclTagger): ?>
|
||||
<th class="actions"><?php echo __('Actions');?></th>
|
||||
<?php endif; ?>
|
||||
|
@ -28,6 +29,7 @@ foreach ($list as $item): ?>
|
|||
<tr>
|
||||
<td class="short"><?php echo h($item['Tag']['id']); ?> </td>
|
||||
<td><a href="/events/index/searchtag:<?php echo $item['Tag']['id']; ?>" class="tag" style="background-color: <?php echo h($item['Tag']['colour']); ?>;color:<?php echo $this->TextColour->getTextColour($item['Tag']['colour']); ?>"><?php echo h($item['Tag']['name']); ?></a></td>
|
||||
<td class="short"><?php echo h($item['Tag']['count']); ?> </td>
|
||||
<?php if ($isAclTagger): ?>
|
||||
<td class="short action-links">
|
||||
<?php echo $this->Html->link('', array('action' => 'edit', $item['Tag']['id']), array('class' => 'icon-edit', 'title' => 'Edit'));?>
|
||||
|
|
Loading…
Reference in New Issue