Skip to content

Commit

Permalink
Improvement: When duration is 0, we do not show any duration info. (#753
Browse files Browse the repository at this point in the history
).
  • Loading branch information
ibernhardf committed Dec 9, 2024
1 parent 4f2d53d commit 97d8b24
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 33 deletions.
28 changes: 19 additions & 9 deletions classes/output/bookingoption_description.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class bookingoption_description implements renderable, templatable {
/** @var string $canceluntil */
private $canceluntil = null;

/** @var bool $selflearningcourseshowdurationinfo */
private $selflearningcourseshowdurationinfo = null;

/**
* Constructor.
*
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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,
Expand Down
29 changes: 20 additions & 9 deletions classes/output/col_coursestarttime.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class col_coursestarttime implements renderable, templatable {
/** @var string $timeremaining */
public $timeremaining = null;

/** @var bool $selflearningcourseshowdurationinfo */
private $selflearningcourseshowdurationinfo = null;

/**
* Constructor
*
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
24 changes: 11 additions & 13 deletions templates/bookingoption_description_view.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,17 @@
</div>
</div>
{{/datesexist}}
{{^datesexist}}
{{#selflearningcourse}}
<div>
<i class="fa fa-fw fa-clock-o" aria-hidden="true"></i>&nbsp;
{{^timeremaining}}
{{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}}
{{/timeremaining}}
{{#timeremaining}}
{{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}}
{{/timeremaining}}
</div>
{{/selflearningcourse}}
{{/datesexist}}
{{#selflearningcourseshowdurationinfo}}
<div>
<i class="fa fa-fw fa-clock-o" aria-hidden="true"></i>&nbsp;
{{^timeremaining}}
{{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}}
{{/timeremaining}}
{{#timeremaining}}
{{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}}
{{/timeremaining}}
</div>
{{/selflearningcourseshowdurationinfo}}
</div>
<div class="col-md-5">
<div class="card price-card">
Expand Down
4 changes: 2 additions & 2 deletions templates/col_coursestarttime.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@
{{/datestrings.0}}
{{/showcollapsebtn}}
{{/selflearningcourse}}
{{#selflearningcourse}}
{{#selflearningcourseshowdurationinfo}}
<i class="fa fa-fw fa-clock-o" aria-hidden="true"></i>&nbsp;
{{^timeremaining}}
{{#str}}selflearningcoursedurationinfo, mod_booking, {{duration}}{{/str}}
{{/timeremaining}}
{{#timeremaining}}
{{#str}}selflearningcoursetimeremaininginfo, mod_booking, {{timeremaining}}{{/str}}
{{/timeremaining}}
{{/selflearningcourse}}
{{/selflearningcourseshowdurationinfo}}

0 comments on commit 97d8b24

Please sign in to comment.