ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TableViewControlFieldSelection.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
27 {
31  protected ?array $selected_optional_column_ids = null;
32 
36  protected function initViewControlFieldSelection(array $columns): void
37  {
38  $this->selected_optional_column_ids = $this->filterVisibleColumnIds($columns);
39  }
40 
42  {
43  $optional_cols = $this->getOptionalColumns();
44  if ($optional_cols === []) {
45  return null;
46  }
47 
48  return $this->view_control_factory
49  ->fieldSelection(array_map(
50  static fn($c): string => $c->getTitle(),
51  $optional_cols
52  ))
53  ->withValue($this->getSelectedOptionalColumns());
54  }
55 
60  protected function filterVisibleColumnIds(array $columns): array
61  {
62  return array_keys(
63  array_filter(
64  $columns,
65  static fn($c): bool => $c->isInitiallyVisible()
66  )
67  );
68  }
69 
73  public function withSelectedOptionalColumns(?array $selected_optional_column_ids): static
74  {
75  $clone = clone $this;
76  $clone->selected_optional_column_ids = $selected_optional_column_ids;
77  return $clone;
78  }
79 
83  public function getSelectedOptionalColumns(): array
84  {
85  if (is_null($this->selected_optional_column_ids)) {
86  return array_keys($this->getInitiallyVisibleColumns());
87  }
88  return $this->selected_optional_column_ids;
89  }
90 
94  protected function getOptionalColumns(): array
95  {
96  return array_filter(
97  $this->getColumns(),
98  static fn($c): bool => $c->isOptional()
99  );
100  }
101 
105  protected function getInitiallyVisibleColumns(): array
106  {
107  return array_filter(
108  $this->getOptionalColumns(),
109  static fn($c): bool => $c->isInitiallyVisible()
110  );
111  }
112 
116  public function getVisibleColumns(): array
117  {
118  $visible_optional_columns = $this->getSelectedOptionalColumns();
119  return array_filter(
120  $this->getColumns(),
121  fn(Column $col, string $col_id): bool => !$col->isOptional() || in_array($col_id, $visible_optional_columns, true),
122  ARRAY_FILTER_USE_BOTH
123  );
124  }
125 
126 
127 }
withSelectedOptionalColumns(?array $selected_optional_column_ids)
$c
Definition: deliver.php:25
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This describes a Field Selection View Control.
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:27