Skip to content
Snippets Groups Projects
Commit b7bda469 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

ensure that all ranges a news can be linked to are presented to the user and...

Closes #1982

Merge request studip/studip!1291
parent 374ff293
No related branches found
No related tags found
No related merge requests found
...@@ -39,49 +39,32 @@ class NewsRangesInput extends Input ...@@ -39,49 +39,32 @@ class NewsRangesInput extends Input
} }
$selectable = []; $selectable = [];
$studip_options = [];
if ($GLOBALS['perm']->have_perm('root')) { // Stud.IP
$studip_options[] = [ $studip_options = $this->getStudipOptions();
'value' => 'studip__home', if (count($studip_options) > 0) {
'name' => _('Stud.IP-Startseite'), $selectable[] = [
'label' => _('Stud.IP'),
'options' => $studip_options
]; ];
} }
$studip_options[] = [
'value' => \User::findCurrent()->id . '__person', // Institutes
'name' => _('Meine Profilseite') $inst_options = $this->getInstituteOptions();
]; if (count($inst_options) > 0) {
$selectable[] = [ $selectable[] = [
'label' => _('Stud.IP'), 'label' => _('Einrichtungen'),
'options' => $studip_options 'options' => $inst_options
]; ];
if ($GLOBALS['perm']->have_perm('admin')) { }
$inst_options = [];
foreach (\Institute::getMyInstitutes() as $institut) { // Courses
$inst_options[] = [ $course_options = $this->getCourseOptions();
'value' => $institut['Institut_id'] . '__institute', if (count($course_options) > 0) {
'name' => (string) $institut['Name'], $selectable[] = [
]; 'label' => _('Veranstaltungen'),
} 'options' => $course_options
if (count($inst_options)) { ];
$selectable[] = [
'label' => _('Einrichtungen'),
'options' => $inst_options
];
}
} else {
$course_options = [];
foreach (\Course::findByUser(\User::findCurrent()->id) as $course) {
$course_options[] = [
'value' => $course->getId()."__seminar",
'name' => (string) $course['name']
];
}
if (count($course_options)) {
$selectable[] = [
'label' => _('Veranstaltungen'),
'options' => $course_options
];
}
} }
$template = $GLOBALS['template_factory']->open('forms/news_ranges_input'); $template = $GLOBALS['template_factory']->open('forms/news_ranges_input');
...@@ -131,4 +114,71 @@ class NewsRangesInput extends Input ...@@ -131,4 +114,71 @@ class NewsRangesInput extends Input
} }
return []; return [];
} }
/**
* Returns a list of all possible stud.ip related ranges to link a news to.
*/
public function getStudipOptions(): array
{
$options = [];
if ($GLOBALS['perm']->have_perm('root')) {
$options[] = [
'value' => 'studip__home',
'name' => _('Stud.IP-Startseite'),
];
}
$options[] = [
'value' => \User::findCurrent()->id . '__person',
'name' => _('Meine Profilseite')
];
return $options;
}
/**
* Returns a list of all possible institute ranges to link a news to.
*/
public function getInstituteOptions(): array
{
$options = [];
foreach (\Institute::getMyInstitutes() as $institut) {
if (!\StudipNews::haveRangePermission('edit', $institut['Institut_id'])) {
continue;
}
$options[] = [
'value' => $institut['Institut_id'] . '__institute',
'name' => (string) $institut['Name'],
];
}
return $options;
}
/**
* Returns a list of all possible course ranges to link a news to.
*/
protected function getCourseOptions(): array
{
if ($GLOBALS['perm']->have_perm('admin')) {
return [];
}
$options = [];
foreach (\Course::findByUser(\User::findCurrent()->id) as $course) {
if (!\StudipNews::haveRangePermission('edit', $course->id)) {
continue;
}
$options[] = [
'value' => $course->id . '__seminar',
'name' => (string) $course->name,
];
}
return $options;
}
} }
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