diff --git a/lib/Controller/Schedule.php b/lib/Controller/Schedule.php index 484b95034c..729e0a97cd 100644 --- a/lib/Controller/Schedule.php +++ b/lib/Controller/Schedule.php @@ -304,6 +304,9 @@ public function eventData(Request $request, Response $response) 'geoAware' => $sanitizedParams->getInt('geoAware'), 'recurring' => $sanitizedParams->getInt('recurring'), 'eventTypeId' => $sanitizedParams->getInt('eventTypeId'), + 'name' => $sanitizedParams->getString('name'), + 'useRegexForName' => $sanitizedParams->getCheckbox('useRegexForName'), + 'logicalOperatorName' => $sanitizedParams->getString('logicalOperatorName'), ]; if ($campaignId != null) { @@ -414,8 +417,12 @@ public function eventData(Request $request, Response $response) $toDt = Carbon::createFromTimestamp($scheduleEvent->toDt); // Set the row from/to date to be an ISO date for display - $scheduleEvent->fromDt = Carbon::createFromTimestamp($scheduleEvent->fromDt)->format(DateFormatHelper::getSystemFormat()); - $scheduleEvent->toDt = Carbon::createFromTimestamp($scheduleEvent->toDt)->format(DateFormatHelper::getSystemFormat()); + $scheduleEvent->fromDt = + Carbon::createFromTimestamp($scheduleEvent->fromDt) + ->format(DateFormatHelper::getSystemFormat()); + $scheduleEvent->toDt = + Carbon::createFromTimestamp($scheduleEvent->toDt) + ->format(DateFormatHelper::getSystemFormat()); $this->getLog()->debug(sprintf('Start date is ' . $fromDt->toRssString() . ' ' . $scheduleEvent->fromDt)); $this->getLog()->debug(sprintf('End date is ' . $toDt->toRssString() . ' ' . $scheduleEvent->toDt)); @@ -522,7 +529,12 @@ public function eventList(Request $request, Response $response, $id) // Reset the seconds $date->second(0); - $this->getLog()->debug(sprintf('Generating eventList for DisplayGroupId ' . $id . ' on date ' . $date->format(DateFormatHelper::getSystemFormat()))); + $this->getLog()->debug( + sprintf( + 'Generating eventList for DisplayGroupId ' . $id . ' on date ' + . $date->format(DateFormatHelper::getSystemFormat()) + ) + ); // Get a list of scheduled events $events = []; @@ -796,7 +808,7 @@ private function calculateIntermediates($display, $displayGroup, $eventDisplayGr * @throws InvalidArgumentException * @throws NotFoundException */ - function addForm(Request $request, Response $response, ?string $from, ?int $id): Response|ResponseInterface + public function addForm(Request $request, Response $response, ?string $from, ?int $id): Response|ResponseInterface { // Get the display groups added to the session (if there are some) $displayGroupIds = $this->session->get('displayGroupIds'); @@ -843,7 +855,11 @@ function addForm(Request $request, Response $response, ?string $from, ?int $id): if (!empty($from) && !empty($id)) { $formNowData = [ 'eventTypeId' => $this->getEventTypeId($from), - 'campaign' => (($from == 'Campaign' || $from == 'Layout') ? $this->campaignFactory->getById($id) : null), + 'campaign' => ( + ($from == 'Campaign' || $from == 'Layout') + ? $this->campaignFactory->getById($id) + : null + ), 'displayGroup' => (($from == 'DisplayGroup') ? [$this->displayGroupFactory->getById($id)] : null), 'displayGroupId' => (($from == 'DisplayGroup') ? (int)$id : 0), 'mediaId' => (($from === 'Library') ? $id : null), @@ -896,21 +912,24 @@ function addForm(Request $request, Response $response, ?string $from, ?int $id): * @SWG\Parameter( * name="eventTypeId", * in="formData", - * description="The Event Type Id to use for this Event. 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action, 7=Media Library, 8=Playlist", + * description="The Event Type Id to use for this Event. + * 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action, 7=Media Library, 8=Playlist", * type="integer", * required=true * ), * @SWG\Parameter( * name="campaignId", * in="formData", - * description="The Campaign ID to use for this Event. If a Layout is needed then the Campaign specific ID for that Layout should be used.", + * description="The Campaign ID to use for this Event. + * If a Layout is needed then the Campaign specific ID for that Layout should be used.", * type="integer", * required=false * ), * @SWG\Parameter( * name="fullScreenCampaignId", * in="formData", - * description="For Media or Playlist eventyType. The Layout specific Campaign ID to use for this Event. This needs to be the Layout created with layout/fullscreen function", + * description="For Media or Playlist eventyType. The Layout specific Campaign ID to use for this Event. + * This needs to be the Layout created with layout/fullscreen function", * type="integer", * required=false * ), @@ -1160,7 +1179,10 @@ public function add(Request $request, Response $response) $schedule->recurrenceDetail = $sanitizedParams->getInt('recurrenceDetail'); $recurrenceRepeatsOn = $sanitizedParams->getIntArray('recurrenceRepeatsOn'); $schedule->recurrenceRepeatsOn = (empty($recurrenceRepeatsOn)) ? null : implode(',', $recurrenceRepeatsOn); - $schedule->recurrenceMonthlyRepeatsOn = $sanitizedParams->getInt('recurrenceMonthlyRepeatsOn', ['default' => 0]); + $schedule->recurrenceMonthlyRepeatsOn = $sanitizedParams->getInt( + 'recurrenceMonthlyRepeatsOn', + ['default' => 0] + ); foreach ($sanitizedParams->getIntArray('displayGroupIds', ['default' => []]) as $displayGroupId) { $schedule->assignDisplayGroup($this->displayGroupFactory->getById($displayGroupId)); @@ -1176,9 +1198,12 @@ public function add(Request $request, Response $response) throw new InvalidArgumentException(__('Please enter a from date'), 'fromDt'); } - $logToDt = isset($toDt) ? $toDt->format(DateFormatHelper::getSystemFormat()) : null; - $logRecurrenceRange = isset($recurrenceRange) ? $recurrenceRange->format(DateFormatHelper::getSystemFormat()) : null; - $this->getLog()->debug('Times received are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange); + $logToDt = $toDt?->format(DateFormatHelper::getSystemFormat()); + $logRecurrenceRange = $recurrenceRange?->format(DateFormatHelper::getSystemFormat()); + $this->getLog()->debug( + 'Times received are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) + . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange + ); if (!$schedule->isCustomDayPart() && !$schedule->isAlwaysDayPart()) { // Daypart selected @@ -1202,9 +1227,13 @@ public function add(Request $request, Response $response) } if ($recurrenceRange != null) { - $schedule->recurrenceRange = $recurrenceRange->setTime($recurrenceRange->hour, $recurrenceRange->minute, 0)->format('U'); + $schedule->recurrenceRange = + $recurrenceRange->setTime( + $recurrenceRange->hour, + $recurrenceRange->minute, + 0 + )->format('U'); } - } else { $schedule->fromDt = $fromDt->format('U'); @@ -1217,9 +1246,12 @@ public function add(Request $request, Response $response) } } - $logToDt = isset($toDt) ? $toDt->format(DateFormatHelper::getSystemFormat()) : null; - $logRecurrenceRange = isset($recurrenceRange) ? $recurrenceRange->format(DateFormatHelper::getSystemFormat()) : null; - $this->getLog()->debug('Processed times are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange ); + $logToDt = $toDt?->format(DateFormatHelper::getSystemFormat()); + $logRecurrenceRange = $recurrenceRange?->format(DateFormatHelper::getSystemFormat()); + $this->getLog()->debug( + 'Processed times are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) + . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange + ); } // Ready to do the add @@ -1326,14 +1358,20 @@ function editForm(Request $request, Response $response, $id) $schedule->fromDt = ''; $schedule->toDt = ''; } else { - $schedule->fromDt = Carbon::createFromTimestamp($schedule->fromDt)->format(DateFormatHelper::getSystemFormat()); + $schedule->fromDt = + Carbon::createFromTimestamp($schedule->fromDt) + ->format(DateFormatHelper::getSystemFormat()); if ($schedule->toDt != null) { - $schedule->toDt = Carbon::createFromTimestamp($schedule->toDt)->format(DateFormatHelper::getSystemFormat()); + $schedule->toDt = + Carbon::createFromTimestamp($schedule->toDt) + ->format(DateFormatHelper::getSystemFormat()); } } if ($schedule->recurrenceRange != null) { - $schedule->recurrenceRange = Carbon::createFromTimestamp($schedule->recurrenceRange)->format(DateFormatHelper::getSystemFormat()); + $schedule->recurrenceRange = + Carbon::createFromTimestamp($schedule->recurrenceRange) + ->format(DateFormatHelper::getSystemFormat()); } // Get all reminders $scheduleReminders = $this->scheduleReminderFactory->query(null, ['eventId' => $id]); @@ -1361,19 +1399,22 @@ function editForm(Request $request, Response $response, $id) $this->getState()->template = 'schedule-form-edit'; $this->getState()->setData([ 'event' => $schedule, - 'campaigns' => $this->campaignFactory->query(null, ['isLayoutSpecific' => -1, 'retired' => 0, 'includeCampaignId' => $schedule->campaignId]), + 'campaigns' => $this->campaignFactory->query( + null, + ['isLayoutSpecific' => -1, 'retired' => 0, 'includeCampaignId' => $schedule->campaignId] + ), 'commands' => $this->commandFactory->query(), 'dayParts' => $this->dayPartFactory->allWithSystem(), 'displayGroups' => $schedule->displayGroups, 'campaign' => ($schedule->campaignId != '') ? $this->campaignFactory->getById($schedule->campaignId) : null, - 'displayGroupIds' => array_map(function($element) { + 'displayGroupIds' => array_map(function ($element) { return $element->displayGroupId; }, $schedule->displayGroups), 'layoutCodes' => $this->layoutFactory->getLayoutCodes(), 'reminders' => $scheduleReminders, 'defaultLat' => $defaultLat, 'defaultLong' => $defaultLong, - 'recurringEvent' => ($schedule->recurrenceType != '') ? true : false, + 'recurringEvent' => $schedule->recurrenceType != '', 'eventStart' => $eventStart, 'eventEnd' => $eventEnd, 'eventTypes' => \Xibo\Entity\Schedule::getEventTypesForm(), @@ -1393,7 +1434,7 @@ function editForm(Request $request, Response $response, $id) * @throws NotFoundException * @throws ControllerNotImplemented */ - function deleteRecurrenceForm(Request $request, Response $response, $id) + public function deleteRecurrenceForm(Request $request, Response $response, $id) { $sanitizedParams = $this->getSanitizer($request->getParams()); // Recurring event start/end @@ -1499,14 +1540,16 @@ public function deleteRecurrence(Request $request, Response $response, $id) * @SWG\Parameter( * name="eventTypeId", * in="formData", - * description="The Event Type Id to use for this Event. 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action", + * description="The Event Type Id to use for this Event. + * 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action", * type="integer", * required=true * ), * @SWG\Parameter( * name="campaignId", * in="formData", - * description="The Campaign ID to use for this Event. If a Layout is needed then the Campaign specific ID for that Layout should be used.", + * description="The Campaign ID to use for this Event. + * If a Layout is needed then the Campaign specific ID for that Layout should be used.", * type="integer", * required=false * ), @@ -1534,7 +1577,8 @@ public function deleteRecurrence(Request $request, Response $response, $id) * @SWG\Parameter( * name="displayGroupIds", * in="formData", - * description="The Display Group IDs for this event. Display specific Group IDs should be used to schedule on single displays.", + * description="The Display Group IDs for this event. + * Display specific Group IDs should be used to schedule on single displays.", * type="array", * required=true, * @SWG\Items(type="integer") @@ -1681,16 +1725,19 @@ public function edit(Request $request, Response $response, $id) ? $sanitizedParams->getInt('fullScreenCampaignId') : $sanitizedParams->getInt('campaignId'); $schedule->commandId = $sanitizedParams->getInt('commandId'); - $schedule->displayOrder = $sanitizedParams->getInt('displayOrder',['default' => $schedule->displayOrder]); + $schedule->displayOrder = $sanitizedParams->getInt('displayOrder', ['default' => $schedule->displayOrder]); $schedule->isPriority = $sanitizedParams->getInt('isPriority', ['default' => $schedule->isPriority]); - $schedule->dayPartId = $sanitizedParams->getInt('dayPartId',['default' => $schedule->dayPartId]); + $schedule->dayPartId = $sanitizedParams->getInt('dayPartId', ['default' => $schedule->dayPartId]); $schedule->syncTimezone = $sanitizedParams->getCheckbox('syncTimezone'); $schedule->syncEvent = $this->isSyncEvent($schedule->eventTypeId); $schedule->recurrenceType = $sanitizedParams->getString('recurrenceType'); $schedule->recurrenceDetail = $sanitizedParams->getInt('recurrenceDetail'); $recurrenceRepeatsOn = $sanitizedParams->getIntArray('recurrenceRepeatsOn'); $schedule->recurrenceRepeatsOn = (empty($recurrenceRepeatsOn)) ? null : implode(',', $recurrenceRepeatsOn); - $schedule->recurrenceMonthlyRepeatsOn = $sanitizedParams->getInt('recurrenceMonthlyRepeatsOn', ['default' => 0]); + $schedule->recurrenceMonthlyRepeatsOn = $sanitizedParams->getInt( + 'recurrenceMonthlyRepeatsOn', + ['default' => 0] + ); $schedule->displayGroups = []; $schedule->isGeoAware = $sanitizedParams->getCheckbox('isGeoAware'); $schedule->actionType = $sanitizedParams->getString('actionType'); @@ -1765,9 +1812,12 @@ public function edit(Request $request, Response $response, $id) throw new InvalidArgumentException(__('Please enter a from date'). 'fromDt'); } - $logToDt = isset($toDt) ? $toDt->format(DateFormatHelper::getSystemFormat()) : null; - $logRecurrenceRange = isset($recurrenceRange) ? $recurrenceRange->format(DateFormatHelper::getSystemFormat()) : null; - $this->getLog()->debug('Times received are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange); + $logToDt = $toDt?->format(DateFormatHelper::getSystemFormat()); + $logRecurrenceRange = $recurrenceRange?->format(DateFormatHelper::getSystemFormat()); + $this->getLog()->debug( + 'Times received are: FromDt=' . $fromDt->format(DateFormatHelper::getSystemFormat()) + . '. ToDt=' . $logToDt . '. recurrenceRange=' . $logRecurrenceRange + ); if (!$schedule->isCustomDayPart() && !$schedule->isAlwaysDayPart()) { // Daypart selected @@ -1788,7 +1838,9 @@ public function edit(Request $request, Response $response, $id) $schedule->toDt = $toDt->setTime($toDt->hour, $toDt->minute, 0)->format('U'); } - $schedule->recurrenceRange = ($recurrenceRange === null) ? null : $recurrenceRange->setTime($recurrenceRange->hour, $recurrenceRange->minute, 0)->format('U'); + $schedule->recurrenceRange = ($recurrenceRange === null) + ? null + : $recurrenceRange->setTime($recurrenceRange->hour, $recurrenceRange->minute, 0)->format('U'); } else { $schedule->fromDt = $fromDt->format('U'); @@ -2074,7 +2126,8 @@ private function getEventTypeId($from) * in="query", * required=false, * type="integer", - * description="Filter grid by eventTypeId. 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action, 7=Media Library, 8=Playlist" + * description="Filter grid by eventTypeId. + * 1=Layout, 2=Command, 3=Overlay, 4=Interrupt, 5=Campaign, 6=Action, 7=Media Library, 8=Playlist" * ), * @SWG\Parameter( * name="fromDt", @@ -2150,6 +2203,9 @@ public function grid(Request $request, Response $response) 'recurring' => $params->getInt('recurring'), 'campaignId' => $params->getInt('campaignId'), 'displayGroupIds' => $params->getIntArray('displayGroupIds'), + 'name' => $params->getString('name'), + 'useRegexForName' => $params->getCheckbox('useRegexForName'), + 'logicalOperatorName' => $params->getString('logicalOperatorName'), 'gridFilter' => 1 ], $params) ); diff --git a/lib/Factory/ScheduleFactory.php b/lib/Factory/ScheduleFactory.php index b6c8943300..74cbfc2cda 100644 --- a/lib/Factory/ScheduleFactory.php +++ b/lib/Factory/ScheduleFactory.php @@ -70,8 +70,16 @@ class ScheduleFactory extends BaseFactory * @param ScheduleExclusionFactory $scheduleExclusionFactory * @param User $user */ - public function __construct($config, $pool, $displayGroupFactory, $dayPartFactory, $userFactory, $scheduleReminderFactory, $scheduleExclusionFactory, $user) - { + public function __construct( + $config, + $pool, + $displayGroupFactory, + $dayPartFactory, + $userFactory, + $scheduleReminderFactory, + $scheduleExclusionFactory, + $user + ) { $this->setAclDependencies($user, $userFactory); $this->config = $config; $this->pool = $pool; @@ -478,19 +486,29 @@ public function query($sortOrder = null, $filterBy = []) // End both dates if ($parsedFilter->getIntArray('displayGroupIds') != null) { - $body .= ' AND `schedule`.eventId IN (SELECT `lkscheduledisplaygroup`.eventId FROM `lkscheduledisplaygroup` WHERE displayGroupId IN (' . implode(',', $parsedFilter->getIntArray('displayGroupIds')) . ')) '; + $body .= ' AND `schedule`.eventId IN (SELECT `lkscheduledisplaygroup`.eventId FROM `lkscheduledisplaygroup` + WHERE displayGroupId IN (' . implode(',', $parsedFilter->getIntArray('displayGroupIds')) . ')) '; } // Future schedules? - if ($parsedFilter->getInt('futureSchedulesFrom') !== null && $parsedFilter->getInt('futureSchedulesTo') === null) { + if ($parsedFilter->getInt('futureSchedulesFrom') !== null + && $parsedFilter->getInt('futureSchedulesTo') === null + ) { // Get schedules that end after this date, or that recur after this date - $body .= ' AND (IFNULL(`schedule`.toDt, `schedule`.fromDt) >= :futureSchedulesFrom OR `schedule`.recurrence_range >= :futureSchedulesFrom OR (IFNULL(`schedule`.recurrence_range, 0) = 0) AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\') '; + $body .= ' AND (IFNULL(`schedule`.toDt, `schedule`.fromDt) >= :futureSchedulesFrom + OR `schedule`.recurrence_range >= :futureSchedulesFrom OR (IFNULL(`schedule`.recurrence_range, 0) = 0) + AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\') '; $params['futureSchedulesFrom'] = $parsedFilter->getInt('futureSchedulesFrom'); } - if ($parsedFilter->getInt('futureSchedulesFrom') !== null && $parsedFilter->getInt('futureSchedulesTo') !== null) { + if ($parsedFilter->getInt('futureSchedulesFrom') !== null + && $parsedFilter->getInt('futureSchedulesTo') !== null + ) { // Get schedules that end after this date, or that recur after this date - $body .= ' AND ((schedule.fromDt < :futureSchedulesTo AND IFNULL(`schedule`.toDt, `schedule`.fromDt) >= :futureSchedulesFrom) OR `schedule`.recurrence_range >= :futureSchedulesFrom OR (IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\') ) '; + $body .= ' AND ((schedule.fromDt < :futureSchedulesTo + AND IFNULL(`schedule`.toDt, `schedule`.fromDt) >= :futureSchedulesFrom) + OR `schedule`.recurrence_range >= :futureSchedulesFrom OR (IFNULL(`schedule`.recurrence_range, 0) = 0 + AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\') ) '; $params['futureSchedulesFrom'] = $parsedFilter->getInt('futureSchedulesFrom'); $params['futureSchedulesTo'] = $parsedFilter->getInt('futureSchedulesTo'); } @@ -553,6 +571,20 @@ public function query($sortOrder = null, $filterBy = []) $params['syncGroupId'] = $parsedFilter->getInt('syncGroupId'); } + if ($parsedFilter->getString('name') != null) { + $terms = explode(',', $parsedFilter->getString('name')); + $logicalOperator = $parsedFilter->getString('logicalOperatorName', ['default' => 'OR']); + $this->nameFilter( + 'schedule', + 'name', + $terms, + $body, + $params, + ($parsedFilter->getCheckbox('useRegexForName') == 1), + $logicalOperator + ); + } + // Sorting? $order = ''; if ($parsedFilter->getInt('gridFilter') === 1 && $sortOrder === null) { diff --git a/ui/src/core/xibo-calendar.js b/ui/src/core/xibo-calendar.js index 0ea85cc1da..c4aa969ab5 100644 --- a/ui/src/core/xibo-calendar.js +++ b/ui/src/core/xibo-calendar.js @@ -260,16 +260,21 @@ $(document).ready(function() { let eventTypes = $('#eventTypeId').serialize(); let geoAware = $('#geoAware').serialize(); let recurring = $('#recurring').serialize(); + let name = $('#name').serialize(); + let nameRegEx = 'useRegexForName=' + $('#useRegexForName').is('checked'); + let nameLogicalOperator = $('#logicalOperatorName').serialize(); - !displayGroups ? $calendarErrorMessage.show() : $calendarErrorMessage.hide() + !displayGroups && !displayLayouts ? $calendarErrorMessage.show() : $calendarErrorMessage.hide() var url = calendarOptions.eventSource; // Append the selected filters - url += '?' + displayLayouts + '&' + eventTypes + '&' + geoAware + '&' + recurring; + url += '?' + displayLayouts + '&' + eventTypes + '&' + geoAware + + '&' + recurring + '&' + name + + '&' + nameRegEx + '&' + nameLogicalOperator; // Should we append displays? - if (isShowAll) { + if (!displayGroups && displayLayouts !== '') { // Ignore the display list url += '&' + 'displayGroupIds[]=-1'; } else if (displayGroups !== '') { diff --git a/views/inline.twig b/views/inline.twig index 2977ab07ac..7689747990 100644 --- a/views/inline.twig +++ b/views/inline.twig @@ -238,8 +238,8 @@ {% endmacro %} -{% macro inputNameGrid(name, title) %} -