. * * @package LibreNMS * @link http://librenms.org * @copyright 2023 Tony Murray * @author Tony Murray */ namespace App\Http\Controllers\Table; use App\Models\TnmsneInfo; use Illuminate\Http\Request; class TnmsneController extends TableController { protected function rules() { return [ 'device_id' => 'nullable|integer', ]; } protected function sortFields($request) { return [ 'neName', 'neLocation', 'neType', 'neOpMode', 'neAlarm', 'neOpState', ]; } protected function searchFields(Request $request) { return [ 'neName', 'neLocation', 'neType', 'neOpMode', 'neAlarm', 'neOpState', ]; } protected function filterFields(Request $request) { return ['device_id']; } /** * @inheritDoc */ protected function baseQuery(Request $request) { return TnmsneInfo::query(); } /** * @param TnmsneInfo $tnmsne * @return array */ public function formatItem($tnmsne) { $neOp = $tnmsne->neOpMode == 'operation' ? 'operation' : '' . htmlspecialchars($tnmsne->neOpMode) . ''; $opState = $tnmsne->neOpState == 'enabled' ? 'enabled' : '' . htmlspecialchars($tnmsne->neOpState) . ''; return [ 'neName' => htmlspecialchars($tnmsne->neName), 'neLocation' => htmlspecialchars($tnmsne->neLocation), 'neType' => htmlspecialchars($tnmsne->neType), 'neOpMode' => $neOp, 'neAlarm' => $this->getAlarmLabel($tnmsne->neAlarm), 'neOpState' => $opState, ]; } private function getAlarmLabel(string $neAlarm): string { return match ($neAlarm) { 'cleared' => 'cleared', 'warning' => 'warning', 'minor', 'major', 'critical', 'indeterminate' => '' . htmlspecialchars($neAlarm) . '', default => '' . htmlspecialchars($neAlarm) . '', }; } }