Reworked the Events index view to display thumbnails by default.

The EventsController calls createListThumbnail() to build a list
of thumbnail data which is then passed to the view to be looped though.

Also had to change how I loop through $events so that I can match up the
indexes in $events with the indexes in $thumbData
This commit is contained in:
Kyle Johnson 2013-05-30 22:54:51 -04:00
parent 3505f35a6d
commit 50085d48b5
2 changed files with 19 additions and 5 deletions

View File

@ -6,6 +6,7 @@ class EventsController extends AppController {
public function index() {
$this->loadModel('Monitor');
$this->loadModel('Frame');
$conditions = array();
$named = $this->extractNamedParams(
@ -22,7 +23,7 @@ public function index() {
$events_per_page = Configure::read('ZM_WEB_EVENTS_PER_PAGE');
$this->paginate = array(
'fields' => array('Event.Name', 'Event.Length', 'Event.MonitorId', 'Event.Id', 'Monitor.Name'),
'fields' => array('Event.Name', 'Event.Length', 'Event.MonitorId', 'Event.Id', 'Monitor.Name', 'Event.MaxScore', 'Event.Width', 'Event.Height', 'Event.StartTime'),
'limit' => $events_per_page,
'order' => array( 'Event.Id' => 'asc'),
'conditions' => $conditions
@ -37,6 +38,11 @@ public function index() {
$this->set('eventsLastWeek', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 WEEK) GROUP BY Monitor.Id'));
$this->set('eventsLastMonth', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.StartTime > DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY Monitor.Id'));
$this->set('eventsArchived', $this->Monitor->query('SELECT COUNT(Event.Id) AS count FROM Monitors AS Monitor LEFT JOIN Events as Event ON Monitor.Id = Event.MonitorId AND Event.Archived = 1 GROUP BY Monitor.Id'));
foreach ($data as $key => $value) {
$thumbData[$key] = $this->Frame->createListThumbnail($value['Event']);
$this->set('thumbData', $thumbData);
}
}
public function view($id = null) {

View File

@ -24,16 +24,24 @@
<th>Length</th>
</tr>
<?php foreach ($events as $event): ?>
<?php foreach ($events as $key => $value): ?>
<tr>
<td>
<?php echo $this->Html->link($event['Event']['Name'],
array('controller' => 'events', 'action' => 'view', $event['Event']['Id'])); ?>
<td><?php echo $event['Monitor']['Name']; ?></td>
<td><?php echo $event['Event']['Length']; ?></td>
<?php
echo $this->Html->link($this->Html->image('/events/'.$thumbData[$key]['Path'], array(
'alt' => $thumbData[$key]['Frame']['FrameId'].'/'.$thumbData[$key]['Event']['MaxScore'],
'width' => $thumbData[$key]['Width'],
'height' => $thumbData[$key]['Height']
)), array('controller' => 'events', 'action' => 'view', $value['Event']['Id']),
array('escape' => false));
?>
</td>
</tr>
<?php endforeach; ?>
<?php unset($event); ?>
<?php unset($key); ?>
</table>
<div><?php echo $this->Paginator->numbers(); ?></div>
</div>