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

iCalendar Unterscheidung zwischen Eigen- und Fremdterminen #1218

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 7 additions & 5 deletions includes/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,22 +1041,24 @@
'id' => 'feed_enabled',
'type' => 'checkbox',
),
//TODO: Consider to switch first_name and last_name with user_login since the other fields are not required.
array(
'name' => esc_html__( 'Event title', 'commonsbooking'),
'desc' => esc_html__( 'You can use template tags here as well', 'commonsbooking'),
'default' => commonsbooking_sanitizeHTML( __( '{{item:post_title}} at {{location:post_title}}',
'desc' => esc_html__( 'This is the event title that will be given to bookings that do not belong to the current user. This is what the CB-Manager will see when they subscribe to the station calendar. You can use template tags here as well', 'commonsbooking'),
'default' => commonsbooking_sanitizeHTML( __( '{{item:post_title}} @ {{user:first_name}} {{user:last_name}}',
'commonsbooking' ) ),
'id' => 'event_title',
'type' => 'text',
),
//TODO: more useful default template tags; better description
array(
'name' => esc_html__( 'Event description', 'commonsbooking'),
'desc' => esc_html__( 'You can use template tags here as well', 'commonsbooking'),
'desc' => esc_html__( 'This is the event description that will be given to bookings that do not belong to the current user. This is what the CB-Manager will see when they subscribe to the station calendar. You can use template tags here.', 'commonsbooking'),
'default' => commonsbooking_sanitizeHTML( __( '
Pick up: {{booking:pickupDatetime}}
Return date: {{booking:returnDatetime}}
{{location:formattedPickupInstructions}}
{{booking:formattedBookingCode}} ',
Booking code: {{booking:formattedBookingCode}}
User Email: {{user:user_email}}',
'commonsbooking' ) ),
'id' => 'event_desc',
'type' => 'textarea',
Expand Down
47 changes: 31 additions & 16 deletions src/View/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,51 @@ public static function shortcode( $atts ) {
return ob_get_clean();
}

public static function getBookingListiCal($user = null):String{
$eventTitle_unparsed = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_advanced-options', 'event_title' );
$eventDescription_unparsed = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_advanced-options', 'event_desc' );
/**
* Gets all booking that the current user has access to in iCal format to be used for calendar subscriptions.
* @param int|null $userID
*
* @return string|null - iCal string or null if no bookings are found
*/
public static function getBookingListiCal(?int $userID = null): ?string{

$user = get_user_by('id', $user);
$user = get_user_by('id', $userID);
if (!$user){
return null;
}

$bookingList = self::getBookingListData(999,$user);

//returns false when booking list is empty
if (!$bookingList){

return false;
if ( empty($bookingList) ){
return null;
}

$userBookingTitle = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_templates', 'emailtemplates_mail-booking_ics_event-title' );
$userBookingDescription = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_templates', 'emailtemplates_mail-booking_ics_event-description' );
$otherUserBookingTitle = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_advanced-options', 'event_title' );
$otherUserBookingDescription = Settings::getOption( COMMONSBOOKING_PLUGIN_SLUG . '_options_advanced-options', 'event_desc' );

$calendar = New iCalendar();

foreach ($bookingList["data"] as $booking)
foreach ($bookingList["data"] as $bookingData)
{
$booking_model = New \CommonsBooking\Model\Booking($booking["postID"]);
$booking = new \CommonsBooking\Model\Booking($bookingData["postID"]);
$bookingUser = $booking->getUserData();
$isOwnBooking = $bookingUser->ID == $user->ID;

$template_objects = [
'booking' => $booking_model,
'item' => $booking_model->getItem(),
'location' => $booking_model->getLocation(),
'user' => $booking_model->getUserData(),
'booking' => $booking,
'item' => $booking->getItem(),
'location' => $booking->getLocation(),
'user' => $bookingUser,
];

$eventTitle_unparsed = $isOwnBooking ? $userBookingTitle : $otherUserBookingTitle;
$eventDescription_unparsed = $isOwnBooking ? $userBookingDescription : $otherUserBookingDescription;

$eventTitle = commonsbooking_sanitizeHTML ( commonsbooking_parse_template ( $eventTitle_unparsed, $template_objects ) );
$eventDescription = commonsbooking_sanitizeHTML ( strip_tags ( commonsbooking_parse_template ( $eventDescription_unparsed, $template_objects ) ) );

$calendar->addBookingEvent($booking_model,$eventTitle,$eventDescription);
$calendar->addBookingEvent($booking,$eventTitle,$eventDescription);
}

return $calendar->getCalendarData();
Expand Down