Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using flag decorator in card table #1756

Closed
wants to merge 13 commits into from
29 changes: 29 additions & 0 deletions demos/collection/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/* TODO - merge this into /demos/interactive/cardtable.php */
declare(strict_types=1);

namespace Atk4\Ui\Demos;

use Atk4\Ui\CardTable;
use Atk4\Ui\Table;

/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';

$m = new Country($app->db);
$m->addField('flag', [
'neverPersist' => true, // no need for actual value in this field
'ui' => [
'table' => [
Table\Column\CountryFlag::class,
[
'codeField' => $m->fieldName()->iso,
'nameField' => $m->fieldName()->name,
],
],
],
]);

$e = $m->loadAny();
$t = CardTable::addTo($app);
$t->setModel($e);
15 changes: 10 additions & 5 deletions src/CardTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ public function setModel(Model $model, array $columns = null): void
}

$data = [];
foreach ($model->get() as $key => $value) {
if (in_array($key, $columns, true)) {
foreach (array_keys($model->get()) as $fieldName) {
if (in_array($fieldName, $columns, true)) {
$data[] = [
'id' => $key,
'field' => $model->getField($key)->getCaption(),
'value' => $this->getApp()->uiPersistence->typecastSaveField($model->getField($key), $value),
'id' => $fieldName,
'field' => $model->getField($fieldName)->getCaption(),
'value' => new Model\EntityFieldPair($model, $fieldName),
];
}
}

$this->_bypass = true;

parent::setSource($data);
/*
$mm = parent::setSource($data);
$this->addDecorator('value', [Table\Column\Multiformat::class, function (Model $row) use ($model) {
$field = $model->getField($row->getId());
Expand All @@ -58,6 +61,8 @@ public function setModel(Model $model, array $columns = null): void

return [$ret];
}]);
*/

$this->_bypass = false;
}
}