From 97d8b24afbefcebc66d8bc75f0b47c6c44ebc735 Mon Sep 17 00:00:00 2001 From: Bernhard Fischer Date: Mon, 9 Dec 2024 12:18:18 +0100 Subject: [PATCH] Improvement: When duration is 0, we do not show any duration info. (#753). --- classes/output/bookingoption_description.php | 28 ++++++++++++------ classes/output/col_coursestarttime.php | 29 +++++++++++++------ .../bookingoption_description_view.mustache | 24 +++++++-------- templates/col_coursestarttime.mustache | 4 +-- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/classes/output/bookingoption_description.php b/classes/output/bookingoption_description.php index 5af836afe..b11284a1e 100755 --- a/classes/output/bookingoption_description.php +++ b/classes/output/bookingoption_description.php @@ -176,6 +176,9 @@ class bookingoption_description implements renderable, templatable { /** @var string $canceluntil */ private $canceluntil = null; + /** @var bool $selflearningcourseshowdurationinfo */ + private $selflearningcourseshowdurationinfo = null; + /** * Constructor. * @@ -264,15 +267,21 @@ public function __construct( // Check if it's a self-learning course. There's a JSON flag for this. if (!empty($settings->selflearningcourse)) { $this->selflearningcourse = true; - // Format the duration correctly. - $this->duration = format_time($settings->duration); - - $ba = singleton_service::get_instance_of_booking_answers($settings); - $buyforuser = price::return_user_to_buy_for(); - if (isset($ba->usersonlist[$buyforuser->id])) { - $timebooked = $ba->usersonlist[$buyforuser->id]->timecreated; - $timeremainingsec = $timebooked + $settings->duration - time(); - $this->timeremaining = format_time($timeremainingsec); + + if (!empty($settings->duration)) { + // We do not show duration info if it is set to 0. + $this->selflearningcourseshowdurationinfo = true; + + // Format the duration correctly. + $this->duration = format_time($settings->duration); + + $ba = singleton_service::get_instance_of_booking_answers($settings); + $buyforuser = price::return_user_to_buy_for(); + if (isset($ba->usersonlist[$buyforuser->id])) { + $timebooked = $ba->usersonlist[$buyforuser->id]->timecreated; + $timeremainingsec = $timebooked + $settings->duration - time(); + $this->timeremaining = format_time($timeremainingsec); + } } } @@ -571,6 +580,7 @@ public function get_returnarray(): array { 'address' => $this->address, 'institution' => $this->institution, 'selflearningcourse' => $this->selflearningcourse, + 'selflearningcourseshowdurationinfo' => $this->selflearningcourseshowdurationinfo, 'duration' => $this->duration, 'dates' => $this->dates, 'datesexist' => $this->datesexist, diff --git a/classes/output/col_coursestarttime.php b/classes/output/col_coursestarttime.php index fb40c4a79..6bd522104 100755 --- a/classes/output/col_coursestarttime.php +++ b/classes/output/col_coursestarttime.php @@ -59,6 +59,9 @@ class col_coursestarttime implements renderable, templatable { /** @var string $timeremaining */ public $timeremaining = null; + /** @var bool $selflearningcourseshowdurationinfo */ + private $selflearningcourseshowdurationinfo = null; + /** * Constructor * @@ -81,16 +84,23 @@ public function __construct($optionid, $booking = null, $cmid = null, $collapsed // For self-learning courses, we do not show any optiondates (sessions). if (!empty($settings->selflearningcourse)) { - $ba = singleton_service::get_instance_of_booking_answers($settings); - $buyforuser = price::return_user_to_buy_for(); - if (isset($ba->usersonlist[$buyforuser->id])) { - $timebooked = $ba->usersonlist[$buyforuser->id]->timecreated; - $timeremainingsec = $timebooked + $settings->duration - time(); - $this->timeremaining = format_time($timeremainingsec); - } - $this->selflearningcourse = true; - $this->duration = format_time($settings->duration); + + if (!empty($settings->duration)) { + // We do not show duration info if it is set to 0. + $this->selflearningcourseshowdurationinfo = true; + + // Format the duration correctly. + $this->duration = format_time($settings->duration); + + $ba = singleton_service::get_instance_of_booking_answers($settings); + $buyforuser = price::return_user_to_buy_for(); + if (isset($ba->usersonlist[$buyforuser->id])) { + $timebooked = $ba->usersonlist[$buyforuser->id]->timecreated; + $timeremainingsec = $timebooked + $settings->duration - time(); + $this->timeremaining = format_time($timeremainingsec); + } + } } else { // No self-learning course. $this->datestrings = dates_handler::return_array_of_sessions_simple($optionid); @@ -117,6 +127,7 @@ public function export_for_template(renderer_base $output) { if (!empty($this->selflearningcourse)) { $returnarr['selflearningcourse'] = $this->selflearningcourse; $returnarr['duration'] = $this->duration; + $returnarr['selflearningcourseshowdurationinfo'] = $this->selflearningcourseshowdurationinfo; if (!empty($this->timeremaining)) { $returnarr['timeremaining'] = $this->timeremaining; } diff --git a/templates/bookingoption_description_view.mustache b/templates/bookingoption_description_view.mustache index 4401fde19..c82ab3012 100755 --- a/templates/bookingoption_description_view.mustache +++ b/templates/bookingoption_description_view.mustache @@ -179,19 +179,17 @@ {{/datesexist}} - {{^datesexist}} - {{#selflearningcourse}} -
-   - {{^timeremaining}} - {{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}} - {{/timeremaining}} - {{#timeremaining}} - {{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}} - {{/timeremaining}} -
- {{/selflearningcourse}} - {{/datesexist}} + {{#selflearningcourseshowdurationinfo}} +
+   + {{^timeremaining}} + {{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}} + {{/timeremaining}} + {{#timeremaining}} + {{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}} + {{/timeremaining}} +
+ {{/selflearningcourseshowdurationinfo}}
diff --git a/templates/col_coursestarttime.mustache b/templates/col_coursestarttime.mustache index d2e042100..1afab6ec3 100755 --- a/templates/col_coursestarttime.mustache +++ b/templates/col_coursestarttime.mustache @@ -78,7 +78,7 @@ {{/datestrings.0}} {{/showcollapsebtn}} {{/selflearningcourse}} -{{#selflearningcourse}} +{{#selflearningcourseshowdurationinfo}}   {{^timeremaining}} {{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}} @@ -86,4 +86,4 @@ {{#timeremaining}} {{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}} {{/timeremaining}} -{{/selflearningcourse}} \ No newline at end of file +{{/selflearningcourseshowdurationinfo}} \ No newline at end of file