ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
base.php
Go to the documentation of this file.
1 <?php
2 
7 
8 function base()
9 {
10  global $DIC;
11  $f = $DIC['ui.factory'];
12  $r = $DIC['ui.renderer'];
13 
14  //this is some dummy-data:
15  $dummy_records = [
16  ['f1' => 'value1.1','f2' => 'value1.2','f3' => 1.11],
17  ['f1' => 'value2.1','f2' => 'value2.2','f3' => 2.22],
18  ['f1' => 'value3.1','f2' => 'value3.2','f3' => 4.44],
19  ['f1' => 'value4.1','f2' => 'value4.2','f3' => 8.88]
20  ];
21 
22  // This is what the table will look like
23  $columns = [
24  'f1' => $f->table()->column()->text("Field 1")
25  ->withIsSortable(false),
26 
27  'f0' => $f->table()->column()->text("empty"),
28 
29  'f2' => $f->table()->column()->text("Field 2")
30  ->withIsOptional(true)
31  ->withIsInitiallyVisible(false),
32 
33  'f3' => $f->table()->column()->number("Field 3")
34  ->withIsOptional(true)
35  ->withDecimals(2),
36 
37  'f4' => $f->table()->column()->number("Field 4")
38  ->withIsOptional(false)
39  ];
40 
41  // retrieve data and map records to table rows
42  $data_retrieval = new class($dummy_records) extends T\DataRetrieval {
43  protected $records;
44 
45  public function __construct(array $dummy_records)
46  {
47  $this->records = $dummy_records;
48  }
49 
50  public function getRows(
51  I\RowFactory $row_factory,
52  Range $range,
53  Order $order,
54  array $visible_column_ids,
55  array $additional_parameters
56  ) : \Generator {
57  foreach ($this->records as $record) {
58  //maybe do something with the record
59  $record['f4'] = $record['f3'] * 2;
60  //and yield the row
61  yield $row_factory->map($record);
62  }
63  }
64  };
65 
66  //setup the table
67  $table = $f->table()->data('a data table', 50)
68  ->withColumns($columns)
69  ->withData($data_retrieval);
70 
71  //apply request and render
72  $request = $DIC->http()->request();
73  return $r->render($table->withRequest($request));
74 }
base()
Definition: base.php:4
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:10
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:10
if(! $in) $columns
Definition: Utf8Test.php:45