aboutsummaryrefslogtreecommitdiff
path: root/lib/models/ConsultationBlock.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2021-11-04 13:28:13 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2021-11-04 13:28:13 +0000
commitbca463638c5b919a34ec90f3909c2eb44d2d1f77 (patch)
tree7941a9e178dff09ad8a98367ed59bbf43d926846 /lib/models/ConsultationBlock.php
parent0fe45573d21b5110a46de7b6dc60cbcec3f99de7 (diff)
fixes #132
Diffstat (limited to 'lib/models/ConsultationBlock.php')
-rw-r--r--lib/models/ConsultationBlock.php94
1 files changed, 67 insertions, 27 deletions
diff --git a/lib/models/ConsultationBlock.php b/lib/models/ConsultationBlock.php
index bb83515..d644629 100644
--- a/lib/models/ConsultationBlock.php
+++ b/lib/models/ConsultationBlock.php
@@ -24,7 +24,8 @@
* @property bool has_bookings computed column
* @property Range range computed column
* @property SimpleORMapCollection slots has_many ConsultationSlot
- * @property User teacher belongs_to User
+ * @property ConsultationResponsibility[] responsibilities has_many ConsultationResponsibility
+ * @property User[] responsible_persons
*/
class ConsultationBlock extends SimpleORMap implements PrivacyObject
{
@@ -36,16 +37,18 @@ class ConsultationBlock extends SimpleORMap implements PrivacyObject
{
$config['db_table'] = 'consultation_blocks';
- $config['belongs_to']['teacher'] = [
- 'class_name' => User::class,
- 'foreign_key' => 'teacher_id',
- ];
$config['has_many']['slots'] = [
'class_name' => ConsultationSlot::class,
'assoc_foreign_key' => 'block_id',
'on_store' => 'store',
'on_delete' => 'delete',
];
+ $config['has_many']['responsibilities'] = [
+ 'class_name' => ConsultationResponsibility::class,
+ 'assoc_foreign_key' => 'block_id',
+ 'on_delete' => 'delete',
+ 'order_by' => "ORDER BY range_type = 'user' DESC, range_type = 'statusgroup' DESC",
+ ];
$config['additional_fields']['range'] = [
'set' => function ($block, $field, Range $range) {
@@ -61,31 +64,11 @@ class ConsultationBlock extends SimpleORMap implements PrivacyObject
return $block->range->getFullName() . ' <' . $block->range->email . '>';
}
if ($block->range instanceof Course || $block->range instanceof Institute) {
- $display = $block->range->getFullName();
- if ($block->teacher) {
- $display .= ' (' . $block->teacher->getFullName() . ')';
- }
- return $display;
- }
-
- throw new Exception('Not implemented yet');
- };
- $config['additional_fields']['responsible_persons']['get'] = function ($block) {
- if ($block->range instanceof User) {
- return [$block->range];
- }
- if ($block->range instanceof Course && $block->teacher) {
- return [$block->teacher];
- }
-
- if ($block->range instanceof Course) {
- return $block->range->getMembersWithStatus('tutor dozent', true)->pluck('user');
+ return sprintf(_('Veranstaltung: %s'), $block->range->getFullName());
}
if ($block->range instanceof Institute) {
- return $block->range->members->filter(function ($member) {
- return in_array($member->inst_perms, ['tutor', 'dozent']);
- })->pluck('user');
+ return sprintf(_('Einrichtung: %s'), $block->range->getFullname());
}
throw new Exception('Not implemented yet');
@@ -103,6 +86,32 @@ class ConsultationBlock extends SimpleORMap implements PrivacyObject
});
};
+ $config['additional_fields']['responsible_persons']['get'] = function (ConsultationBlock $block) {
+ if (count($block->responsibilities) !== 0) {
+ $result = [];
+ foreach (array_merge(...$block->responsibilities->getUsers()) as $user) {
+ $result[$user->id] = $user;
+ }
+ return array_values($result);
+ }
+
+ if ($block->range instanceof User) {
+ return [$block->range];
+ }
+ if ($block->range instanceof Course) {
+ return ConsultationResponsibility::getCourseResponsibilities($block->range);
+ }
+ if ($block->range instanceof Institute) {
+ return ConsultationResponsibility::getInstituteResponsibilites($block->range);
+ }
+
+ throw new Exception('Unknown range type');
+ };
+
+ $config['registered_callbacks']['after_store'][] = function (ConsultationBlock $block) {
+ $block->slots->updateEvents();
+ };
+
parent::configure($config);
}
@@ -274,6 +283,37 @@ class ConsultationBlock extends SimpleORMap implements PrivacyObject
}
/**
+ *
+ */
+ public function getPossibleResponsibilites()
+ {
+ if ($this->range instanceof User) {
+ return [
+ 'users' => [$this->range]
+ ];
+ }
+
+ if ($this->range instanceof Course) {
+ return [
+ 'users' => $this->range->getMembersWithStatus('tutor dozent', true)->pluck('user'),
+ ];
+ }
+
+ if ($this->range instanceof Institute) {
+ $users = $this->range->members->filter(function ($member) {
+ return in_array($member->inst_perms, ['tutor', 'dozent']);
+ })->pluck('user');
+
+ $groups = $this->range->status_groups;
+ $institutes = $this->range->sub_institutes;
+
+ return compact('users', 'groups', 'institutes');
+ }
+
+ throw new Exception('Not implemented yet');
+ }
+
+ /**
* Export available data of a given user into a storage object
* (an instance of the StoredUserData class) for that user.
*