ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Data.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
36 
37 class Data extends AbstractTable implements T\Data
38 {
43 
44  public const STORAGE_ID_PREFIX = self::class . '_';
45  public const VIEWCONTROL_KEY_PAGINATION = 'range';
46  public const VIEWCONTROL_KEY_ORDERING = 'order';
47  public const VIEWCONTROL_KEY_FIELDSELECTION = 'selected_optional';
48 
49  protected ?array $filter = null;
50  protected ?array $additional_parameters = null;
51 
55  public function __construct(
56  SignalGeneratorInterface $signal_generator,
57  ViewControl\Factory $view_control_factory,
58  ViewControlContainer\Factory $view_control_container_factory,
59  protected DataFactory $data_factory,
60  protected DataRowBuilder $data_row_builder,
61  string $title,
62  array $columns,
63  protected T\DataRetrieval $data_retrieval,
64  \ArrayAccess $storage
65  ) {
67  $signal_generator,
68  $view_control_factory,
69  $view_control_container_factory,
70  $storage,
71  $title,
72  $columns
73  );
74  $this->initViewControlFieldSelection($columns);
75  $this->initViewControlOrdering();
77  }
78 
79  public function getDataRetrieval(): T\DataRetrieval
80  {
81  return $this->data_retrieval;
82  }
83 
84  public function withFilter(?array $filter): self
85  {
86  $clone = clone $this;
87  $clone->filter = $filter;
88  return $clone;
89  }
90 
91  public function getFilter(): ?array
92  {
93  return $this->filter;
94  }
95 
96  public function withAdditionalParameters(?array $additional_parameters): self
97  {
98  $clone = clone $this;
99  $clone->additional_parameters = $additional_parameters;
100  return $clone;
101  }
102 
103  public function getAdditionalParameters(): ?array
104  {
106  }
107 
108  public function getRowBuilder(): DataRowBuilder
109  {
110  return $this->data_row_builder
112  ->withSingleActions($this->getSingleActions())
113  ->withVisibleColumns($this->getVisibleColumns());
114  }
115 
119  public function applyViewControls(
120  array $filter_data,
121  ?array $additional_parameters = []
122  ): array {
123  $table = $this;
124  $total_count = $this->getDataRetrieval()->getTotalRowCount($filter_data, $additional_parameters);
125  $view_controls = $this->getViewControls($total_count);
126 
127  if ($request = $this->getRequest()) {
128  # This retrieves container data from the request
129  $data = $this->applyValuesToViewcontrols($view_controls, $request)->getData();
130  $range = $data[self::VIEWCONTROL_KEY_PAGINATION];
131  $range = ($range instanceof Range) ? $range : null;
132  $order = $data[self::VIEWCONTROL_KEY_ORDERING];
133  $order = ($order instanceof Order) ? $order : null;
134 
135  if ($range instanceof Range) {
136  $range = $range->withStart($range->getStart() <= $total_count ? $range->getStart() : 0);
137  $range = $range->croppedTo($total_count ?? PHP_INT_MAX);
138  }
139 
140  $table = $table
141  ->withRange($range)
142  ->withOrder($order)
143  ->withSelectedOptionalColumns($data[self::VIEWCONTROL_KEY_FIELDSELECTION] ?? null);
144  # This retrieves the view controls that should be displayed
145  $view_controls = $table->applyValuesToViewcontrols($table->getViewControls($total_count), $request);
146  }
147 
148  return [
149  $table,
150  $view_controls
151  ];
152  }
153 
154  protected function getViewControls(?int $total_count = null): ViewControlContainer\ViewControl
155  {
156  $view_controls = [
157  self::VIEWCONTROL_KEY_PAGINATION => $this->getViewControlPagination($total_count),
158  self::VIEWCONTROL_KEY_ORDERING => $this->getViewControlOrdering($total_count),
159  self::VIEWCONTROL_KEY_FIELDSELECTION => $this->getViewControlFieldSelection(),
160  ];
161  $view_controls = array_filter($view_controls);
162  return $this->view_control_container_factory->standard($view_controls);
163  }
164 }
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withAdditionalParameters(?array $additional_parameters)
Definition: Data.php:96
croppedTo(int $max)
This will create a range that is guaranteed to not exceed $max.
Definition: Range.php:98
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Builds data types.
Definition: Factory.php:35
getViewControls(?int $total_count=null)
Definition: Data.php:154
applyValuesToViewcontrols(ViewControlContainer\ViewControl $view_controls, ServerRequestInterface $request)
__construct(SignalGeneratorInterface $signal_generator, ViewControl\Factory $view_control_factory, ViewControlContainer\Factory $view_control_container_factory, protected DataFactory $data_factory, protected DataRowBuilder $data_row_builder, string $title, array $columns, protected T\DataRetrieval $data_retrieval, \ArrayAccess $storage)
Definition: Data.php:55
applyViewControls(array $filter_data, ?array $additional_parameters=[])
Definition: Data.php:119
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
withStart(int $start)
Definition: Range.php:79
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28