Skip to content

Commit

Permalink
decscriptionview
Browse files Browse the repository at this point in the history
  • Loading branch information
cbadusch committed Jun 27, 2024
1 parent c0b8284 commit 44c690d
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 80 deletions.
206 changes: 203 additions & 3 deletions classes/output/mod_booking_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
/**
* A custom renderer class that extends the plugin_renderer_base and is used by the booking module.
*
* @package mod_booking
* @package theme_lexa
* @copyright 2023 Wunderbyte GmbH <info@wunderbyte.at>
* @author David Bogner, Andraž Prinčič
* @author Christian Badusch
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace theme_lexa\output;

use local_berta\shortcodes;
use mod_booking;
use core_user;
use html_writer;
use mod_booking\output\bookingoption_description;
use mod_booking\output\col_availableplaces;
use mod_booking\price;
use mod_booking\singleton_service;

/**
* A custom renderer class that extends the plugin_renderer_base and is used by the booking module.
Expand All @@ -50,4 +55,199 @@ public function render_col_availableplaces($data) {
return $o;
}

/**
* This function is called for each data row to allow processing of the
* booking value.
*
* @param object $values Contains object with all the values of record.
* @return string $coursestarttime Returns course start time as a readable string.
* @throws coding_exception
*/
public function prepare_bookings($values, $id) {

$settings = singleton_service::get_instance_of_booking_option_settings((int)$id);
// Render col_bookings using a template.

$buyforuser = price::return_user_to_buy_for();

$data = new col_availableplaces($values, $settings, $buyforuser);
$output = singleton_service::get_renderer('local_berta');
return $output->render_col_availableplaces($data);
}

/**
* This function is called for each data row to allow processing of the
* booking option tags (botags).
*
* @param object $values Contains object with all the values of record.
* @return string $sports Returns course start time as a readable string.
* @throws coding_exception
*/
public function prepare_botags($id) {

$settings = singleton_service::get_instance_of_booking_option_settings((int)$id);

$botagsstring = '';

if (isset($settings->customfields) && isset($settings->customfields['botags'])) {
$botagsarray = $settings->customfields['botags'];
if (!empty($botagsarray)) {

if (!is_array($botagsarray)) {
$botagsarray = (array)$botagsarray;
}
foreach ($botagsarray as $botag) {
if (!empty($botag)) {
$botagsstring .=
"<span class='berta-table-botag rounded-sm bg-info text-light pl-2 pr-2 pt-1 pb-1 mr-1 d-inline-block text-center'>
$botag
</span>";
} else {
continue;
}
}
if (!empty($botagsstring)) {
return $botagsstring;
} else {
return '';
}
}
}
return '';
}

/**
* Renders the booking option description view.
*
* This function processes the booking option description data, prepares necessary
* details for display, and renders them using a template.
*
* @param bookingoption_description $data The booking option description data object.
* @return string The rendered HTML output.
*/
public function render_bookingoption_description_view(bookingoption_description $data) {
$o = '';
$data = $data->export_for_template($this);
// Prepare Data for template.
if (!empty($data['bookinginformation'])) {
$data['bookings'] = $this->prepare_bookings($data['bookinginformation'], $data['modalcounter']);
}
if (!empty($data['kurssprache'])) {
$data['kurssprache'] = $this->prepare_kurssprache($data['kurssprache'], $data['modalcounter'] );
}
if (!empty($data['format'])) {
$data['format'] = $this->prepare_format($data['format'], $data['modalcounter'] );
}
if (!empty($data['kompetenzen'])) {
$data['competency'] = $this->prepare_kompetenzen($data['modalcounter'] );
}
$data['botags'] = $this->prepare_botags($data['modalcounter']);
// $data['dates'] = $this->prepare_dates($data['dates'], $data['modalcounter']);
if (!isset($data['location']) || $data['location'] == '') {
$data['location'] = get_string('nolocation', 'local_berta');
}
$data['showcollapse'] = $this->prepare_dates($data);
$settings = singleton_service::get_instance_of_booking_option_settings((int)$data['modalcounter']);

if (!empty($settings->entity)) {
$data['entities'] = $settings->entity;
}

$o .= $this->render_from_template('mod_booking/bookingoption_description_view', $data);
return $o;
}

/**
* Prepare and format Kompetenzen (competencies) information based on custom fields.
*
* This method retrieves and formats the custom 'Kompetenzen' fields associated with
* a given booking option. It returns a string of HTML elements representing these
* competencies, each wrapped in a span tag with specific classes for styling.
*
* @param int $id The unique identifier for the booking option settings.
* @return string|null A string containing formatted HTML elements for each competency,
* or null if no competencies are found.
* @throws InvalidArgumentException When the ID is not a valid integer.
*/
public function prepare_kompetenzen($id) {

$settings = singleton_service::get_instance_of_booking_option_settings((int)$id);

if (isset($settings->customfields) && isset($settings->customfields['kompetenzen'])) {
if (is_array($settings->customfields['kompetenzen'])) {

$returnorgas = [];
foreach ($settings->customfields['kompetenzen'] as $orgaid) {
$organisations = shortcodes::KOMPETENZEN;

if (isset($organisations[$orgaid])) {
$returnorgas[] = html_writer::tag(
'span',
$organisations[$orgaid]['localizedname'],
['class' => 'bg-secondary pl-1 pr-1 mr-1 rounded category']
);

}
}

return implode(", ", $returnorgas);
} else {
$value = $settings->customfields['kompetenzen'];
$message = "<span class='bg-secondary orga'>$value</span>";
return $message;
}
}
}

/**
* Retrieve course language from custom fields.
*
* @param mixed $values Unused parameter.
* @param int $id Booking option settings ID.
* @return string|null The course language or null if not found.
*/
public function prepare_kurssprache($values, $id) {
$settings = singleton_service::get_instance_of_booking_option_settings((int)$id);

if (isset($settings->customfieldsfortemplates) && isset($settings->customfieldsfortemplates['kurssprache'])) {
$value = $settings->customfieldsfortemplates['kurssprache']['value'];
return $value;
}
}


/**
* Retrieve course format from custom fields.
*
* @param mixed $values Unused parameter.
* @param int $id Booking option settings ID.
* @return string|null The course language or null if not found.
*/
public function prepare_format($values, $id) {
$settings = singleton_service::get_instance_of_booking_option_settings((int)$id);

if (isset($settings->customfieldsfortemplates) && isset($settings->customfieldsfortemplates['format'])) {
$value = $settings->customfieldsfortemplates['format']['value'];
return $value;
}
}


/**
* Prepare dates collapse.
*
* @param mixed $values
* @return bool The course language or null if not found.
*/
public function prepare_dates($values) {

$maxdates = get_config('booking', 'collapseshowsettings') ?? 2; // Hardcoded fallback on two.
// Show a collapse button for the dates.
if (!empty($values['dates']) && count($values['dates']) > $maxdates) {
return true;
} else {
return false;
}
}

}
24 changes: 24 additions & 0 deletions scss/lexa.scss
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,27 @@ body.limitedwidth #page.drawers .footer-popover {
padding-bottom: 1rem;
}
}

#page-mod-booking-optionview {
background-color: $primarylightbg;
.main-inner, #region-main, #page-header, #topofscroll {
background-color: $primarylightbg;
}

.datestring {
.date {
margin-right:auto;
font-weight: bold;
}
}

.location {
a {
color: black;
border: 1px solid black;
background: white;
border-radius: .5rem;
padding: .375rem .75rem;
}
}
}
3 changes: 3 additions & 0 deletions scss/lexapre.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ $success: $green !default;
$warning: #f3874a !default;
$danger: $red !default;

$primarylightbg: #EDF6FA !default;


$drawer-bg-color: #e9f0f3 !default;

$footer: #001f33 !default;
Expand Down
2 changes: 1 addition & 1 deletion templates/local_shopping_cart/addtocartdb.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

}}
<div class="btn btn-secondary w-100 mt-0 mb-0 p-1 wb_shopping_cart booking-button-area "
<div class="btn btn-secondary w-100 mt-0 mb-0 p-1 wb_shopping_cart booking-button-area bertabutton"
id="btn-{{componentname}}-{{area}}-{{itemid}}"
tabindex="0"
data-itemid="{{itemid}}"
Expand Down
Loading

0 comments on commit 44c690d

Please sign in to comment.