Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daypart: Unable to retire Dayparts #2883

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Controller/DayPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public function grid(Request $request, Response $response)
'name' => $sanitizedParams->getString('name'),
'useRegexForName' => $sanitizedParams->getCheckbox('useRegexForName'),
'isAlways' => $sanitizedParams->getInt('isAlways'),
'isCustom' => $sanitizedParams->getInt('isCustom')
'isCustom' => $sanitizedParams->getInt('isCustom'),
'isRetired' => $sanitizedParams->getInt('isRetired')
];

$dayParts = $this->dayPartFactory->query($this->gridRenderSort($sanitizedParams), $this->gridRenderFilter($filter, $sanitizedParams));
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public function addForm(Request $request, Response $response, ?string $from, ?in
$criteriaDefaultCondition = $event->getCriteriaDefaultCondition();

$addFormData = [
'dayParts' => $this->dayPartFactory->allWithSystem(),
'dayParts' => $this->dayPartFactory->allWithSystem(['isRetired' => 0]),
'reminders' => [],
'defaultLat' => $defaultLat,
'defaultLong' => $defaultLong,
Expand Down Expand Up @@ -1393,7 +1393,7 @@ function editForm(Request $request, Response $response, $id)
$this->getState()->template = 'schedule-form-edit';
$this->getState()->setData([
'event' => $schedule,
'dayParts' => $this->dayPartFactory->allWithSystem(),
'dayParts' => $this->dayPartFactory->allWithSystem(['isRetired' => 0]),
'displayGroups' => $schedule->displayGroups,
'campaign' => !empty($schedule->campaignId) ? $this->campaignFactory->getById($schedule->campaignId) : null,
'displayGroupIds' => array_map(function ($element) {
Expand Down Expand Up @@ -2667,7 +2667,7 @@ public function syncForm(Request $request, Response $response): Response|Respons
$this->getState()->template = 'schedule-form-sync-add';
$this->getState()->setData([
'eventTypeId' => \Xibo\Entity\Schedule::$SYNC_EVENT,
'dayParts' => $this->dayPartFactory->allWithSystem(),
'dayParts' => $this->dayPartFactory->allWithSystem(['isRetired' => 0]),
'defaultLat' => $defaultLat,
'defaultLong' => $defaultLong,
'reminders' => [],
Expand Down Expand Up @@ -2728,7 +2728,7 @@ public function syncEditForm(Request $request, Response $response, $id): Respons
$this->getState()->setData([
'eventTypeId' => \Xibo\Entity\Schedule::$SYNC_EVENT,
'event' => $schedule,
'dayParts' => $this->dayPartFactory->allWithSystem(),
'dayParts' => $this->dayPartFactory->allWithSystem(['isRetired' => 0]),
'defaultLat' => $defaultLat,
'defaultLong' => $defaultLong,
'eventStart' => $eventStart,
Expand Down
11 changes: 9 additions & 2 deletions lib/Factory/DayPartFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public function getCustomDayPart()

/**
* Get all dayparts with the system entries (always and custom)
* @param array $filter
* @return DayPart[]
* @throws NotFoundException
*/
public function allWithSystem()
public function allWithSystem($filter = [])
{
$dayParts = $this->query(['isAlways DESC', 'isCustom DESC', 'name']);
$dayParts = $this->query(['isAlways DESC', 'isCustom DESC', 'name'], $filter);

return $dayParts;
}
Expand Down Expand Up @@ -164,6 +165,12 @@ public function query($sortOrder = null, $filterBy = [])
$params['isCustom'] = $sanitizedFilter->getInt('isCustom');
}

if ($sanitizedFilter->getInt('isRetired', ['default'=> -1]) == 1)
$body .= ' AND daypart.isRetired = 1 ';

if ($sanitizedFilter->getInt('isRetired', ['default'=> -1]) == 0)
$body .= ' AND daypart.isRetired = 0 ';

if ($sanitizedFilter->getString('name') != null) {
$terms = explode(',', $sanitizedFilter->getString('name'));
$this->nameFilter('daypart', 'name', $terms, $body, $params, ($sanitizedFilter->getCheckbox('useRegexForName') == 1));
Expand Down
2 changes: 1 addition & 1 deletion views/daypart-form-add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

{% set title %}{% trans "Retired" %}{% endset %}
{% set helpText %}{% trans "Retire? It will no longer be visible when scheduling" %}{% endset %}
{{ forms.checkbox("retired", title, dayPart.isRetired, helpText) }}
{{ forms.checkbox("isRetired", title, dayPart.isRetired, helpText) }}

{% set title %}{% trans "Start Time" %}{% endset %}
{% set helpText %}{% trans "Enter the start time for this daypart" %}{% endset %}
Expand Down
2 changes: 1 addition & 1 deletion views/daypart-form-edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

{% set title %}{% trans "Retired" %}{% endset %}
{% set helpText %}{% trans "Retire? It will no longer be visible when scheduling" %}{% endset %}
{{ forms.checkbox("retired", title, dayPart.isRetired, helpText) }}
{{ forms.checkbox("isRetired", title, dayPart.isRetired, helpText) }}

{% set title %}{% trans "Start Time" %}{% endset %}
{% set helpText %}{% trans "Enter the start time for this daypart" %}{% endset %}
Expand Down
6 changes: 6 additions & 0 deletions views/daypart-page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<form class="form-inline">
{% set title %}{% trans "Name" %}{% endset %}
{{ inline.inputNameGrid('name', title) }}

{% set title %}{% trans "Retired" %}{% endset %}
{% set option1 = "Yes"|trans %}
{% set option2 = "No"|trans %}
{% set values = [{id: 1, value: option1}, {id: 0, value: option2}] %}
{{ inline.dropdown("isRetired", "single", title, 0, values, "id", "value") }}
</form>
</div>
</div>
Expand Down