Skip to content

Commit

Permalink
Row update: ActiveRow property moved to separate method, added custom…
Browse files Browse the repository at this point in the history
… "throughColumn" specification
  • Loading branch information
paveljanda committed Dec 24, 2016
1 parent 655b5af commit 34bcd68
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,7 @@ public function getValue($key)
return $this->item->{$this->formatDibiRowKey($key)};

} else if ($this->item instanceof ActiveRow) {
if (preg_match("/^:([a-zA-Z0-9_$]*)\.([a-zA-Z0-9_$]*)$/", $key, $matches)) {
$relatedTable = $matches[1];
$relatedColumn = $matches[2];

return $this->item->related($relatedTable)->fetch()->{$relatedColumn};
}

if (preg_match("/^([a-zA-Z0-9_$]*)\.([a-zA-Z0-9_$]*)$/", $key, $matches)) {
$referredTable = $matches[1];
$referredColumn = $matches[2];

return $this->item->ref($referredTable)->{$referredColumn};
}
return $this->item->{$key};
return $this->getActiveRowProperty($this->item, $key);

} else if ($this->item instanceof Nette\Database\Row) {
return $this->item->{$key};
Expand Down Expand Up @@ -145,6 +132,37 @@ public function getControlClass()
}


/**
* @param ActiveRow $item
* @param string $key
* @return mixed|NULL
*/
public function getActiveRowProperty(ActiveRow $item, $key)
{
if (preg_match("/^:([a-zA-Z0-9_$]+)\.([a-zA-Z0-9_$]+)(:([a-zA-Z0-9_$]+))?$/", $key, $matches)) {
$relatedTable = $matches[1];
$relatedColumn = $matches[2];
$throughColumn = isset($matches[4]) ? $matches[4] : NULL;

This comment has been minimized.

Copy link
@kubarta

kubarta Dec 26, 2016

Contributor

@paveljanda
It should be
$relatedRow = $item->related($relatedTable, $throughColumn)->fetch();

Or not?

This comment has been minimized.

Copy link
@juniwalk

juniwalk Dec 26, 2016

Contributor

Yes, I will fix it.

$relatedRow = $this->item->related($relatedTable, $throughColumn)->fetch();

return $relatedRow ? $relatedRow->{$relatedColumn} : NULL;
}

if (preg_match("/^([a-zA-Z0-9_$]+)\.([a-zA-Z0-9_$]+)(:([a-zA-Z0-9_$]+))?$/", $key, $matches)) {
$referencedTable = $matches[1];
$referencedColumn = $matches[2];
$throughColumn = isset($matches[4]) ? $matches[4] : NULL;

$referencedRow = $this->item->ref($referencedTable, $throughColumn);

return $referencedRow ? $referencedRow->{$referencedColumn} : NULL;
}

return $this->item->{$key};
}


/**
* LeanMapper: Access object properties to get a item value
* @param LeanMapper\Entity $item
Expand Down

0 comments on commit 34bcd68

Please sign in to comment.