19declare(strict_types=1);
55use Psr\Http\Message\ServerRequestInterface;
72 protected ServerRequestInterface
$request,
88 array $visible_column_ids,
91 mixed $additional_viewcontrol_data,
93 mixed $additional_parameters
105 foreach ($records as $record) {
107 $row_builder->
buildDataRow((
string) $record[
'id'], $record),
115 $column_factory = $this->ui_factory->table()->column();
118 'post' => $column_factory->text($this->
lng->txt(
'news_news_item_post'))->withIsSortable(
false),
119 'assigned_to' => $column_factory->text($this->
lng->txt(
'news_attached_to'))->withIsSortable(
false),
122 if ($this->isInternalRssEnabled()) {
123 $columns[
'access'] = $column_factory->text($this->
lng->txt(
'access'))->withIsSortable(
false);
126 $date_format = $this->
user->getDateTimeFormat();
128 'author' => $column_factory->text($this->
lng->txt(
'author'))->withIsSortable(
false),
129 'created_at' => $column_factory->date($this->
lng->txt(
'created'), $date_format)->withIsSortable(
true),
130 'updated_at' => $column_factory->date($this->
lng->txt(
'last_update'), $date_format)->withIsSortable(
true),
136 public function getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters): ?
int
138 return count($this->loadRecords($this->extractFilterData($filter_data)));
143 return $filter_data instanceof StandardFilter
144 ? $this->filter_service->getData($filter_data)
151 'ref_id' => (
int) ($this->request->getQueryParams()[
'ref_id'] ?? 0),
152 'context_obj_id' => $this->
ctrl->getContextObjId() ?? 0,
153 'context_obj_type' => $this->
ctrl->getContextObjType() ??
'',
154 'context_sub_obj_id' => 0,
160 return (
bool) $this->setting->get(
'enable_rss_for_internal');
165 foreach ($order->
get() as $order_field => $order_direction) {
166 usort($records,
static function (array $left, array $right) use ($order_field):
int {
167 $l = $left[$order_field] ??
null;
168 $r = $right[$order_field] ??
null;
169 return is_string($l) && is_string($r) ? strcmp($l, $r) : $l <=> $r;
176 $records = array_reverse($records);
197 $this->
filter = $this->getFilter();
198 $table = $this->ui_factory->table()->data(
200 $this->
lng->txt(
'news'),
203 ->withRequest($this->request)
204 ->withFilter($this->
filter)
205 ->withActions($this->
getTableActions()->getEnabledActions(...$this->acquireParameters($url_builder)))
206 ->withId($this->getTableId());
220 [$this->getTableId()],
221 self::ROW_ID_PARAMETER,
222 self::ACTION_PARAMETER,
223 self::ACTION_TYPE_PARAMETER
239 ))->getTableActions();
244 $author_options = [];
246 foreach ($this->loadNewsCollection()->getNewsItems() as $item) {
253 $author_options[$login] = $login;
256 $field_factory = $this->ui_factory->input()->field();
258 'text' => $field_factory->text($this->
lng->txt(
'news_news_item_content')),
261 if ($this->isInternalRssEnabled()) {
262 $filter_inputs[
'access'] = $field_factory->select(
263 $this->
lng->txt(
'access'),
265 'public' => $this->lng->txt(
'news_visibility_public'),
266 'users' => $this->lng->txt(
'news_visibility_users'),
271 $filter_inputs[
'author'] = $field_factory->select($this->
lng->txt(
'author'), $author_options);
273 return $this->filter_service->standard(
274 'news_item_table_filter',
275 $this->
ctrl->getLinkTargetByClass(ilNewsItemGUI::class,
'editNews',
''),
277 array_fill(0, count($filter_inputs),
true),
287 prevent_nesting: !in_array($context_obj_type, [
'cat',
'grp',
'crs',
'root'],
true),
288 no_auto_generated:
true,
289 include_read_status:
false
295 $news_request_context = $this->getNewsRequestContext();
297 return $this->news_collection_service->getNewsForContext(
299 $news_request_context[
'ref_id'],
300 $news_request_context[
'context_obj_id'],
301 $news_request_context[
'context_obj_type']
303 $this->buildOverviewCriteria($this->getNewsRequestContext()[
'context_obj_type']),
310 $data = $this->loadNewsCollection()->getNewsItems();
315 $filter = $filter_data ?? [];
316 $filter_raw = $filter[
'text'] ??
'';
317 $filter_text = $filter_raw !==
'' ? strtolower($filter_raw) :
'';
318 $filter_access = $filter[
'access'] ??
'';
319 $filter_author = $filter[
'author'] ??
'';
320 $enable_internal_rss = $this->isInternalRssEnabled();
323 foreach (
$data as $item) {
324 $item_matches_filters = $this->itemMatchesFilters(
332 if (!$item_matches_filters || !$this->itemShouldAppearInTable($item)) {
336 $assigned_to = $this->assignedToMarkupOrNull($item);
337 if ($assigned_to ===
null) {
342 'id' => (string) $item->getId(),
343 'post' => $this->renderPostCell($item),
344 'assigned_to' => $assigned_to,
345 'author' => $this->renderAuthorDisplay($item),
346 'created_at' => $item->getCreationDate(),
347 'updated_at' => $item->getUpdateDate(),
350 if ($enable_internal_rss) {
351 $record[
'access'] = $this->renderAccessDisplay($item);
354 $records[] = $record;
363 string $filter_access,
364 string $filter_author,
365 bool $enable_internal_rss
367 if ($search_text !==
'') {
368 $search_text = strtolower($search_text);
371 !str_contains(strtolower($item->
getTitle()), $search_text)
379 $filter_access !==
''
380 && $this->getItemAccess($item, $enable_internal_rss) !== $filter_access
385 if ($filter_author !==
'') {
386 $filter_user_id = $item->getUserId();
400 return $item->
getId() > 0 && ($this->news_access->canEdit($item) || $this->news_access->canDelete($item));
406 if ($post_title ===
'' || $item->
getId() <= 0) {
410 $post_content =
"{$item->getContent()}{$item->getContentLong()}";
411 $lightbox_page = $this->ui_factory->modal()->lightboxTextPage(
412 $post_content ?: $this->
lng->txt(
'news_news_item_no_content'),
415 $modal = $this->ui_factory->modal()->lightbox([$lightbox_page]);
416 $post_button = $this->ui_factory->button()->shy($post_title,
'')
417 ->withOnClick($modal->getShowSignal());
419 return $this->ui_renderer->render([$post_button, $modal]);
424 return $this->
lng->txt(
425 $this->getItemAccess($item,
true) ===
'public'
426 ?
'news_visibility_public'
427 :
'news_visibility_users'
441 if ($context_obj_type ===
'' || $context_obj_id <= 0) {
446 $item_ref_id = array_values($ref_ids)[0] ?? 0;
448 if ($item_ref_id <= 0) {
453 $obj_type_txt = $this->
lng->txt(
"obj_{$context_obj_type}");
455 $this->
ctrl->setParameterByClass(ilRepositoryGUI::class,
'ref_id', $item_ref_id);
456 $link_url = $this->
ctrl->getLinkTargetByClass(ilRepositoryGUI::class,
'');
457 $this->
ctrl->setParameterByClass(ilRepositoryGUI::class,
'ref_id',
null);
459 $obj_link = $this->ui_factory->link()->standard($obj_title, $link_url);
461 return "{$obj_type_txt}: {$this->ui_renderer->render($obj_link)}";
466 if (!$enable_internal_rss) {
472 'public_notifications',
476 $public_via_block_defaults = $item->
getPriority() === 0 && $public_notifications_for_context;
478 return ($item->
getVisibility() ===
'public' || $public_via_block_defaults) ?
'public' :
'users';
483 return $this->
getTableActions()->execute(...$this->acquireParameters($url_builder));
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
A simple class to express a naive range of whole positive numbers.
Optimized News Collection with memory-efficient data structures to support large news feeds.
News Context DTO represents a context where news items can be associated with.
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
News Item DTO for transfer of news items.
News Collection Service orchestrates all news-related operations and provides a high-level API for th...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
itemMatchesFilters(NewsItem $item, string $search_text, string $filter_access, string $filter_author, bool $enable_internal_rss)
acquireParameters(URLBuilder $url_builder)
renderPostCell(NewsItem $item)
execute(URLBuilder $url_builder)
const string ROW_ID_PARAMETER
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
const string ACTION_PARAMETER
limitRecords(array $records, Range $range)
getItemAccess(NewsItem $item, bool $enable_internal_rss)
renderAuthorDisplay(NewsItem $item)
itemShouldAppearInTable(NewsItem $item)
__construct(protected Factory $ui_factory, protected ilLanguage $lng, protected ServerRequestInterface $request, protected ilCtrl $ctrl, protected ilSetting $setting, protected Renderer $ui_renderer, protected NewsAccess $news_access, protected ilUIFilterService $filter_service, protected NewsCollectionService $news_collection_service, protected ilObjUser $user, protected HttpService $http_service, protected ilGlobalTemplateInterface $main_tpl, protected Refinery $refinery,)
buildOverviewCriteria(string $context_obj_type)
renderAccessDisplay(NewsItem $item)
extractFilterData(mixed $filter_data)
loadRecords(?array $filter_data=null)
const string ACTION_TYPE_PARAMETER
sortRecords(array $records, Order $order)
getComponents(URLBuilder $url_builder)
assignedToMarkupOrNull(NewsItem $item)
acquireParameters(array $namespace, string ... $names)
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
Class ilCtrl provides processing control methods.
User Interface for NewsItem entities.
static _lookupLogin(int $a_user_id)
Class ilObject Basic functions for all objects.
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
A component is the most general form of an entity in the UI.
This describes commonalities between the different modals.
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
An entity that renders components to a string output.
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
trait TableActionExecutorTrait
readonly UIRenderer $ui_renderer
trait TableActionExecutorTrait
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
if(!file_exists('../ilias.ini.php'))