Skip to content

Commit 7ff7e3e

Browse files
committed
Convert hardcoded strings to hintable fields
1 parent 16c6efb commit 7ff7e3e

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@
7171
"behat/mink-selenium2-driver": "^1.4",
7272
"friendsofphp/php-cs-fixer": "^2.16",
7373
"fzaninotto/faker": "^1.6",
74-
"instaclick/php-webdriver": "^1.4.7",
7574
"guzzlehttp/guzzle": "^6.3",
75+
"instaclick/php-webdriver": "^1.4.7",
7676
"johnkary/phpunit-speedtrap": "^3.2",
77+
"mahalux/atk4-hintable": "^1.0.1",
7778
"phpstan/phpstan": "^0.12.58",
7879
"phpunit/phpcov": "*",
7980
"phpunit/phpunit": ">=9.3",

demos/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ RUN (cd public && lessc agileui.less agileui.css)
3232
ADD composer.json .
3333
RUN jq 'del(."require-release")|del(."require-dev")' < composer.json > tmp && mv tmp composer.json \
3434
&& composer require --no-update fzaninotto/faker \
35+
&& composer require --no-update mahalux/atk4-hintable \
3536
&& composer install --no-dev
3637

3738
RUN echo 'disable_functions = pcntl_exec,exec,passthru,proc_open,shell_exec,system,popen/g' >> "$PHP_INI_DIR/php.ini"

demos/collection/card-deck.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
\Atk4\Ui\Header::addTo($app, ['Card Deck', 'size' => 1, 'subHeader' => 'Card can be display in a deck, also using model action.']);
1515

1616
$countries = new Country($app->db);
17-
$countries->addCalculatedField('Cost', function ($model) {
17+
$countries->addCalculatedField('Cost', function (Country $country) {
1818
return '$ ' . number_format(random_int(500, 1500));
1919
});
2020

2121
$action = $countries->addUserAction('book', [
22-
'callback' => function ($model, $email, $city) {
23-
return 'Your request to visit ' . ucwords($city) . ' in ' . $model->get('name') . ' was sent to: ' . $email;
22+
'callback' => function (Country $country, $email, $city) {
23+
return 'Your request to visit ' . ucwords($city) . ' in ' . $country->name . ' was sent to: ' . $email;
2424
},
2525
'ui' => ['button' => [null, 'icon' => 'plane']],
2626
]);
@@ -31,7 +31,7 @@
3131
];
3232

3333
$infoAction = $countries->addUserAction('request_info', [
34-
'callback' => function ($model, $email) {
34+
'callback' => function (Country $country, $email) {
3535
return 'Your request for information was sent to email: ' . $email;
3636
},
3737
'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_NO_RECORDS,

demos/collection/multitable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function setModel(\Atk4\Data\Model $model, $route = [])
7373
});
7474

7575
$model = new File($app->db);
76-
$model->addCondition('parent_folder_id', null);
77-
$model->setOrder(['is_folder' => 'desc', 'name']);
76+
$model->addCondition($model->fieldName()->parent_folder_id, null);
77+
$model->setOrder([$model->fieldName()->is_folder => 'desc', $model->fieldName()->name]);
7878

7979
\Atk4\Ui\Header::addTo($app, ['MacOS File Finder', 'subHeader' => 'Component built around Table, Columns and JsReload']);
8080

demos/init-db.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121
// a very basic file that sets up Agile Data to be used in some demonstrations
2222

23+
/**
24+
* @property int $id @Atk\Field(visibility="protected_set") Contains ID of the current record.
25+
* If the value is null then the record is considered to be new.
26+
*/
27+
class HintableModel extends \Mvorisek\Atk4\Hintable\Data\HintableModel
28+
{
29+
}
30+
2331
trait ModelLockTrait
2432
{
2533
public function lock(): void
@@ -40,7 +48,10 @@ public function lock(): void
4048
}
4149
}
4250

43-
class Country extends \Atk4\Data\Model
51+
/**
52+
* @property string $name @Atk\Field()
53+
*/
54+
class Country extends HintableModel
4455
{
4556
public $table = 'country';
4657

@@ -156,7 +167,12 @@ class Percent extends \Atk4\Data\Field
156167
public $type = 'float'; // will need to be able to affect rendering and storage
157168
}
158169

159-
class File extends \Atk4\Data\Model
170+
/**
171+
* @property string $name @Atk\Field()
172+
* @property bool $is_folder @Atk\Field()
173+
* @property int $parent_folder_id @Atk\Field()
174+
*/
175+
class File extends HintableModel
160176
{
161177
public $table = 'file';
162178

0 commit comments

Comments
 (0)