mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
102 lines
3.3 KiB
PHP
102 lines
3.3 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,
|
|
];
|
|
}
|
|
|
|
// /**
|
|
// * @param Request $request
|
|
// * @param Builder $query
|
|
// * @return Builder
|
|
// */
|
|
// protected function sort($request, $query)
|
|
// {
|
|
// $columns = $this->sortFields($request);
|
|
// $sort = $request->get('sort', $this->default_sort);
|
|
//
|
|
// foreach ($sort as $column => $direction) {
|
|
// if (isset($columns[$column])) {
|
|
// $query->orderBy($columns[$column], $direction == 'desc' ? 'desc' : 'asc');
|
|
// }
|
|
// }
|
|
//
|
|
// return $query;
|
|
// }
|
|
}
|