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

Adjust to renamed Model::onlyFields and Model::loaded methods #1701

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/collection/multitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setModel(Model $model, $route = []): void
$path[] = $id;
$pushModel = new $model($model->persistence);
$pushModel = $pushModel->tryLoad($id);
if (!$pushModel->loaded()) {
if (!$pushModel->isLoaded()) {
break;
}
$ref = array_shift($route);
Expand Down
2 changes: 1 addition & 1 deletion demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function validate($intent = null): array

// look if name is unique
$c = $this->getModel()->tryLoadBy($this->fieldName()->name, $this->name);
if ($c->loaded() && $c->getId() !== $this->getId()) {
if ($c->isLoaded() && $c->getId() !== $this->getId()) {
$errors[$this->fieldName()->name] = 'Country name must be unique';
}

Expand Down
4 changes: 2 additions & 2 deletions demos/tutorial/intro.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function init(): void
$model = $model->tryLoad(1);
$form->setModel($model);

if (!$model->loaded()) {
if (!$model->isLoaded()) {
// set default data
$model->setMulti([
'id' => 1,
Expand Down Expand Up @@ -210,7 +210,7 @@ protected function init(): void

Header::addTo($owner, ['Record display in Card View using model data.']);
$model = $model->tryLoad(1);
if ($model->loaded()) {
if ($model->isLoaded()) {
\Atk4\Ui\Card::addTo($owner, ['useLabel' => true])
->setModel($model);
} else {
Expand Down
2 changes: 1 addition & 1 deletion docs/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ active. (See :ref:`system_pattern`)::
}

          // Make sure user is valid
if(!$this->user->loaded()) {
if (!$this->user->isLoaded()) {
$this->initLayout([\Atk4\Ui\Layout\Centered::class]);
Message::addTo($this, ['Login Required', 'error']);
Button::addTo($this, ['Login', 'primary'])->link('index.php');
Expand Down
2 changes: 1 addition & 1 deletion docs/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ POST data to submit itself and will re-use the query string, so you can also saf
use any GET arguments for passing record $id. You may also perform model load after
record association. This gives the benefit of not loading any other fields, unless
they're marked as System (https://agile-data.readthedocs.io/en/develop/fields.html#Field::$system),
see https://agile-data.readthedocs.io/en/develop/model.html?highlight=onlyfields#Model::onlyFields::
see https://agile-data.readthedocs.io/en/develop/model.html?highlight=onlyfields#Model::setOnlyFields::

$form = Form::addTo($app);
$form->setModel((new User($db))->load($current_user), ['email', 'name']);
Expand Down
6 changes: 2 additions & 4 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ public function addContent(View $view)
*/
public function setModel(Model $model, array $fields = null): void
{
if (!$model->loaded()) {
throw new Exception('Model need to be loaded.');
}
$model->assertIsLoaded();

parent::setModel($model);

Expand Down Expand Up @@ -290,7 +288,7 @@ public function addClickAction(Model\UserAction $action, Button $button = null,
$btn = $this->addButton($button ?? $this->getExecutorFactory()->createTrigger($action, $this->getExecutorFactory()::CARD_BUTTON));

// Setting arg for model id. $args[0] is consider to hold a model id, i.e. as a js expression.
if ($this->model && $this->model->loaded() && !isset($args[0])) {
if ($this->model && $this->model->isLoaded() && !isset($args[0])) {
$defaults[] = $this->model->getId();
}

Expand Down
4 changes: 2 additions & 2 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected function jsExecute($return, $action)
} elseif (is_array($return) || $return instanceof JsExpressionable) {
return $return;
} elseif ($return instanceof Model) {
$msg = $return->loaded() ? $this->saveMsg : ($action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD ? $this->deleteMsg : $this->defaultMsg);
$msg = $return->isLoaded() ? $this->saveMsg : ($action->appliesTo === Model\UserAction::APPLIES_TO_SINGLE_RECORD ? $this->deleteMsg : $this->defaultMsg);

return $this->jsModelReturn($action, $msg);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ protected function getNotifier(string $msg = null, Model\UserAction $action = nu
protected function jsModelReturn(Model\UserAction $action = null, string $msg = 'Done!'): array
{
$js[] = $this->getNotifier($msg, $action);
if ($action->getModel()->loaded() && $card = $this->findCard($action->getModel())) {
if ($action->getModel()->isLoaded() && $card = $this->findCard($action->getModel())) {
$js[] = $card->jsReload($this->getReloadArgs());
} else {
$js[] = $this->container->jsReload($this->getReloadArgs());
Expand Down
4 changes: 1 addition & 3 deletions src/CardSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public function addDescription($description)
*/
public function addFields(Model $model, array $fields, bool $useLabel = false, bool $useTable = false)
{
if (!$model->loaded()) {
throw new Exception('Model need to be loaded.');
}
$model->assertIsLoaded();

if ($useTable) {
$this->addTableSection($model, $fields);
Expand Down
5 changes: 1 addition & 4 deletions src/CardTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public function setModel(Model $model, array $columns = null): void
return;
}

if (!$model->loaded()) {
throw (new Exception('Model must be loaded'))
->addMoreInfo('model', $model);
}
$model->assertIsLoaded();

$data = [];
foreach ($model->get() as $key => $value) {
Expand Down
4 changes: 2 additions & 2 deletions src/Component/InlineEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function setModel(Model $model): void
parent::setModel($model);

$this->fieldName = $this->fieldName ?: $this->model->title_field;
if ($this->autoSave && $this->model->loaded()) {
if ($this->autoSave && $this->model->isLoaded()) {
$value = $_POST['value'] ?? null;
$this->cb->set(function () use ($value) {
try {
Expand Down Expand Up @@ -190,7 +190,7 @@ protected function renderView(): void
throw new Exception('Only string or number field can be edited inline. Field Type = ' . $type);
}

if ($this->model && $this->model->loaded()) {
if ($this->model && $this->model->isLoaded()) {
$initValue = $this->model->get($this->fieldName);
} else {
$initValue = $this->initValue;
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function htmlRenderValue(): void
}
} else {
// for standard model rendering, only load id and title field
$this->model->only_fields = [$this->model->title_field, $this->model->id_field];
$this->model->setOnlyFields([$this->model->title_field, $this->model->id_field]);
$this->_renderItemsForModel();
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected function initQuickNewRecord()

$entity = $this->model->createEntity();

$form->setModel($entity->onlyFields($this->plus['fields'] ?? []));
$form->setModel($entity->setOnlyFields($this->plus['fields'] ?? []));

$form->onSubmit(function (\Atk4\Ui\Form $form) {
$form->model->save();
Expand Down Expand Up @@ -440,7 +440,7 @@ protected function renderView(): void

$this->model = $this->model->tryLoadBy($id_field, $this->entityField->get());

if ($this->model->loaded()) {
if ($this->model->isLoaded()) {
$row = $this->renderRow($this->model);

$chain->dropdown('set value', $row['value'])->dropdown('set text', $row['title']);
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public function setLookupOptionValue(Field $field, string $value)
{
$model = $field->getReference()->refModel($this->model);
$rec = $model->tryLoadBy($field->getReference()->getTheirFieldName(), $value);
if ($rec->loaded()) {
if ($rec->isLoaded()) {
$option = [
'key' => $value,
'text' => $rec->get($model->title_field),
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ protected static function getOption(string $type, string $value, Condition $cond
$model = $reference->refModel($condField->getOwner());
$fieldName = $reference->getTheirFieldName();
$rec = $model->tryLoadBy($fieldName, $value);
if ($rec->loaded()) {
if ($rec->isLoaded()) {
$option = [
'key' => $value,
'text' => $rec->get($model->title_field),
Expand Down