Files
librenms-librenms/app/Http/Controllers/Table/AlertScheduleController.php
Tony Murray a312436bca Edit maintenance schedule, handle timezone properly (#11889)
Was not properly formatting to user's timezone
Also handle the case where the browser and server timezone don't match
don't show incorrect values in dialog then pop to the correct ones.
Update title on modal to be appropriate
2020-07-02 17:46:16 -05:00

83 lines
2.8 KiB
PHP

<?php
/**
* AlertScheduleController.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2020 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Http\Controllers\Table;
use App\Models\AlertSchedule;
use Carbon\Carbon;
use DB;
class AlertScheduleController extends TableController
{
protected $default_sort = ['title' => 'asc', 'start' => 'asc'];
protected function baseQuery($request)
{
return AlertSchedule::query();
}
protected function searchFields($request)
{
return['title', 'start', 'end'];
}
protected function sortFields($request)
{
return [
'start_recurring_dt' => DB::raw('DATE(`start`)'),
'start_recurring_ht' => DB::raw('TIME(`start`)'),
'end_recurring_dt' => DB::raw('DATE(`end`)'),
'end_recurring_ht' => DB::raw('TIME(`end`)'),
'title' => 'title',
'recurring' => 'recurring',
'start' => 'start',
'end' => 'end',
'status' => DB::raw("end < '" . Carbon::now('UTC') ."'"), // only partition lapsed
];
}
/**
* @param AlertSchedule $schedule
* @return array
*/
public function formatItem($schedule)
{
return [
'title' => $schedule->title,
'notes' => $schedule->notes,
'id' => $schedule->schedule_id,
'start' => $schedule->recurring ? '' : $schedule->start->toDateTimeString('minutes'),
'end' => $schedule->recurring ? '' : $schedule->end->toDateTimeString('minutes'),
'start_recurring_dt' => $schedule->recurring ? $schedule->start_recurring_dt : '',
'start_recurring_hr' => $schedule->recurring ? $schedule->start_recurring_hr : '',
'end_recurring_dt' => $schedule->recurring ? $schedule->end_recurring_dt : '',
'end_recurring_hr' => $schedule->recurring ? $schedule->end_recurring_hr : '',
'recurring' => $schedule->recurring ? __('Yes') : __('No'),
'recurring_day' => $schedule->recurring ? implode(',', $schedule->recurring_day) : '',
'status' => $schedule->status,
];
}
}