1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
<?php
use Courseware\StructuralElement;
use Courseware\Block;
use Courseware\Container;
use Courseware\Unit;
/**
* Global search module for files
*
* @author Ron Lucke <lucke@elan-ev.de>
* @category Stud.IP
* @since 5.2
*/
class GlobalSearchCourseware extends GlobalSearchModule implements GlobalSearchFulltext
{
/**
* Returns the displayname for this module
*
* @return string
*/
public static function getName()
{
return _('Courseware');
}
/**
* Returns the filters that are displayed in the sidebar of the global search.
*
* @return array Filters for this class.
*/
public static function getFilters()
{
return [];
}
public static function getSQL($search, $filter, $limit)
{
if (!$search) {
return null;
}
$payload_search = str_replace('"', '', json_encode($search));
$query = DBManager::get()->quote("%{$search}%");
$payload_query = DBManager::get()->quote("%{$payload_search}%");
if (!empty($filter['rangeId'])) {
$range_id = $filter['rangeId'];
$sql = "(SELECT `cw_structural_elements` . `id` AS id, CONCAT('', 'cw_structural_elements') AS type
FROM `cw_structural_elements`
WHERE (`title` LIKE {$query} OR `payload` LIKE {$payload_query})
AND `range_id` = '{$range_id}'
ORDER BY `cw_structural_elements`.`mkdate` DESC)
UNION (
SELECT se . `id` AS id, CONCAT('', 'cw_containers') AS type
FROM `cw_containers` c
JOIN cw_structural_elements se
ON se . `id` = c . `structural_element_id`
WHERE c. `payload` LIKE {$payload_query}
AND `container_type` != 'list'
AND se . `range_id` = '{$range_id}'
ORDER BY c . `mkdate` DESC)
UNION (
SELECT se . `id` AS id, CONCAT('', 'cw_blocks') AS type
FROM `cw_blocks` b
JOIN cw_containers c
ON c.id = b.container_id
JOIN cw_structural_elements se
ON se . `id` = c . `structural_element_id`
WHERE b.payload LIKE {$payload_query}
AND se . `range_id` = '{$range_id}'
ORDER BY b . `mkdate` DESC
) LIMIT {$limit}";
} else {
$user_id = DBManager::get()->quote($GLOBALS['user']->id);
$mycourses = "SELECT `Seminar_id`
FROM `seminar_user`
WHERE `user_id` = {$user_id}";
if (Config::get()->DEPUTIES_ENABLE) {
$mycourses .= "
UNION
SELECT `range_id` AS Seminar_id
FROM `deputies`
WHERE `user_id` = {$user_id}";
}
$sql = "(SELECT `cw_structural_elements` . `id` AS id, CONCAT('', 'cw_structural_elements') AS type
FROM `cw_structural_elements`
WHERE (`title` LIKE {$query} OR `payload` LIKE {$payload_query})
AND (`range_id` IN ({$mycourses}) OR `range_id` = {$user_id})
ORDER BY `cw_structural_elements`.`mkdate` DESC)
UNION (
SELECT se . `id` AS id, CONCAT('', 'cw_containers') AS type
FROM `cw_containers` c
JOIN cw_structural_elements se
ON se . `id` = c . `structural_element_id`
WHERE c. `payload` LIKE {$payload_query}
AND `container_type` != 'list'
AND (se . `range_id` IN ({$mycourses}) OR se .`range_id` = {$user_id})
ORDER BY c . `mkdate` DESC)
UNION (
SELECT se . `id` AS id, CONCAT('', 'cw_blocks') AS type
FROM `cw_blocks` b
JOIN cw_containers c
ON c.id = b.container_id
JOIN cw_structural_elements se
ON se . `id` = c . `structural_element_id`
WHERE b.payload LIKE {$payload_query}
AND (se . `range_id` IN ({$mycourses}) OR se .`range_id` = {$user_id})
ORDER BY b . `mkdate` DESC
) LIMIT {$limit}";
}
return $sql;
}
public static function filter($data, $search)
{
$structural_element = StructuralElement::find($data['id']);
$unit = $structural_element->findUnit();
if ($unit && $structural_element->canRead($GLOBALS['user'])) {
$description = '';
if ($data['type'] === 'cw_structural_elements') {
$description = self::mark($structural_element->payload['description'], $search, true);
}
if ($data['type'] === 'cw_containers') {
$description = _('Suchbegriff wurde in einem Abschnitt gefunden');
}
if ($data['type'] === 'cw_blocks') {
$description = _('Suchbegriff wurde in einem Block gefunden');
}
$pageData = self::getPageData($structural_element, $unit);
$date = new DateTime();
$date->setTimestamp($structural_element->chdate);
$name = $unit->structural_element->id === $structural_element->id
? $structural_element->title
: $unit->structural_element->title . ': ' . $structural_element->title;
return [
'name' => self::mark($name, $search, true),
'description' => $description,
'url' => $pageData['url'],
'img' => $structural_element->image ? $structural_element->getImageUrl() : Icon::create('courseware')->asImagePath(),
'additional' => '<a href="' . $pageData['originUrl'] . '" title="' . $pageData['originName'] . '">' . $pageData['originName'] . '</a>',
'date' => $date->format('d.m.Y H:i'),
'structural-element-id' => $structural_element->id,
'expand' => null
];
}
return [];
}
private static function getPageData(StructuralElement $structural_element, Unit $unit): Array
{
$url = '';
$originUrl = '';
$originName = '';
if ($structural_element->range_type === 'course') {
$url = URLHelper::getURL(
"dispatch.php/course/courseware/courseware/{$unit->id}?cid={$structural_element->range_id}#/structural_element/{$structural_element->id}",
[],
true);
$originUrl = URLHelper::getURL(
"dispatch.php/course/overview?cid={$structural_element->range_id}",
[],
true);
$originName = Course::find($structural_element->range_id)->name;
}
if ($structural_element->range_type === 'user') {
$url = URLHelper::getURL(
"dispatch.php/contents/courseware/courseware/{$unit->id}#/structural_element/{$structural_element->id}",
[],
true);
$originUrl = URLHelper::getURL(
"dispatch.php/contents/courseware/index",
[],
true);
$originName = _('Persönliche Lernmaterialien');
}
return array(
'url' => $url,
'originUrl' => $originUrl,
'originName' => $originName
);
}
public static function enable()
{
}
public static function disable()
{
}
public static function getSearchURL($searchterm)
{
return URLHelper::getURL('dispatch.php/search/globalsearch', [
'q' => $searchterm,
'category' => self::class
]);
}
}
|