Update getNearEvents to handle when event doesn't exist
This commit is contained in:
parent
283f224a95
commit
93021f5806
|
@ -411,7 +411,10 @@ function getNearEvents() {
|
|||
global $user, $sortColumn, $sortOrder;
|
||||
|
||||
$eventId = $_REQUEST['id'];
|
||||
$NearEvents = array( 'EventId'=>$eventId );
|
||||
|
||||
$event = dbFetchOne('SELECT * FROM Events WHERE Id=?', NULL, array($eventId));
|
||||
if ( !$event ) return $NearEvents;
|
||||
|
||||
parseFilter($_REQUEST['filter']);
|
||||
parseSort();
|
||||
|
@ -423,10 +426,10 @@ function getNearEvents() {
|
|||
|
||||
# When listing, it may make sense to list them in descending order. But when viewing Prev should timewise earlier and Next should be after.
|
||||
if ( $sortColumn == 'E.Id' or $sortColumn == 'E.StartTime' ) {
|
||||
$sortOrder = 'asc';
|
||||
$sortOrder = 'ASC';
|
||||
}
|
||||
|
||||
$sql = "SELECT E.Id AS Id, E.StartTime AS StartTime FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE $sortColumn ".($sortOrder=='asc'?'<=':'>=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql.' AND E.Id<'.$event['Id'] . " ORDER BY $sortColumn ".($sortOrder=='asc'?'desc':'asc');
|
||||
$sql = 'SELECT E.Id AS Id, E.StartTime AS StartTime FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE '.$sortColumn.' '.($sortOrder=='ASC'?'<=':'>=').' \''.$event[$_REQUEST['sort_field']].'\''.$_REQUEST['filter']['sql'].$midSql.' AND E.Id<'.$event['Id'] . ' ORDER BY '.$sortColumn.' '.($sortOrder=='ASC'?'DESC':'ASC');
|
||||
if ( $sortColumn != 'E.Id' ) {
|
||||
# When sorting by starttime, if we have two events with the same starttime (diffreent monitors) then we should sort secondly by Id
|
||||
$sql .= ', E.Id DESC';
|
||||
|
@ -435,7 +438,7 @@ function getNearEvents() {
|
|||
$result = dbQuery($sql);
|
||||
$prevEvent = dbFetchNext($result);
|
||||
|
||||
$sql = "SELECT E.Id AS Id, E.StartTime AS StartTime FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE $sortColumn ".($sortOrder=='asc'?'>=':'<=')." '".$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql.' AND E.Id>'.$event['Id'] . " ORDER BY $sortColumn $sortOrder";
|
||||
$sql = 'SELECT E.Id AS Id, E.StartTime AS StartTime FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE '.$sortColumn .' '.($sortOrder=='asc'?'>=':'<=').' \''.$event[$_REQUEST['sort_field']]."'".$_REQUEST['filter']['sql'].$midSql.' AND E.Id>'.$event['Id'] . ' ORDER BY '.$sortColumn.' '.($sortOrder=='ASC'?'ASC':'DESC');
|
||||
if ( $sortColumn != 'E.Id' ) {
|
||||
# When sorting by starttime, if we have two events with the same starttime (diffreent monitors) then we should sort secondly by Id
|
||||
$sql .= ', E.Id ASC';
|
||||
|
@ -444,22 +447,21 @@ function getNearEvents() {
|
|||
$result = dbQuery($sql);
|
||||
$nextEvent = dbFetchNext($result);
|
||||
|
||||
$result = array( 'EventId'=>$eventId );
|
||||
if ( $prevEvent ) {
|
||||
$result['PrevEventId'] = $prevEvent['Id'];
|
||||
$result['PrevEventStartTime'] = $prevEvent['StartTime'];
|
||||
$result['PrevEventDefVideoPath'] = getEventDefaultVideoPath($prevEvent['Id']);
|
||||
$NearEvents['PrevEventId'] = $prevEvent['Id'];
|
||||
$NearEvents['PrevEventStartTime'] = $prevEvent['StartTime'];
|
||||
$NearEvents['PrevEventDefVideoPath'] = getEventDefaultVideoPath($prevEvent['Id']);
|
||||
} else {
|
||||
$result['PrevEventId'] = $result['PrevEventStartTime'] = $result['PrevEventDefVideoPath'] = 0;
|
||||
$NearEvents['PrevEventId'] = $result['PrevEventStartTime'] = $result['PrevEventDefVideoPath'] = 0;
|
||||
}
|
||||
if ( $nextEvent ) {
|
||||
$result['NextEventId'] = $nextEvent['Id'];
|
||||
$result['NextEventStartTime'] = $nextEvent['StartTime'];
|
||||
$result['NextEventDefVideoPath'] = getEventDefaultVideoPath($nextEvent['Id']);
|
||||
$NearEvents['NextEventId'] = $nextEvent['Id'];
|
||||
$NearEvents['NextEventStartTime'] = $nextEvent['StartTime'];
|
||||
$NearEvents['NextEventDefVideoPath'] = getEventDefaultVideoPath($nextEvent['Id']);
|
||||
} else {
|
||||
$result['NextEventId'] = $result['NextEventStartTime'] = $result['NextEventDefVideoPath'] = 0;
|
||||
$NearEvents['NextEventId'] = $NearEvents['NextEventStartTime'] = $NearEvents['NextEventDefVideoPath'] = 0;
|
||||
}
|
||||
return $result;
|
||||
return $NearEvents;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue