Skip to content

Commit

Permalink
Add phpdoc filter hook and refactor into only one occurence of the fi…
Browse files Browse the repository at this point in the history
…lter
  • Loading branch information
datengraben committed Dec 26, 2024
1 parent 81c3c22 commit be7b7b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
12 changes: 1 addition & 11 deletions src/Messages/BookingCodesMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ public function sendMessage(): bool {
$bookingCodes = BookingCodes::getCodes($timeframeId, $this->tsFrom,$this->tsTo);
if(empty($bookingCodes)) return $this->raiseError( __( "Could not find booking codes for this timeframe/period", "commonsbooking" ));

/**
* TODO
*
* @since 2.9.0
*/
$bookingTable = apply_filters(
'commonsbooking_emailcodes_rendertable',
\CommonsBooking\View\BookingCodes::renderBookingCodesTable( $bookingCodes ),
$bookingCodes,
'email'
);
$bookingTable = \CommonsBooking\View\BookingCodes::renderTableFor( 'email', $bookingCodes );

/**
* TODO
Expand Down
42 changes: 27 additions & 15 deletions src/View/BookingCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,8 @@ public static function renderTable( $timeframeId ) {
</div>
<div class="cmb-td">';
if($timeframe->hasBookingCodes()) {
/**
* Default rendering of the booking code table.
*
* @param string rendering of booking codes list as html string
* @param array $bookingCodes list of booking codes
* @param string ?
*
* @since 2.9.0
*/
echo apply_filters(
'commonsbooking_emailcodes_rendertable',
self::renderBookingCodesTable($bookingCodes),
$bookingCodes,
'timeframe_form'
);
echo self::renderTableFor( 'timeframe_form', $bookingCodes );

echo '<br>';
echo '<p class="cmb2-metabox-description">';
echo sprintf( __('Only showing booking codes for the next %s days.', 'commonsbooking'), $bcToShow );
Expand Down Expand Up @@ -531,4 +518,29 @@ public static function emailCodes($timeframeId = null, $tsFrom=null, $tsTo=null)
);

}

/**
* @param string $renderTarget code where email is rendered (email|timeframe_form)
* @param CommonsBooking\Model\BookingCode[] $bookingCodes array of string booking codes
*
* @return string|null
*/
public static function renderTableFor( $renderTarget, $bookingCodes ) {
$renderedTable = self::renderBookingCodesTable( $bookingCodes );
/**
* Default rendering of the booking code table in the specified target.
*
* @since 2.9.0
*
* @param string $renderedTable rendering of booking codes list as html string
* @param CommonsBooking\Model\BookingCode[] $bookingCodes list of booking codes
* @param string $renderTarget where email is rendered (email|timeframe_form)
*/
return apply_filters(
'commonsbooking_emailcodes_rendertable',
$renderedTable,
$bookingCodes,
$renderTarget
);
}
}

0 comments on commit be7b7b1

Please sign in to comment.