Skip to content
Snippets Groups Projects
Commit e680fded authored by Ron Lucke's avatar Ron Lucke Committed by Jan-Hendrik Willms
Browse files

fix #2087

Closes #2087

Merge request studip/studip!1352
parent 569c0c25
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
use Courseware\StructuralElement; use Courseware\StructuralElement;
use Courseware\Block; use Courseware\Block;
use Courseware\Container; use Courseware\Container;
use Courseware\Unit;
/** /**
* Global search module for files * Global search module for files
...@@ -115,6 +116,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF ...@@ -115,6 +116,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF
{ {
$user = $GLOBALS['user']; $user = $GLOBALS['user'];
$structural_element = StructuralElement::find($data['id']); $structural_element = StructuralElement::find($data['id']);
$unit = $structural_element->findUnit();
if ($structural_element->canRead($user)) { if ($structural_element->canRead($user)) {
if ($data['type'] === 'cw_structural_elements') { if ($data['type'] === 'cw_structural_elements') {
$description = self::mark($structural_element->payload['description'], $search, true); $description = self::mark($structural_element->payload['description'], $search, true);
...@@ -125,12 +127,16 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF ...@@ -125,12 +127,16 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF
if ($data['type'] === 'cw_blocks') { if ($data['type'] === 'cw_blocks') {
$description = _('Suchbegriff wurde in einem Block gefunden'); $description = _('Suchbegriff wurde in einem Block gefunden');
} }
$pageData = self::getPageData($structural_element); $pageData = self::getPageData($structural_element, $unit);
$date = new DateTime(); $date = new DateTime();
$date->setTimestamp($structural_element->chdate); $date->setTimestamp($structural_element->chdate);
$name = $unit->structural_element->id === $structural_element->id
? $structural_element->title
: $unit->structural_element->title . ': ' . $structural_element->title;
return [ return [
'name' => self::mark($structural_element->title, $search, true), 'name' => self::mark($name, $search, true),
'description' => $description, 'description' => $description,
'url' => $pageData['url'], 'url' => $pageData['url'],
'img' => $structural_element->image ? $structural_element->getImageUrl() : Icon::create('courseware')->asImagePath(), 'img' => $structural_element->image ? $structural_element->getImageUrl() : Icon::create('courseware')->asImagePath(),
...@@ -143,14 +149,14 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF ...@@ -143,14 +149,14 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF
return []; return [];
} }
private static function getPageData(StructuralElement $structural_element): Array private static function getPageData(StructuralElement $structural_element, Unit $unit): Array
{ {
$url = ''; $url = '';
$originUrl = ''; $originUrl = '';
$originName = ''; $originName = '';
if ($structural_element->range_type === 'course') { if ($structural_element->range_type === 'course') {
$url = URLHelper::getURL( $url = URLHelper::getURL(
"dispatch.php/course/courseware?cid={$structural_element->range_id}#/structural_element/{$structural_element->id}", "dispatch.php/course/courseware/courseware/{$unit->id}?cid={$structural_element->range_id}#/structural_element/{$structural_element->id}",
[], [],
true); true);
$originUrl = URLHelper::getURL( $originUrl = URLHelper::getURL(
...@@ -161,7 +167,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF ...@@ -161,7 +167,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF
} }
if ($structural_element->range_type === 'user') { if ($structural_element->range_type === 'user') {
$url = URLHelper::getURL( $url = URLHelper::getURL(
"dispatch.php/contents/courseware/courseware#/structural_element/{$structural_element->id}", "dispatch.php/contents/courseware/courseware/{$unit->id}#/structural_element/{$structural_element->id}",
[], [],
true); true);
$originUrl = URLHelper::getURL( $originUrl = URLHelper::getURL(
...@@ -171,6 +177,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF ...@@ -171,6 +177,7 @@ class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchF
$originName = _('Persönliche Lernmaterialien'); $originName = _('Persönliche Lernmaterialien');
} }
return array( return array(
'url' => $url, 'url' => $url,
'originUrl' => $originUrl, 'originUrl' => $originUrl,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment