Skip to content
Snippets Groups Projects
Commit f7b14b87 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

fix for BIESt 1813, closes #1813

Closes #1813

Merge request !1365
parent b8ccb22d
No related branches found
No related tags found
No related merge requests found
...@@ -680,30 +680,65 @@ class Course_TimesroomsController extends AuthenticatedController ...@@ -680,30 +680,65 @@ class Course_TimesroomsController extends AuthenticatedController
*/ */
$this->date = CourseDate::findOneByMetadate_id($cycle_id); $this->date = CourseDate::findOneByMetadate_id($cycle_id);
$this->checked_dates = $_SESSION['_checked_dates']; $this->checked_dates = $_SESSION['_checked_dates'];
$this->preparation_time = '0';
//Check if the preparation time is the same for all dates. $this->selected_lecturer_ids = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
//In that case, use the common value as preparation time. return $date->dozenten->pluck('user_id');
$i = 0; });
$ptime = 0; $this->selected_room_id = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
foreach ($checked_course_dates as $course_date) { return $date->room_booking->resource_id ?? '';
$current_ptime = $course_date->room_booking->preparation_time; });
if ($i == 0) { $this->selected_room_name = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
$ptime = $current_ptime; return $date->raum ?? '';
} else { });
if ($current_ptime != $ptime) {
$ptime = -1; $preparation_time = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
break; return $date->room_booking->preparation_time ?? 0;
} });
} $this->preparation_time = floor($preparation_time / 60);
$i++;
}
if ($ptime > -1) {
$this->preparation_time = $ptime / 60;
}
$this->max_preparation_time = Config::get()->RESOURCES_MAX_PREPARATION_TIME; $this->max_preparation_time = Config::get()->RESOURCES_MAX_PREPARATION_TIME;
$this->render_template('course/timesrooms/editStack'); $this->render_template('course/timesrooms/editStack');
} }
/**
* Checks a specific field value of the specified course dates for equality.
* A closure defines which field of the course dates to check.
*
* @param CourseDate[] $dates The dates from which to extract values.
* @param Closure $callback The closure that extracts values from a CourseDate object that is passed to it.
* @return mixed The identical value that has been retrieved from all course dates or a value that is equal to
* false in case the value differs. The returned result might be a string or an array or it may be empty.
*/
protected function getSameFieldValue(array $dates, Closure $callback)
{
$data = array_map($callback, $dates);
$initial = null;
foreach ($data as $item) {
if ($initial === null) {
$initial = $item;
continue;
}
// Compare array by checking their sizes and different items
if (
is_array($initial)
&& (
count($initial) !== count($item)
|| count(array_diff($initial, $item)) > 0
)
) {
return [];
}
// Otherwise compare items themselves
if (!is_array($initial) && $initial != $item) {
return '';
}
}
return $initial;
}
/** /**
* Creates a new room request for the selected dates. * Creates a new room request for the selected dates.
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
* @var array $linkAttributes * @var array $linkAttributes
* @var array $checked_dates * @var array $checked_dates
* @var array $selectable_rooms * @var array $selectable_rooms
* @var array $tpl
* @var QuickSearch $room_search * @var QuickSearch $room_search
* @var array $only_bookable_rooms * @var array $only_bookable_rooms
* @var array $teachers * @var array $teachers
* @var array $gruppen * @var array $gruppen
* @var int $preparation_time * @var int $preparation_time
* @var int $max_preparation_time * @var int $max_preparation_time
* @var string[] $selected_lecturer_ids
*/ */
?> ?>
<form method="post" action="<?= $controller->url_for('course/timesrooms/saveStack/' . $cycle_id, $linkAttributes) ?>" <form method="post" action="<?= $controller->url_for('course/timesrooms/saveStack/' . $cycle_id, $linkAttributes) ?>"
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
<select name="room_id" onFocus="jQuery('input[type=radio][name=action][value=room]').prop('checked', 'checked')"> <select name="room_id" onFocus="jQuery('input[type=radio][name=action][value=room]').prop('checked', 'checked')">
<option value="0"><?= _('Auswählen') ?></option> <option value="0"><?= _('Auswählen') ?></option>
<? foreach ($selectable_rooms as $room): ?> <? foreach ($selectable_rooms as $room): ?>
<option value="<?= htmlReady($room->id)?>"> <option value="<?= htmlReady($room->id)?>"
<?= $room->id === $selected_room_id ? 'selected' : '' ?>>
<?= htmlReady($room->name) ?> <?= htmlReady($room->name) ?>
</option> </option>
<? endforeach ?> <? endforeach ?>
...@@ -75,7 +76,7 @@ ...@@ -75,7 +76,7 @@
<?= $placerholder ?> <?= $placerholder ?>
</label> </label>
<label> <label>
<input type="text" name="freeRoomText" value="<?= htmlReady($tpl['freeRoomText']) ?>" <input type="text" name="freeRoomText" value="<?= htmlReady($selected_room_name) ?>"
placeholder="<?= $placerholder ?>" placeholder="<?= $placerholder ?>"
onFocus="jQuery('input[type=radio][name=action][value=freetext]').prop('checked', 'checked')"> onFocus="jQuery('input[type=radio][name=action][value=freetext]').prop('checked', 'checked')">
</label> </label>
...@@ -108,6 +109,15 @@ ...@@ -108,6 +109,15 @@
<fieldset class="collapsed"> <fieldset class="collapsed">
<legend><?= _('Durchführende Lehrende') ?></legend> <legend><?= _('Durchführende Lehrende') ?></legend>
<? if ($selected_lecturer_ids) : ?>
<ul>
<? foreach ($teachers as $teacher) : ?>
<? if (in_array($teacher['user_id'], $selected_lecturer_ids)) : ?>
<li><?= htmlReady($teacher['fullname']) ?></li>
<? endif ?>
<? endforeach ?>
</ul>
<? endif ?>
<label> <label>
<?= _('Aktion auswählen') ?> <?= _('Aktion auswählen') ?>
<select name="related_persons_action" id="related_persons_action"> <select name="related_persons_action" id="related_persons_action">
...@@ -121,11 +131,11 @@ ...@@ -121,11 +131,11 @@
<label> <label>
<?= _('Lehrende') ?> <?= _('Lehrende') ?>
<select name="related_persons[]" id="related_persons" multiple> <select name="related_persons[]" id="related_persons" multiple>
<? foreach ($teachers as $teacher) : ?> <? foreach ($teachers as $teacher) : ?>
<option value="<?= htmlReady($teacher['user_id']) ?>"> <option value="<?= htmlReady($teacher['user_id']) ?>">
<?= htmlReady($teacher['fullname']) ?> <?= htmlReady($teacher['fullname']) ?>
</option> </option>
<? endforeach ?> <? endforeach ?>
</select> </select>
</label> </label>
<? endif ?> <? endif ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment