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

'NoRep' Einstellung entfernen #1378

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 0 additions & 18 deletions assets/admin/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@
const BOOKABLE_ID = "2";
const HOLIDAYS_ID = "3";
const REPAIR_ID = "5";
const REPETITION_NONE = "norep";
const REPETITION_MANUAL = "manual";
const REPETITION_DAILY = "d";
const REPETITION_WEEKLY = "w";
Expand Down Expand Up @@ -241,18 +240,9 @@
const bookingConfigurationTitle = $("#title-bookings-config");
const allowUserRoles = $("#allowed_user_roles");
const repSet = [ repConfigTitle, fullDayInput, startTimeInput, endTimeInput, weekdaysInput, repetitionStartInput, repetitionEndInput, gridInput ];
const noRepSet = [ fullDayInput, startTimeInput, endTimeInput, gridInput, repetitionStartInput, repetitionEndInput ];
const repTimeFieldsSet = [ gridInput, startTimeInput, endTimeInput ];
const bookingCodeSet = [ createBookingCodesInput, bookingCodesList, bookingCodesDownload, showBookingCodes ];
const bookingConfigSet = [ maxDaysSelect, advanceBookingDays, bookingStartDayOffset, allowUserRoles, bookingConfigurationTitle ];
const showRepFields = function() {
showFieldset(repSet);
hideFieldset(arrayDiff(repSet, noRepSet));
};
const showNoRepFields = function() {
showFieldset(noRepSet);
hideFieldset(arrayDiff(noRepSet, repSet));
};
const uncheck = function(checkboxes) {
$.each(checkboxes, function() {
$(this).prop("checked", false);
Expand Down Expand Up @@ -290,11 +280,6 @@
const selectedType = $("option:selected", timeframeRepetitionInput).val();
const selectedTimeframeType = $("option:selected", typeInput).val();
if (selectedType) {
if (selectedType == REPETITION_NONE) {
showNoRepFields();
} else {
showRepFields();
}
if (selectedType === REPETITION_MANUAL) {
manualDateField.show();
manualDatePicker.show();
Expand All @@ -313,9 +298,6 @@
uncheck($("input[name*=weekdays]"));
}
handleFullDaySelection();
} else {
hideFieldset(noRepSet);
hideFieldset(repSet);
}
};
handleRepetitionSelection();
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions assets/admin/js/src/timeframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
const HOLIDAYS_ID = "3";
const REPAIR_ID = "5";

const REPETITION_NONE = "norep";
const REPETITION_MANUAL = "manual";
const REPETITION_DAILY = "d";
const REPETITION_WEEKLY = "w";
Expand Down Expand Up @@ -72,27 +71,10 @@
const bookingConfigurationTitle = $('#title-bookings-config');
const allowUserRoles = $('#allowed_user_roles');
const repSet = [repConfigTitle, fullDayInput, startTimeInput, endTimeInput, weekdaysInput, repetitionStartInput, repetitionEndInput, gridInput];
const noRepSet = [fullDayInput, startTimeInput, endTimeInput, gridInput, repetitionStartInput, repetitionEndInput];
const repTimeFieldsSet = [gridInput, startTimeInput, endTimeInput];
const bookingCodeSet = [createBookingCodesInput, bookingCodesList, bookingCodesDownload, showBookingCodes];
const bookingConfigSet = [maxDaysSelect, advanceBookingDays, bookingStartDayOffset, allowUserRoles, bookingConfigurationTitle];

/**
* Show repetition fields.
*/
const showRepFields = function () {
showFieldset(repSet);
hideFieldset(arrayDiff(repSet, noRepSet));
}

/**
* Show no-repetition fields.
*/
const showNoRepFields = function () {
showFieldset(noRepSet);
hideFieldset(arrayDiff(noRepSet, repSet));
}

/**
* Uncheck checkboxes.
* @param checkboxes
Expand Down Expand Up @@ -148,12 +130,6 @@
const selectedTimeframeType = $("option:selected", typeInput).val();

if (selectedType) {
if (selectedType == REPETITION_NONE) {
showNoRepFields();
} else {
showRepFields();
}

if (selectedType === REPETITION_MANUAL) {
manualDateField.show();
manualDatePicker.show();
Expand All @@ -174,11 +150,7 @@
}

handleFullDaySelection();
} else {
hideFieldset(noRepSet);
hideFieldset(repSet);
}

}
handleRepetitionSelection();
timeframeRepetitionInput.change(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public static function migrateBooking( $booking ): bool {
\CommonsBooking\Model\Timeframe::META_ITEM_ID => $cbItem ? $cbItem->ID : '',
\CommonsBooking\Model\Timeframe::META_LOCATION_ID => $cbLocation ? $cbLocation->ID : '',
'type' => Timeframe::BOOKING_ID,
\CommonsBooking\Model\Timeframe::META_REPETITION => 'norep',
\CommonsBooking\Model\Timeframe::META_REPETITION => 'd',
'start-time' => '00:00',
'end-time' => '23:59',
'full-day' => 'on',
Expand Down
20 changes: 3 additions & 17 deletions src/Model/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public function isInTimeframe( \CommonsBooking\Model\Timeframe $timeframe ): boo
if ( $timeframe->getRepetition() ) {
switch ( $timeframe->getRepetition() ) {
// Weekly Rep
//These repetitions take place on the weekdays that are configured in the timeframe
case "w":
$dayOfWeek = intval( $this->getDateObject()->format( 'w' ) );
$timeframeWeekdays = get_post_meta( $timeframe->ID, 'weekdays', true );
Expand All @@ -328,6 +329,7 @@ public function isInTimeframe( \CommonsBooking\Model\Timeframe $timeframe ): boo
}

// Monthly Rep
//These repetitions take place on the same day of the month as the start date
case "m":
$dayOfMonth = intval( $this->getDateObject()->format( 'j' ) );
$timeframeStartDayOfMonth = date('j',$timeframe->getStartDate());
Expand All @@ -339,6 +341,7 @@ public function isInTimeframe( \CommonsBooking\Model\Timeframe $timeframe ): boo
}

// Yearly Rep
// These repetitions take place on the same day of the year as the start date
case "y":
$date = intval( $this->getDateObject()->format( 'dm' ) );
$timeframeDate = date('dm',$timeframe->getStartDate());
Expand All @@ -351,23 +354,6 @@ public function isInTimeframe( \CommonsBooking\Model\Timeframe $timeframe ): boo
// Manual Rep
case "manual":
return in_array( $this->getDate(), $timeframe->getManualSelectionDates() );

// No Repetition
case "norep":
$timeframeStartTimestamp = intval( $timeframe->getMeta( \CommonsBooking\Model\Timeframe::REPETITION_START ));
$timeframeEndTimestamp = intval( $timeframe->getMeta( \CommonsBooking\Model\Timeframe::REPETITION_END ));

$currentDayStartTimestamp = strtotime('midnight', $this->getDateObject()->getTimestamp());
$currentDayEndTimestamp = strtotime('+1 day midnight', $this->getDateObject()->getTimestamp()) - 1;

$timeframeStartsBeforeEndOfToday = $timeframeStartTimestamp <= $currentDayEndTimestamp;
$timeframeEndsAfterStartOfToday = $timeframeEndTimestamp >= $currentDayStartTimestamp;

if(!$timeframeEndTimestamp) {
return $timeframeStartsBeforeEndOfToday;
} else {
return $timeframeStartsBeforeEndOfToday && $timeframeEndsAfterStartOfToday;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/Model/Timeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ public function getAdmins(): array {
* m = monthly
* y = yearly
* manual = manual selection of dates
* norep = no repetition
*
* @return mixed
*/
Expand Down
29 changes: 29 additions & 0 deletions src/Service/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Upgrade {
],
'2.8.5' => [
[self::class, 'removeBreakingPostmeta']
],
'2.9.0' => [
[self::class, 'timeframeNoRepToDaily']
]
];

Expand Down Expand Up @@ -284,4 +287,30 @@ public static function fixBrokenICalTitle() : void {
Settings::updateOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_advanced-options', 'event_title', $updatedString );
}
}

/**
* Will convert all timeframes with the old "norep" setting to use the "daily" setting in the repetition
*
* @since 2.9 (expected)
* @return void
* @throws \Exception
*/
public static function timeframeNoRepToDaily() {
$timeframes = \CommonsBooking\Repository\Timeframe::getBookable( [], [], null, true );
/** @var Timeframe $timeframe */
foreach ( $timeframes as $timeframe ) {
if ($timeframe->getRepetition() === 'norep') {
//you could previously set a timeframe with norep to just have a start-date and it would just be valid for the start-date.
//so we have to give norep timeframes without an end-date the start-date as end-date
if ( empty ( $timeframe->getMeta( Timeframe::REPETITION_END) ) ) {
update_post_meta(
$timeframe->ID,
Timeframe::REPETITION_END,
$timeframe->getMeta( Timeframe::REPETITION_START)
);
}
update_post_meta( $timeframe->ID, Timeframe::META_REPETITION, 'd' );
}
}
}
}
1 change: 0 additions & 1 deletion src/Wordpress/CustomPostType/Timeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ public static function getGridOptions() {
*/
public static function getTimeFrameRepetitions() {
return [
'norep' => esc_html__( "No repetition", 'commonsbooking' ),
'manual' => esc_html__( "Manual repetition", 'commonsbooking' ),
'd' => esc_html__( "Daily", 'commonsbooking' ),
'w' => esc_html__( "Weekly", 'commonsbooking' ),
Expand Down
Loading
Loading