Skip to content

Commit 9041368

Browse files
authored
Adjust to the latest atk4/data (#1960)
1 parent e244add commit 9041368

File tree

14 files changed

+51
-55
lines changed

14 files changed

+51
-55
lines changed

demos/init-app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public static function get_class(\Closure $createAnonymousClassFx): string
157157
$menu = $layout->addMenuGroup(['Interactive', 'icon' => 'talk']);
158158
$layout->addMenuItem('Tabs', [$path . 'tabs'], $menu);
159159
$layout->addMenuItem('Card', [$path . 'card'], $menu);
160+
$layout->addMenuItem('Card Table', [$path . 'cardtable'], $menu);
160161
$layout->addMenuItem(['Accordion'], [$path . 'accordion'], $menu);
161162
$layout->addMenuItem(['Wizard'], [$path . 'wizard'], $menu);
162163
$layout->addMenuItem(['Virtual Page'], [$path . 'virtual'], $menu);

src/Card.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,20 @@ public function addContent(View $view)
175175
*
176176
* @param array<int, string>|null $fields
177177
*/
178-
public function setModel(Model $model, array $fields = null): void
178+
public function setModel(Model $entity, array $fields = null): void
179179
{
180-
$model->assertIsLoaded();
180+
$entity->assertIsLoaded();
181181

182-
parent::setModel($model);
182+
parent::setModel($entity);
183183

184184
if ($fields === null) {
185185
$fields = array_keys($this->model->getFields(['editable', 'visible']));
186186
}
187187

188188
$this->setDataId($this->model->getId());
189189

190-
View::addTo($this->getSection(), [$model->getTitle(), 'class.header' => true]);
191-
$this->getSection()->addFields($model, $fields, $this->useLabel, $this->useTable);
190+
View::addTo($this->getSection(), [$entity->getTitle(), 'class.header' => true]);
191+
$this->getSection()->addFields($entity, $fields, $this->useLabel, $this->useTable);
192192
}
193193

194194
/**

src/CardTable.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,40 @@ class CardTable extends Table
1919
/**
2020
* @param array<int, string>|null $columns
2121
*/
22-
public function setModel(Model $model, array $columns = null): void
22+
public function setModel(Model $entity, array $columns = null): void
2323
{
2424
if ($this->_bypass) {
25-
parent::setModel($model);
25+
parent::setModel($entity);
2626

2727
return;
2828
}
2929

30-
$model->assertIsLoaded();
30+
$entity->assertIsLoaded();
3131

3232
if ($columns === null) {
33-
$columns = array_keys($model->getFields('visible'));
33+
$columns = array_keys($entity->getFields('visible'));
3434
}
3535

3636
$data = [];
37-
foreach ($model->get() as $key => $value) {
37+
foreach ($entity->get() as $key => $value) {
3838
if (in_array($key, $columns, true)) {
3939
$data[] = [
4040
'id' => $key,
41-
'field' => $model->getField($key)->getCaption(),
42-
'value' => $this->getApp()->uiPersistence->typecastSaveField($model->getField($key), $value),
41+
'field' => $entity->getField($key)->getCaption(),
42+
'value' => $this->getApp()->uiPersistence->typecastSaveField($entity->getField($key), $value),
4343
];
4444
}
4545
}
4646

4747
$this->_bypass = true;
48-
$mm = parent::setSource($data);
49-
$this->addDecorator('value', [Table\Column\Multiformat::class, function (Model $row) use ($model) {
50-
$field = $model->getField($row->getId());
48+
try {
49+
parent::setSource($data);
50+
} finally {
51+
$this->_bypass = false;
52+
}
53+
54+
$this->addDecorator('value', [Table\Column\Multiformat::class, function (Model $row) use ($entity) {
55+
$field = $entity->getField($row->getId());
5156
$ret = $this->decoratorFactory(
5257
$field,
5358
$field->type === 'boolean' ? [Table\Column\Status::class, ['positive' => [true, 'Yes'], 'negative' => [false, 'No']]] : []
@@ -58,6 +63,5 @@ public function setModel(Model $model, array $columns = null): void
5863

5964
return [$ret];
6065
}]);
61-
$this->_bypass = false;
6266
}
6367
}

src/Form.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group')
221221
*
222222
* @param array<int, string>|null $fields
223223
*/
224-
public function setModel(Model $model, array $fields = null): void
224+
public function setModel(Model $entity, array $fields = null): void
225225
{
226-
$model->assertIsEntity();
226+
$entity->assertIsEntity();
227227

228228
// Model is set for the form and also for the current layout
229229
try {
230-
parent::setModel($model);
230+
parent::setModel($entity);
231231

232-
$this->layout->setModel($model, $fields);
232+
$this->layout->setModel($entity, $fields);
233233
} catch (Exception $e) {
234-
throw $e->addMoreInfo('model', $model);
234+
throw $e->addMoreInfo('model', $entity);
235235
}
236236
}
237237

src/Form/AbstractLayout.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ protected function getModelFields(Model $model)
8989
*
9090
* @param array<int, string>|null $fields
9191
*/
92-
public function setModel(Model $model, array $fields = null): void
92+
public function setModel(Model $entity, array $fields = null): void
9393
{
94-
$model->assertIsEntity();
94+
$entity->assertIsEntity();
9595

96-
parent::setModel($model);
96+
parent::setModel($entity);
9797

9898
if ($fields === null) {
99-
$fields = $this->getModelFields($model);
99+
$fields = $this->getModelFields($entity);
100100
}
101101

102102
// add controls - check if fields are editable or read-only/disabled
103103
foreach ($fields as $fieldName) {
104-
$field = $model->getField($fieldName);
104+
$field = $entity->getField($fieldName);
105105

106106
$controlSeed = null;
107107
if ($field->isEditable()) {

src/Form/Layout/Columns.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class Columns extends Form\Layout
2626
*
2727
* @param array<int, string>|null $fields
2828
*/
29-
public function setModel(Model $model, array $fields = null): void
29+
public function setModel(Model $entity, array $fields = null): void
3030
{
3131
// dont add any fields automatically
32-
parent::setModel($model, []);
32+
parent::setModel($entity, []);
3333

3434
if ($fields === null) {
35-
$fields = $this->getModelFields($model);
35+
$fields = $this->getModelFields($entity);
3636
}
3737

3838
$cnt = count($fields);
@@ -67,7 +67,7 @@ public function setModel(Model $model, array $fields = null): void
6767
foreach ($chunks as $chunk) {
6868
$cc = $c->addColumn();
6969
Form\Layout::addTo($cc, ['form' => $this->form])
70-
->setModel($model, $chunk);
70+
->setModel($entity, $chunk);
7171
}
7272

7373
View::addTo($this, ['ui' => 'clearing hidden divider']);

src/Table.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,13 @@ public function getDataRowHtml()
680680

681681
// we need to smartly wrap things up
682682
$cell = null;
683-
$cnt = count($column);
684683
$td_attr = [];
685-
foreach ($column as $c) {
686-
if (--$cnt) {
684+
foreach ($column as $cKey => $c) {
685+
if ($cKey !== array_key_last($column)) {
687686
$html = $c->getDataCellTemplate($field);
688687
$td_attr = $c->getTagAttributes('body', $td_attr);
689688
} else {
690-
// Last formatter, ask it to give us whole rendering
689+
// last formatter, ask it to give us whole rendering
691690
$html = $c->getDataCellHtml($field, $td_attr);
692691
}
693692

src/Table/Column/FilterModel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Atk4\Data\Field;
1010
use Atk4\Data\Model;
1111
use Atk4\Data\Persistence;
12-
use Atk4\Data\Types\Types as CustomTypes;
12+
use Atk4\Data\Type\Types as CustomTypes;
1313
use Atk4\Ui\App;
1414
use Atk4\Ui\SessionTrait;
1515
use Doctrine\DBAL\Types\Types;
@@ -32,8 +32,8 @@ abstract class FilterModel extends Model
3232
/** @var bool Determines if this field shouldn't have a value field, and use only op field. */
3333
public $noValueField = false;
3434

35-
/** @var Field The field where this filter need to query data. */
36-
public $lookupField;
35+
/** The field where this filter need to query data. */
36+
public Field $lookupField;
3737

3838
public function __construct(App $app, array $defaults = [])
3939
{

src/Table/Column/FilterPopup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class FilterPopup extends Popup
2323
/** @var Form The form associate with this FilterPopup. */
2424
public $form;
2525

26-
/** @var Field The table field that need filtering. */
27-
public $field;
26+
/** The table field that need filtering. */
27+
public Field $field;
2828

2929
/** @var View|null The view associated with this filter popup that needs to be reloaded. */
3030
public $reload;

src/Table/Column/Multiformat.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ public function getHtmlTags(Model $row, ?Field $field): array
3535
// we need to smartly wrap things up
3636
$name = $field->shortName;
3737
$cell = null;
38-
$cnt = count($decorators);
3938
$td_attr = [];
4039
$html_tags = [];
41-
foreach ($decorators as $c) {
40+
foreach ($decorators as $cKey => $c) {
4241
if (!is_object($c)) {
4342
$c = $this->getOwner()->decoratorFactory($field, $c);
4443
}
4544
$c = Table\Column::assertInstanceOf($c);
4645

47-
if (--$cnt) {
46+
if ($cKey !== array_key_last($decorators)) {
4847
$html = $c->getDataCellTemplate($field);
4948
$td_attr = $c->getTagAttributes('body', $td_attr);
5049
} else {
51-
// Last formatter, ask it to give us whole rendering
50+
// last formatter, ask it to give us whole rendering
5251
$html = $c->getDataCellHtml($field, $td_attr);
5352
}
5453

0 commit comments

Comments
 (0)