Skip to content
Snippets Groups Projects
Commit a423fd59 authored by Moritz Strohm's avatar Moritz Strohm Committed by Jan-Hendrik Willms
Browse files

fix for BIESt 1813, closes #1813

Closes #1813

Merge request studip/studip!1365
parent 930bebba
No related branches found
No related tags found
1 merge request!4Draft: Icon creation
......@@ -713,30 +713,65 @@ class Course_TimesroomsController extends AuthenticatedController
*/
$this->date = CourseDate::findOneByMetadate_id($cycle_id);
$this->checked_dates = $_SESSION['_checked_dates'];
$this->preparation_time = '0';
//Check if the preparation time is the same for all dates.
//In that case, use the common value as preparation time.
$i = 0;
$ptime = 0;
foreach ($checked_course_dates as $course_date) {
$current_ptime = $course_date->room_booking->preparation_time;
if ($i == 0) {
$ptime = $current_ptime;
} else {
if ($current_ptime != $ptime) {
$ptime = -1;
break;
}
}
$i++;
}
if ($ptime > -1) {
$this->preparation_time = $ptime / 60;
}
$this->selected_lecturer_ids = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
return $date->dozenten->pluck('user_id');
});
$this->selected_room_id = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
return $date->room_booking->resource_id ?? '';
});
$this->selected_room_name = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
return $date->raum ?? '';
});
$preparation_time = $this->getSameFieldValue($checked_course_dates, function (CourseDate $date) {
return $date->room_booking->preparation_time ?? 0;
});
$this->preparation_time = floor($preparation_time / 60);
$this->max_preparation_time = Config::get()->RESOURCES_MAX_PREPARATION_TIME;
$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.
......
......@@ -5,13 +5,13 @@
* @var array $linkAttributes
* @var array $checked_dates
* @var array $selectable_rooms
* @var array $tpl
* @var QuickSearch $room_search
* @var array $only_bookable_rooms
* @var array $teachers
* @var array $gruppen
* @var int $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) ?>"
......@@ -46,7 +46,8 @@
<select name="room_id" onFocus="jQuery('input[type=radio][name=action][value=room]').prop('checked', 'checked')">
<option value="0"><?= _('Auswählen') ?></option>
<? foreach ($selectable_rooms as $room): ?>
<option value="<?= htmlReady($room->id)?>">
<option value="<?= htmlReady($room->id)?>"
<?= $room->id === $selected_room_id ? 'selected' : '' ?>>
<?= htmlReady($room->name) ?>
</option>
<? endforeach ?>
......@@ -75,7 +76,7 @@
<?= $placerholder ?>
</label>
<label>
<input type="text" name="freeRoomText" value="<?= htmlReady($tpl['freeRoomText']) ?>"
<input type="text" name="freeRoomText" value="<?= htmlReady($selected_room_name) ?>"
placeholder="<?= $placerholder ?>"
onFocus="jQuery('input[type=radio][name=action][value=freetext]').prop('checked', 'checked')">
</label>
......@@ -108,6 +109,15 @@
<fieldset class="collapsed">
<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>
<?= _('Aktion auswählen') ?>
<select name="related_persons_action" id="related_persons_action">
......@@ -121,11 +131,11 @@
<label>
<?= _('Lehrende') ?>
<select name="related_persons[]" id="related_persons" multiple>
<? foreach ($teachers as $teacher) : ?>
<option value="<?= htmlReady($teacher['user_id']) ?>">
<?= htmlReady($teacher['fullname']) ?>
</option>
<? endforeach ?>
<? foreach ($teachers as $teacher) : ?>
<option value="<?= htmlReady($teacher['user_id']) ?>">
<?= htmlReady($teacher['fullname']) ?>
</option>
<? endforeach ?>
</select>
</label>
<? 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