2020-04-11 18:03:19 -05:00
|
|
|
<?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
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-11 18:03:19 -05:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2020-04-11 18:03:19 -05:00
|
|
|
* @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',
|
2020-09-21 14:54:51 +02:00
|
|
|
'status' => DB::raw("end < '" . Carbon::now('UTC') . "'"), // only partition lapsed
|
2020-04-11 18:03:19 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param AlertSchedule $schedule
|
2020-04-11 18:03:19 -05:00
|
|
|
* @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,
|
|
|
|
];
|
|
|
|
}
|
2020-04-14 09:41:07 -05:00
|
|
|
}
|