Skip to content

Commit

Permalink
0.11.1: Streamlined valid listener tests and hid certain tabs when li…
Browse files Browse the repository at this point in the history
…stener has no logged data
  • Loading branch information
classaxe committed Oct 28, 2018
1 parent d5d9603 commit ab23b57
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 35 deletions.
20 changes: 16 additions & 4 deletions src/Controller/Web/Listener/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ protected function getValidListener($id, $listenerRepository)
$this->session->set('lastError', "Listener cannot be found.");
return false;
}
$listener = $listenerRepository->find((int) $id);
if (!$listener) {
$this->session->set('lastError', "Listener cannot be found");
if (!$listener = $listenerRepository->find((int) $id)) {
$this->session->set('lastError', "Listener ".((int) $id)." cannot be found");
return false;
}
return $listener;
}

/**
* @param $id
* @param $listenerRepository
* @return bool
*/
protected function getValidReportingListener($id, $listenerRepository)
{
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
return false;
}
if (!$listener->getCountLogs()) {
$this->session->set('lastError', "Listener <strong>".$listener->getName()."</strong> has no logs to view.");
$this->session->set('lastError', "Listener <strong>".$listener->getName()."</strong> has submitted no logs.");
return false;
}
return $listener;
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Web/Listener/Export.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace App\Controller\Web\Listener;

use App\Controller\Web\Base;
use App\Controller\Web\Listener\Base;
use App\Repository\ListenerRepository;
use Symfony\Component\Routing\Annotation\Route; // Required for annotations

Expand All @@ -28,7 +28,7 @@ public function exportController(
) {
if ((int) $id) {
$listener = $listenerRepository->find((int)$id);
if (!$listener) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Export/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function logsController(
ListenerRepository $listenerRepository,
LogRepository $logRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$logs = $logRepository->getLogsForListener($id);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Export/Signalmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function signalmapController(
LogRepository $logRepository,
TypeRepository $typeRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$listenerSignalTypes = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Export/SignalsKml.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function signalsKmlController(
ListenerRepository $listenerRepository,
TypeRepository $typeRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$filter = [];
Expand Down
9 changes: 3 additions & 6 deletions src/Controller/Web/Listener/Logs.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace App\Controller\Web\Listener;

use App\Controller\Web\Base;
use App\Controller\Web\Listener\Base;
use App\Form\ListenerLogs as ListenerLogsForm;
use App\Repository\ListenerRepository;
use App\Repository\TypeRepository;
Expand Down Expand Up @@ -35,11 +35,8 @@ public function logsController(
$defaultlimit = 100;
$maxNoPaging = 100;

if ((int) $id) {
$listener = $listenerRepository->find((int)$id);
if (!$listener) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}

$options = [
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Ndbweblog/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function configController(
$id,
ListenerRepository $listenerRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$parameters = [
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Ndbweblog/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function logsController(
ListenerRepository $listenerRepository,
LogRepository $logRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$parameters = [
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Ndbweblog/Signals.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function stationsController(
$id,
ListenerRepository $listenerRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$parameters = [
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Web/Listener/Ndbweblog/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function viewController(
$id,
ListenerRepository $listenerRepository
) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$parameters = [
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/Web/Listener/Signals.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace App\Controller\Web\Listener;

use App\Controller\Web\Base;
use App\Controller\Web\Listener\Base;
use App\Form\ListenerSignals as ListenerSignalsForm;
use App\Repository\ListenerRepository;
use App\Repository\TypeRepository;
Expand Down Expand Up @@ -36,8 +36,7 @@ public function signalsController(
$maxNoPaging = 100;

if ((int) $id) {
$listener = $listenerRepository->find((int)$id);
if (!$listener) {
if (!$listener = $this->getValidReportingListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/Web/Listener/View.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace App\Controller\Web\Listener;

use App\Controller\Web\Base;
use App\Controller\Web\Listener\Base;
use App\Entity\Listener as ListenerEntity;
use App\Form\Listener as ListenerForm;
use App\Repository\ListenerRepository;
Expand Down Expand Up @@ -33,8 +33,7 @@ public function viewController(
ListenerRepository $listenerRepository
) {
if ($id !== 'new' && (int) $id) {
$listener = $listenerRepository->find((int)$id);
if (!$listener) {
if (!$listener = $this->getValidListener($id, $listenerRepository)) {
return $this->redirectToRoute('listeners', ['system' => $system]);
}
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/Web/Listener/Weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public function weatherController(
if ((int)$id) {
$listener = $listenerRepository->find($id);
} else {
$listener = new ListenerEntity();
$listener
->setLogLatest(\App\Utils\Rxx::getUtcDateTime('0000-00-00'));
return $this->redirectToRoute('listeners', ['system' => $system]);
}
$listener
->setCallsign($form_data['callsign'])
Expand Down
28 changes: 21 additions & 7 deletions src/Repository/ListenerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,27 @@ public function getTabs($listener = false)
if (!$listener) {
return [];
}
$logs = $listener->getCountLogs();
$signals = $listener->getCountSignals();
$out = [];
foreach ($this->tabs as $route => $label) {
$out[$route] = str_replace(
['%%signals%%', '%%logs%%'],
[$listener->getCountSignals(), $listener->getCountLogs()],
$label
);
foreach ($this->tabs as $idx => $data) {
$route = $data[0];
switch ($route) {
case "listener_export":
case "listener_logs":
case "listener_signals":
if ($logs) {
$out[] = str_replace(
['%%logs%%', '%%signals%%'],
[$logs, $signals],
$data
);
}
break;
default:
$out[] = $data;
break;
}
}
return $out;
}
Expand Down Expand Up @@ -219,7 +233,7 @@ public function getTotalListeners($system)
public function getLogsForListener($listenerID, array $args)
{
$columns =
'trim(l.date) as logDate,'
'trim(l.date) as logDate,'
.'trim(l.time) as logTime,'
.'s.id,'
.'trim(s.khz)+0 as khz,'
Expand Down

0 comments on commit ab23b57

Please sign in to comment.